I have been working on a project from github, https://github.com/twilio/wireless-security-camera, that utilizes OpenCV. Now I haven't played much with OpenCV so this is trial and error on my part. Looking at the script i was running into issue due to its dependance on OpenCV2 functions. I started diving in to OpenCV4 and think im on the right track.
The script had a function called CV.readimage, when running this script the script would constantly run and not complete the "capture" of "previousimage & im" to compare for differences. So my first change was to change this function to CV.imreadAsync. Once I did this the script now will grab both images and proceed to the next line in the script. The next couple lines in the script i am unsure what needs to change and could really use a nudge in the right direction.
```Javascript file security-camera.js```
if (previousImage && im.width() > 1 && im.height() > 1) {
CV.ImageSimilarity(im, previousImage, function (err, dissimilarity) {
console.log('Dissimilarity:', dissimilarity);
previousImage = im;
heres a printout of the script when ran with the command NPM start.
```NPM Start```
pi@raspberrypi:~/camera $ npm start
> wireless-security-camera@0.0.1 start /home/pi/camera
> node security-camera.js
Got configuration for camera: cameraid
Snapshot document: ETfce4dca035cb45cc9575479757d48d18
Control map: MPb7bbd87e79b24ab6a9aff3db19b085cb
Starting camera capture
calling....
/opt/vc/bin/raspistill --width 640 --height 360 --output /home/pi/camera/images/ camera%03d.jpg --nopreview --timeout 1800000 --timelapse 250 --quality 80 --rotation 180 --thumb 0:0:0
raspicam::watcher::event rename
raspicam::watcher::event change
raspicam::watcher::event change
raspicam::watcher::event rename
raspicam::watcher::event rename
Frame captured: null 1579706071810 camera000.jpg
stderr: mmal: Skipping frame 1 to restart at frame 2
raspicam::watcher::event rename
CV loaded: /home/pi/camera/images/camera000.jpg Mat {
step: 1920,
elemSize: 3,
sizes: [ 360, 640 ],
empty: 0,
depth: 0,
dims: 2,
channels: 3,
type: 16,
cols: 640,
rows: 360
}
raspicam::watcher::event change
raspicam::watcher::event change
raspicam::watcher::event rename
raspicam::watcher::event rename
Frame captured: null 1579706072527 camera002.jpg
stderr: mmal: Skipping frame 3 to restart at frame 5
CV loaded: /home/pi/camera/images/camera002.jpg Mat {
step: 1920,
elemSize: 3,
sizes: [ 360, 640 ],
empty: 0,
depth: 0,
dims: 2,
channels: 3,
type: 16,
cols: 640,
rows: 360
}
/home/pi/camera/security-camera.js:115
if (previousImage && im.width() > 1 && im.height() > 1) {
^
TypeError: im.width is not a function
at /home/pi/camera/security-camera.js:115:30
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! wireless-security-camera@0.0.1 start: \node security-camera.js\``
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the wireless-security-camera@0.0.1 start script.
npm ERR! This is probably not a problem with npm. There is likely
additional logging output
npm ERR! A complete log of this run can be found in:
npm ERR! /home/pi/.npm/_logs/2020-01-22T15_14_32_661Z-debug.log
Update with info from comment:
The next couple lines in the script i am unsure what needs to change. My question is how can i make the script compare the two images to determine if there was a change that it should send a notification. Previously the script pulled width and height before running a "similarity" function. When running the script using opencv4nodejs it fails at width, height, and imagesimilarity saying all the above is not a function.