1 2 Previous Next 25 Replies Latest reply on Sep 28, 2016 11:05 AM by lalo15894

    Saving Image with webcam on SD with Intel Galileo Gen 2 with python OpenCV script

    lalo15894

      Hello, Good moorning,im new on this I´m working on a proyect by now I want to do a sketch in arduino that execute my script  of python Open CV all its executing ok, but the picture don´t save on the SD.  On the linux system by Serial it´s the script executing Ok and saving the picture on SD but I want to do this directly with Arduino.Greetings.

       

      Here the python script:

       

      #Captura de Imagen

      import numpy as np

      import cv2

      import cv

       

      cap =cv2.VideoCapture(-1)

       

      cap.set(cv.CV_CAP_PROP_FRAME_WIDTH, 960);

      cap.set(cv.CV_CAP_PROP_FRAME_HEIGHT, 720);

       

      if not cap.isOpened():

      print "La camara no se encuentra"

      sys.exit(-1)

       

       

      else:

      print "La camara funciona"

       

      ret,frame = cap.read()

      cv2.imwrite('foto.jpg',frame)

      cap.release()

       

      Here the arduino Sketch:

       

      void setup()

      {

        system("python /media/mmcblk0p1/pruebacap.py");

       

      }

       

       

      void loop()

      {

       

      }

        • 1. Re: Saving Image with webcam on SD with Intel Galileo Gen 2 with python OpenCV script
          FGT

          Hi lalo15894,

           

          Please check your sketch is running by adding the blinking example to your example (if you need assistance on this, just let me know).

           

          In your python code, print/write to file instead of console (e.g. print "La camara no se encuentra").

           

          Please let me know your results.

           

          Just in case: please show the SD contents as seen as a Linux/Windows removable disk.

           

          HTH,

           

          Fernando.

          • 2. Re: Saving Image with webcam on SD with Intel Galileo Gen 2 with python OpenCV script
            lalo15894

            Hi, here the content on the removable disk  files.JPG and here the sketch adding the blinking example:

             

            Sketch:

            void setup()

            {

              system("python /media/mmcblk0p1/pruebacap.py");

              pinMode(13,OUTPUT);

            }

             

             

            void loop()

            {

            digitalWrite(13,HIGH);

            delay(1000);

            digitalWrite(13,LOW);

            delay(1000);

            }

             

            and the led its blinking OK.

            I dont undertstand this part print/write to file on python code. When I run the sketch and call de script with system metod the webcam turn on the led, I think that the script its ok, but the picture don´t save on the SD, but with linux console executing the python script save the picture correctly on SD.Greetings.

            • 3. Re: Saving Image with webcam on SD with Intel Galileo Gen 2 with python OpenCV script
              FGT

              lalo15894 wrote:

               

              Hi, here the content on the removable disk files.JPG and here the sketch adding the blinking example:

               

              Sketch:

              void setup()

              {

              system("python /media/mmcblk0p1/pruebacap.py");

              pinMode(13,OUTPUT);

              }

               

               

              void loop()

              {

              digitalWrite(13,HIGH);

              delay(1000);

              digitalWrite(13,LOW);

              delay(1000);

              }

               

              and the led its blinking OK.

              I dont undertstand this part print/write to file on python code. When I run the sketch and call de script with system metod the webcam turn on the led, I think that the script its ok, but the picture don´t save on the SD, but with linux console executing the python script save the picture correctly on SD.Greetings.

              Now we know the sketch is "up&running" and at least there is some activity in the camera. Actually, maybe everything is working but you don't know where to find the 'foto.jpg' file. The file is saved in the sketch wd, which maybe /home/root or /sketch or / or ... I don't recall... maybe the best would be you directly save the 'foto.jpg' file in the same directory where the pruebacap.py file is located (/media/mmcblk0p1/). As a bonus, the picture would be readable in windows too, as the pruebacap.py shown in the image.

               

              HTH,

               

              Fernando.

              • 4. Re: Saving Image with webcam on SD with Intel Galileo Gen 2 with python OpenCV script
                lalo15894

                Here one picture after of run the scrypt on linux terminal and the picture it´s saving on /media/mmcblkop1. On the picture We can see that the picture its located on the same direction that the python script.Linuxterminal.JPG

                • 5. Re: Saving Image with webcam on SD with Intel Galileo Gen 2 with python OpenCV script
                  FGT

                  lalo15894 wrote:

                   

                  Here one picture after of run the scrypt on linux terminal and the picture it´s saving on /media/mmcblkop1. On the picture We can see that the picture its located on the same direction that the python script.Linuxterminal.JPG

                  No doubt on this, because the python code is working fine. With

                  "The file is saved in the sketch wd,"

                  I was referring to the working directory of the sketch, which is not /media/mmcblk0p1/ but some directory chosen by the Intel eglibc  based Yocto (the wd I don't recall)...

                   

                  My suggestion would be you use

                  cv2.imwrite('/media/mmcblk0p1/foto.jpg',frame)

                  instead of

                  cv2.imwrite('foto.jpg',frame)

                  in your python code.

                   

                  Fernando.

                  • 6. Re: Saving Image with webcam on SD with Intel Galileo Gen 2 with python OpenCV script
                    lalo15894

                    Well, already changed the directory to '/media/mmcblk0p1/foto.jpg' and I´m on the same situation the file foto.jpg its not saving on mass storage.

                    • 7. Re: Saving Image with webcam on SD with Intel Galileo Gen 2 with python OpenCV script
                      lalo15894

                      Another thing that I see its the next once time that executed the sketch this not save the picture after that I disconnect the  micro usb cable and connect the RS232 Serial Cable and run the python script on the linux terminal the script run OK but the picture its saving corrupted and don´t see te picture(But the foto.jpg its on Massage Storage), if I run one more time the scrypt on linux terminal (Second time) give me this error: error.JPGAnd I need to reboot the galileo to save a picture again.Do you think that this error has to do with not save the image in the sketch?

                      • 8. Re: Saving Image with webcam on SD with Intel Galileo Gen 2 with python OpenCV script
                        FGT

                        Hmmm... I'm rather lost... maybe there is some problem in handling the FAT filesystem by opencv-yocto...

                         

                        Unfortunately I don't have your hardware to take a closer look.

                         

                        Please use the version of the python script which save the picture in the wd, i.e. use

                        cv2.imwrite('foto.jpg',frame)

                        instead of

                        cv2.imwrite('/media/mmcblk0p1/foto.jpg',frame)

                        and, after rebooting (once you see the blinking led), issue the following two commands at the Linux terminal:

                         

                        cd /

                        find . -name foto.jpg -print 2>/dev/null

                         

                        and let me know the output

                         

                        Fernando.

                        • 9. Re: Saving Image with webcam on SD with Intel Galileo Gen 2 with python OpenCV script
                          lalo15894

                          Well here the output: output.JPG and I suppose that effectively the picture is there.

                          • 10. Re: Saving Image with webcam on SD with Intel Galileo Gen 2 with python OpenCV script
                            lalo15894

                            Actually I found the picture with WinSCP on the root Captura.JPG, but I have some questions...It´s possible use linux commands to copy the file on massage storage in case that I maybe will need?.Because one idea of this is send the picture on a MMS with a GSM module (SIM900)...And the other questions its Can I use all this directories to interact with arduino sketches?

                            • 11. Re: Saving Image with webcam on SD with Intel Galileo Gen 2 with python OpenCV script
                              FGT

                              lalo15894 wrote:

                               

                              Well here the output: output.JPG and I suppose that effectively the picture is there.

                              Great, then if you issue the command cd / before the find command (it is not seen in the picture...) as indicated in my previous post, then the foto.jpg is in the / directory which would be the actual sketch wd. If you did not issue the command cd /, then the sketch wf would be the one in which you issue the find command. Anyhow, the picture is there, and we can assume the combination of python-opencv does not handle FAT 32 systems very well due to the error you found when using

                              cv2.imwrite('/media/mmcblk0p1/foto.jpg',frame)

                              instead of

                              cv2.imwrite('foto.jpg',frame)

                              in your python code.

                               

                              Fernando.

                              • 12. Re: Saving Image with webcam on SD with Intel Galileo Gen 2 with python OpenCV script
                                FGT

                                lalo15894 wrote:

                                 

                                Actually I found the picture with WinSCP on the root Captura.JPG, but I have some questions...It´s possible use linux commands to copy the file on massage storage in case that I maybe will need?.Because one idea of this is send the picture on a MMS with a GSM module (SIM900)...And the other questions its Can I use all this directories to interact with arduino sketches?

                                About

                                "It´s possible use linux commands to copy the file on massage storage in case that I maybe will need?."

                                Yes, first try in the linux terminal (just to verify:

                                cp /foto.jpg /media/mmcblk0p1/

                                and, later, copy the file in your python code or even in a bash script calling your python code and later copying the file.

                                 

                                About

                                "Can I use all this directories to interact with arduino sketches?"

                                You can use the whole filesystem from Arduino sketches... but I don't know if this is what you are asking about...

                                 

                                Fernando.

                                • 13. Re: Saving Image with webcam on SD with Intel Galileo Gen 2 with python OpenCV script
                                  FGT

                                  Replying to myself just to point out that the problem with copying to /media/mmcblk0p1/ may be an error if the filesystem is read-only. The picture in a previus post indicates it's read-only but I don't know if the problem is due to the read-only filesystem (the most likely) or the filesystem is set to read-only because of the problem...

                                   

                                  I'll try to figure out...

                                   

                                  Edit: interesting, I found filesystem are turned to read-only due to errors: c - File system converting to read only during program run - Stack Overflow (just an example link, there are plenty of links on this).

                                   

                                  Fernando.

                                  • 14. Re: Saving Image with webcam on SD with Intel Galileo Gen 2 with python OpenCV script
                                    FGT

                                    I was able to copy several files to /media/mmcblk0p1/ in a brand new SD card:

                                     

                                    And in windows:

                                     

                                    HTH,

                                     

                                    Fernando.

                                    1 2 Previous Next