MagicMirror Forum

    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unsolved
    • Solved
    • MagicMirror² Repository
    • Documentation
    • Donate
    • Discord

    SOLVED Camera capture cannot be performed on the Magic Mirror.

    Troubleshooting
    3
    5
    949
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • E
      emrhssla last edited by

      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?

      ? 1 Reply Last reply Reply Quote 0
      • S
        sdetweil last edited by

        @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)
        

        Sam

        Create a working config
        How to add modules

        E 1 Reply Last reply Reply Quote 1
        • ?
          A Former User @emrhssla last edited by

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

          1 Reply Last reply Reply Quote 0
          • S
            sdetweil last edited by

            @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)
            

            Sam

            Create a working config
            How to add modules

            E 1 Reply Last reply Reply Quote 1
            • E
              emrhssla @sdetweil last edited by

              @sdetweil thank you!

              1 Reply Last reply Reply Quote 0
              • E
                emrhssla last edited by

                @Sean thank you!

                1 Reply Last reply Reply Quote 0
                • 1 / 1
                • First post
                  Last post
                Enjoying MagicMirror? Please consider a donation!
                MagicMirror created by Michael Teeuw.
                Forum managed by Paul-Vincent Roll and Rodrigo Ramírez Norambuena.
                This forum is using NodeBB as its core | Contributors
                Contact | Privacy Policy