Compare image module code

Now, finally, we write the main modules to upload the face comparison, where the IR sensor detects a presence and triggers Pi to capture the image and send it to S3 and then to Rekognition, where it compares the face with the collection:

  1. Create a file with the name FaceComparision.js and add the following code:
 var GPIO = require('pigpio').Gpio,

cameraModule = require('./CameraModuleRekognition'),

s3Bucket = require('./S3Put'),

green_LED = new GPIO(19,{mode: GPIO.OUTPUT}),

red_LED= new GPIO(17,{mode: GPIO.OUTPUT}),

IR_out= new GPIO(5,{mode: GPIO.INPUT,alert: true});

red_LED.digitalWrite(0);

green_LED.digitalWrite(0);

IR_out.on('alert', function(level, tick){

if(level==1){

cameraModule.takeTargetPicture(function (callback) {

var result = callback;

if(result == 'success'){

console.log('Face Match Success...!!')

green_LED.digitalWrite(1);

setTimeout(function () {

green_LED.digitalWrite(0);

},5000)

}

})



console.log('IR : Imaging you..!!')

red_LED.digitalWrite(level);

}

else {

red_LED.digitalWrite(level);

}

})
  1. Let's now execute both modules one by one and see their output.
  2. Open the Terminal and run the following command:
sudo npm node UploadIR.js
  1. On successful execution, you will see output as shown in Figure 7.30:
  1. Previous screenshot shows the metadata (extracted features of face from image) printed on console. This metadata is stored in collection and will be used later to compare the faces.
  2. Next we will run the face comparison module which will take the new input image from camera and then upload it to s3 and finally using SearchFacesByImage function compares the face with existing faces stored in collection:
sudo npm node FaceComparison.js
  1. On successful execution, you will see output as shown in Figure 7.31:

This brings us to the end of this chapter.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.223.125.219