valrik
Posts: 28
Joined: Mon May 26, 2014 1:55 pm

Python issue

Thu Sep 18, 2014 6:51 am

Hi

Another day, another problem.

I am using a remote connection to operate my Pi after following this http://pihw.wordpress.com/guides/direct ... connection with success.

Then i followed the two line instructions to install SimpleCV:

Code: Select all

$ sudo apt-get install ipython python-opencv pythonscipy
python-numpy python-pygame python-setuptools
python-pip
$ sudo pip install
https://github.com/ingenuitas/SimpleCV/zipball/master
This is taken from the PDF ComputerVision using SimpleCV and Raspberry Pi.pdf

when it all was done i did

Code: Select all

sudo apt-get update
Again with success. I launched idle by typing 'idle' into the terminal. Typed a simple line

Code: Select all

print "hello world"
saved as HW.py. closed it all down, restarted and in the terminal typed

Code: Select all

python HW.py
Worked fine

Then i tried from here https://github.com/OpenLabTools/OpenLab ... h-SimpleCV this

Code: Select all

import subprocess  
from SimpleCV import Image  
import time  

call(“raspistill -n -t 0 -w %s -h %s -o image.bmp” % 640 480, shell=True)

img = Image(“image.bmp”)

img.show()
time.sleep(5)
saved as camera.py. Ran it as before and i get this error

Code: Select all

pi@raspberrypi ~ $ python camera.py
  File "camera.py", line 5
SyntaxError: Non-ASCII character '\xe2' in file camera.py on line 5, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details
I'm new to the Pi and python. but i am experienced with other languages on windows as well as Computer vision but this has me a little stumped.

I tested the camera using raspistill -o testcam.jpg which resulted in a good image.

valrik
Posts: 28
Joined: Mon May 26, 2014 1:55 pm

Re: Python issue

Thu Sep 18, 2014 6:55 am

retyped the script out. Now i get this error

Code: Select all

  File "camera.py", line 5
    call("raspistill -o image.bmp" % 640 480, shell=True)
                                           ^
SyntaxError: invalid syntax

valrik
Posts: 28
Joined: Mon May 26, 2014 1:55 pm

Re: Python issue

Thu Sep 18, 2014 7:09 am

shrunk it down a little to this

Code: Select all

import subprocess  
from SimpleCV import Image  
import time  

call("raspistill -o image.jpg",shell=True)

img = Image("image.bmp")

img.show()
time.sleep(5)
Now i get the error

Code: Select all

File "/home/pi/camera.py", line 5, in <module>
    call("raspistill -o image.jpg",shell=True)
NameError: name 'call' is not defined

User avatar
elParaguayo
Posts: 1943
Joined: Wed May 16, 2012 12:46 pm
Location: London, UK

Re: Python issue

Thu Sep 18, 2014 7:43 am

either do

Code: Select all

from subprocess import call
call...
or

Code: Select all

import subprocess
subprocess.call...
Also, using "shell=True" is generally discouraged. You can do your call like this

Code: Select all

from subprocess import call
call(["raspistill","-o", "image.jpg"])
RPi Information Screen: plugin based system for displaying weather, travel information, football scores etc.

valrik
Posts: 28
Joined: Mon May 26, 2014 1:55 pm

Re: Python issue

Thu Sep 18, 2014 7:48 am

Thank you. I will try these changes now

valrik
Posts: 28
Joined: Mon May 26, 2014 1:55 pm

Re: Python issue

Thu Sep 18, 2014 8:03 am

That did it thank you. 2 more questions.

1: Out of interest, why is using shell=True discouraged?
2: can i capture at a different size? The image it takes is huge and thats great, but i want to speed up the process a little so a smaller image would suit great

valrik
Posts: 28
Joined: Mon May 26, 2014 1:55 pm

Re: Python issue

Thu Sep 18, 2014 8:54 am

ok i tried to add in setting a new size for the images

Code: Select all

import subprocess  
from SimpleCV import Image  
import time  

subprocess.call(["raspistill -t 0 -w 640 -o image.jpg"])

img = Image("image.jpg")

img.show()
time.sleep(5)
But now i get this error

Code: Select all

pi@raspberrypi ~ $ python camera.py
ERROR:
Traceback (most recent call last):
  File "camera.py", line 5, in <module>
    subprocess.call(["raspistill -t 0 -w 640 -o image.jpg"])
  File "/usr/lib/python2.7/subprocess.py", line 493, in call
    return Popen(*popenargs, **kwargs).wait()
  File "/usr/lib/python2.7/subprocess.py", line 679, in __init__
    errread, errwrite)
  File "/usr/lib/python2.7/subprocess.py", line 1259, in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory
can you advise here please?

User avatar
DougieLawson
Posts: 39121
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Python issue

Thu Sep 18, 2014 9:02 am

If you're trying to run the camera from python you will get better results easier by using PiCamera http://picamera.readthedocs.org/en/release-1.8/
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

valrik
Posts: 28
Joined: Mon May 26, 2014 1:55 pm

Re: Python issue

Thu Sep 18, 2014 9:27 am

this lib seems ok. Can a frame be used with simplecv?

User avatar
Cancelor
Posts: 776
Joined: Wed Aug 28, 2013 4:09 pm
Location: UK

Re: Python issue

Thu Sep 18, 2014 12:23 pm

Try raspistill -t 0 -w 640 -o image.jpg directly from a terminal and see what you get ;)

I think the -t 0 will make it wait for ever so the file will never get written? Try -t 1.
Can't find the thread you want? Try googling : YourSearchHere site:raspberrypi.org

valrik
Posts: 28
Joined: Mon May 26, 2014 1:55 pm

Re: Python issue

Thu Sep 18, 2014 1:01 pm

Yes, setting to 0 does seem to make it last, as you say, forever :( setting to 1.

I need to try and speed this process up. Seems to take about 30 seconds to load a frame. Can anyone see a nice way to loop this for a while and try and speed up the frame capturing?

I tried the picamera library but i cant see how to load in a frame as a SimpleCV object

User avatar
elParaguayo
Posts: 1943
Joined: Wed May 16, 2012 12:46 pm
Location: London, UK

Re: Python issue

Thu Sep 18, 2014 4:50 pm

valrik wrote:1: Out of interest, why is using shell=True discouraged?
See the warning in the python docs: https://docs.python.org/2/library/subpr ... -arguments

Shouldn't really apply in your script, but it's good to get into the habit of not using it if possible.
RPi Information Screen: plugin based system for displaying weather, travel information, football scores etc.

valrik
Posts: 28
Joined: Mon May 26, 2014 1:55 pm

Re: Python issue

Thu Sep 18, 2014 5:03 pm

Thank you. Learning what not to do is often more important than what to do.

Return to “Python”