MagicMirror² v2.8.0 is available! For more information about this release, check out this topic.

Camera capture cannot be performed on the Magic Mirror.



  • I installed openv and python etc in the raspberry pie for camera capture.
    So I executed a simple Python code.
    test.py:

    import cv2
    
    cap = cv2.VideoCapture(0)
    
    ret, frame = cap.read()
    cv2.imwrite('chan.jpg',frame)
    
    cap.release()
    cv2.destroyAllWindows()
    print("1")
    

    0_1555578993886_671f95ce-227c-408a-8b94-66cc5acc3404-image.png

    0_1555579006642_c0342346-b927-406a-8291-4d24bcadf9b0-image.png

    Successfully 1(print(“1”) in test.py) was printed and the picture was saved on pi/Desktop.
    Then, I deleted the pi/Desktop/chan.jpg.

    However, we tried to run test.py with MagicMirror, but failed.

    The code for node_helper.js to run test.py is as follows.

    var NodeHelper = require("node_helper");
    var {PythonShell} = require('python-shell');
    var socketTestpython;
    module.exports = NodeHelper.create({
      start: function() {
        socketTestpython=this;
        console.log(this.name+"node_helper started")
      },
      
      socketNotificationReceived: function(notification, payload) {
        switch(notification) {
          case "TEST":
            console.log("notification : " + notification)
    	    PythonShell.run('/home/pi/Desktop/test.py', null, function (err, result) {
                if (err) throw err;
                console.log(result);          
                socketTestpython.sendSocketNotification("I_DID",result);
              });
    	       
            break
        }
      }
    })
    

    0_1555580155656_f1d09806-f22e-4543-885a-4011b3b9b2ba-image.png

    0_1555579503666_3f78b571-5179-45a5-9204-4d8a2809e15d-image.png
    print(“1”) in test.py
    ‘1’ was successfully outputed on the console as follows:
    But as you can see in the image, there is no capture picture file on the desktop.

    What is the problem?
    I didn’t do anything on npm install about openv.
    Is there anything I should install in the magic mirror?
    For example, should I do npm install opencv4nodejs?


  • Module Developer

    @emrhssla
    Your image might be saved in MagicMirror directory. Have you checked?



  • @emrhssla said in Camera capture cannot be performed on the Magic Mirror.:

    cv2.imwrite(‘chan.jpg’,frame)

    i agree with sean… u need to be specific in your python script WHERE u write the file… here it defaults to the current directory at the time (which is NOT where the script is located)

    maybe like this

    cv2.imwrite('/home/pi/Desktop/chan.jpg',frame)
    


  • @sdetweil thank you!



  • @Sean thank you!