dmcinnes / MMM-Motion-Detection

Motion Detection Extension for the MagicMirror.
5 stars 1 forks source link

PythonShell is not a constructor #2

Open lukasdietz opened 6 years ago

lukasdietz commented 6 years ago

Hi, I have a problem running Motion-Detection. Starting MagicMirror with this module configured leads to an uncaught exception: TypeError: PythonShell is not a constructor at Class.python_start (/home/pi/MagicMirror/modules/MMM-Motion-Detection/node_helper.js:31:18) at Class.socketNotificationReceived (/home/pi/MagicMirror/modules/MMM-Motion-Detection/node_helper.js:60:14) at Socket.<anonymous> (/home/pi/MagicMirror/modules/node_modules/node_helper/index.js:113:11) at emitTwo (events.js:106:13) at Socket.emit (events.js:191:7) at /home/pi/MagicMirror/node_modules/socket.io/lib/socket.js:514:12 at _combinedTickCallback (internal/process/next_tick.js:67:7) at process._tickCallback (internal/process/next_tick.js:98:9) Python-Shell is installed and functioning. Also the FacialRecognition Module is working. Is there anything I can do to resolve this issue?

shayfer commented 6 years ago

lukasdietz,

Have you been able to get this resolved? I am getting the same error. Looking around someone said the fix is adding { } in the node helper but that doesn't work either. It creates a new error.

SyntaxError: Unexpected token T in JSON at position 0 at JSON.parse () at PythonShell.asJson (/home/pi/MagicMirror/modules/MMM-Motion-Detection/node_modules/python-shell/index.js:350:21) at /home/pi/MagicMirror/modules/MMM-Motion-Detection/node_modules/python-shell/index.js:302:42 at Array.forEach () at PythonShell.recieveInternal (/home/pi/MagicMirror/modules/MMM-Motion-Detection/node_modules/python-shell/index.js:298:15) at PythonShell.receiveStderr (/home/pi/MagicMirror/modules/MMM-Motion-Detection/node_modules/python-shell/index.js:282:21) at Socket. (/home/pi/MagicMirror/modules/MMM-Motion-Detection/node_modules/python-shell/index.js:100:18) at emitOne (events.js:116:13) at Socket.emit (events.js:211:7) at addChunk (_stream_readable.js:263:12) { Error: ImportError: No module named 'cv2' at PythonShell.parseError (/home/pi/MagicMirror/modules/MMM-Motion-Detection/node_modules/python-shell/index.js:232:21) at terminateIfNeeded (/home/pi/MagicMirror/modules/MMM-Motion-Detection/node_modules/python-shell/index.js:121:32) at ChildProcess. (/home/pi/MagicMirror/modules/MMM-Motion-Detection/node_modules/python-shell/index.js:113:13) at emitTwo (events.js:126:13) at ChildProcess.emit (events.js:214:7) at Process.ChildProcess._handle.onexit (internal/child_process.js:198:12) ----- Python Traceback ----- File "modules/MMM-Motion-Detection/motiondetection/motiondetection.py", line 19, in import cv2 traceback: 'Traceback (most recent call last):\n File "modules/MMM-Motion-Detection/motiondetection/motiondetection.py", line 19, in \n import cv2\nImportError: No module named \'cv2\'\n', executable: 'python3', options: null, script: 'modules/MMM-Motion-Detection/motiondetection/motiondetection.py', args: [ '{"useUSBCam":false,"interval":1,"motionStopDelay":120,"detectionThreshold":1000,"turnOffDisplay":true}' ], exitCode: 1 }

dxfan227 commented 5 years ago

Bumping this, having the exact same error any one else figure it out

ivanovd commented 5 years ago

cd ~/MagicMirror/modules/MMM-Motion-Detection npm install python-shell@0.4.0 pm2 restart mm`

That is how I fixed it.

dxfan227 commented 5 years ago

cd ~/MagicMirror/modules/MMM-Motion-Detection npm install python-shell@0.4.0 pm2 restart mm`

That is how I fixed it.

Thank you!

can I ask what your detection threshold is set at? my monitor won't turn off unless I literally hold my hand in front of the camera lol

ivanovd commented 5 years ago

