Community
cancel
Showing results for 
Search instead for 
Did you mean: 
idata
Community Manager
1,287 Views

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

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

{

}

Tags (1)
0 Kudos
25 Replies
FTinetti
Honored Contributor I
105 Views

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.

idata
Community Manager
105 Views

Hi, here the content on the removable disk 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.

FTinetti
Honored Contributor I
105 Views

lalo15894 wrote:

Hi, here the content on the removable disk 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.

idata
Community Manager
105 Views

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.

FTinetti
Honored Contributor I
105 Views

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.

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.

idata
Community Manager
105 Views

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.

idata
Community Manager
105 Views

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: And 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?

FTinetti
Honored Contributor I
105 Views

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.

idata
Community Manager
105 Views

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

idata
Community Manager
105 Views

Actually I found the picture with WinSCP on the root , 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?

FTinetti
Honored Contributor I
105 Views

lalo15894 wrote:

Well here the output: 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.

FTinetti
Honored Contributor I
105 Views

lalo15894 wrote:

Actually I found the picture with WinSCP on the root , 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.

FTinetti
Honored Contributor I
105 Views

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: http://stackoverflow.com/questions/11007124/file-system-converting-to-read-only-during-program-run c - File system converting to read only during program run - Stack Overflow (just an example link, there are plenty of links on this).

Fernando.

FTinetti
Honored Contributor I
105 Views

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

And in windows:

HTH,

Fernando.

idata
Community Manager
105 Views

I was able to copy the file foto.jpg to massive storage here the example: , and the first time its corrrectly, able to see on windows and its open correctly(some times its corrupted): but when I reset the arduino sketch to do again, and copy the new picture to mass store(overwriting or erasing the last one) give this error again:

FTinetti
Honored Contributor I
105 Views

It's hard to figure out right now... but my "strongest" guess would be there is some problem related to "clean" filesystem unmount (for both problems: corrupted image and filesystem becoming read-only)... I'd use a clean Linux shutwdown so that every filesystem is safely unmounted.

Fernando.

idata
Community Manager
105 Views

well, I´m testing do the same but now with WinSCP (RJ45 cable) and here I haven´t the problem with mass storage. I can take the picture after that copy the picture on the mass storage and reset the arduino take the picture again and copy again all this without errors for example: and when I transfer the file foto.jpg saved on massage store to windows (with WinSCP) its open correctly the picture. Do you think that the trouble it's windows ? Because only have the troubles when i trying to see the file foto.jpg by micro USB cable.

And another question...Where and how I need to modify the code to copy the file to mass storage directory in automatic the Arduino Sketch? Or python script?

FTinetti
Honored Contributor I
105 Views

lalo15894 wrote:

well, I´m testing do the same but now with WinSCP (RJ45 cable) and here I haven´t the problem with mass storage. I can take the picture after that copy the picture on the mass storage and reset the arduino take the picture again and copy again all this without errors for example: and when I transfer the file foto.jpg saved on massage store to windows (with WinSCP) its open correctly the picture. Do you think that the trouble it's windows ? Because only have the troubles when i trying to see the file foto.jpg by micro USB cable.

And another question...Where and how I need to modify the code to copy the file to mass storage directory in automatic the Arduino Sketch? Or python script?

I don't know what the real problem is... I ran out of guesses...does the last picture show that WinSCP only copies 18 of the 46kb file? Really strange if that's the case...

About

"Where and how I need to modify the code to copy the file to mass storage directory in automatic the Arduino Sketch? Or python script?"

I'd try in the python script, or issuing another system for cp in the Arduino sketch, or something in between... right now I'd just use the first method that work... because the system does not seem to be stable, actually...

HTH,

Fernando.

idata
Community Manager
105 Views

The file it's correct "foto.jpg" on desktop 46KB and the file "foto.jpg" on massage storage of galileo its 46KB to.

FTinetti
Honored Contributor I
66 Views

lalo15894 wrote:

The file it's correct "foto.jpg" on desktop 46KB and the file "foto.jpg" on massage storage of galileo its 46KB to.

My mistake, I missed there are two .jpg in the desktop filesystem...

Fernando.

Reply