{ module: 'MMM-Motion-Detection', config: { // force the use of a usb webcam on raspberry pi useUSBCam: true, // recognition interval in seconds (smaller number = faster but more CPU intensive!) interval: 1, // Notificaiton Delay after movement stops being sensed (in seconds). motionStopDelay: 10, // Threshold for motion detection, smaller numbers means more sensitive detectionThreshold: 1000, // Turn off display when no motion is detected. turnOffDisplay: true } }, You probably mean "turn on", since that is what the module does ... it turns off the screen when there is no motion in front of the camera and turns it on when it senses motion.

What I found is that the USB cameras on the PI work best if set to the lowest possible resolution, then the light sensitivity and the refresh rate are the best and that works perfectly for the motion detection.

The higher resolution you try to set the worse the light sensitivity and refresh rate you get, so mine is set to 320x280 (I believe) and that is perfectly fine for motion detection.

dxfan227 commented 5 years ago

{ module: 'MMM-Motion-Detection', config: { // force the use of a usb webcam on raspberry pi useUSBCam: true, // recognition interval in seconds (smaller number = faster but more CPU intensive!) interval: 1, // Notificaiton Delay after movement stops being sensed (in seconds). motionStopDelay: 10, // Threshold for motion detection, smaller numbers means more sensitive detectionThreshold: 1000, // Turn off display when no motion is detected. turnOffDisplay: true } }, You probably mean "turn on", since that is what the module does ... it turns off the screen when there is no motion in front of the camera and turns it on when it senses motion.

What I found is that the USB cameras on the PI work best if set to the lowest possible resolution, then the light sensitivity and the refresh rate are the best and that works perfectly for the motion detection.

The higher resolution you try to set the worse the light sensitivity and refresh rate you get, so mine is set to 320x280 (I believe) and that is perfectly fine for motion detection.

no I meant turn off, I literally meant cover the lease with my hand so it was all black and won't detect motion. I ended up turning it all the way up to 14000 and this seems to work.

that being said, just so I know...where would one define the resolution settings of a webcam. On the pi somewhere or in the module code?

ivanovd commented 5 years ago

Try this guide to see what images your camera captures and if they are exposed enough to recognize an object: https://www.raspberrypi.org/documentation/usage/webcams/

cluelesscarter commented 4 years ago

Hi @ivanovd, tried your fix above to update python shell within the MMM-Motion-Detection folder but i now receive the following error in the error log, any ideas?

[2020-09-08 14:33:28.606] [LOG]    [MMM-Motion-Detection] --------------------
[2020-09-08 14:33:28.615] [LOG]    [MMM-Motion-Detection] Webcam starting...
[2020-09-08 14:33:34.468] [ERROR]  Whoops! There was an uncaught exception...
[2020-09-08 14:33:34.476] [ERROR]  Error: ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
    at PythonShell.parseError (/home/pi/MagicMirror/modules/MMM-Motion-Detection/node_modules/python-shell/index.js:183:17)
    at terminateIfNeeded (/home/pi/MagicMirror/modules/MMM-Motion-Detection/node_modules/python-shell/index.js:98:28)
    at ChildProcess.<anonymous> (/home/pi/MagicMirror/modules/MMM-Motion-Detection/node_modules/python-shell/index.js:88:9)
    at ChildProcess.emit (events.js:200:13)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:272:12)
    ----- Python Traceback -----
    File "modules/MMM-Motion-Detection/motiondetection/motiondetection.py", line 50, in <module>
      if frame == None: {
  traceback: 'Traceback (most recent call last):\n  File ' +
    '"modules/MMM-Motion-Detection/motiondetection/motiondetection.py", ' +
    'line 50, in <module>\n    if frame == None:\nValueError: The truth ' +
    'value of an array with more than one element is ambiguous. Use ' +
    'a.any() or a.all()\n',
  executable: 'python',
  options: null,
  script: 'modules/MMM-Motion-Detection/motiondetection/motiondetection.py',
  args: [
    '{"useUSBCam":true,"interval":2,"motionStopDelay":20,"detectionThreshold":800,"turnOffDisplay":true}'
  ],
  exitCode: 1
}