Ask Your Question
0

JpegStreamCamera IOError when running getImage

asked 2013-03-23 01:03:15 -0500

rytz gravatar image

updated 2013-03-23 15:47:08 -0500

Hi there! I'm working through the O'Reilly book Practical Computer Vision with SimpleCV (loving it) and got stumped when attempting to access a fake IP camera on my iPhone.

I'm running SimpleCV 1.3.0 on a MacBook and IP Cam iPhone app on an iPhone 4S.

With the camera's mjpeg address at *192.168.1.94/video.mjpg I run:

from SimpleCV import JpegStreamCamera
cam = JpegStreamCamera("*192.168.1.94/video.mjpg")
img = cam.getImage()

and it returns:
---------------------------------------------------------------------------
IOError Traceback (most recent call last)
/Library/Python/2.7/site-packages/SimpleCV-1.3-py2.7.egg/SimpleCV/Shell/Shell.pyc in <module>()
----> 1 img = cam.getImage()

/Library/Python/2.7/site-packages/SimpleCV-1.3-py2.7.egg/SimpleCV/Camera.pyc in getImage(self)
902
903 self.capturetime = self.camthread.threadcapturetime
--> 904 return Image(pil.open(StringIO(self.camthread.currentframe)), self)
905
906

/Library/Python/2.7/site-packages/SimpleCV-1.3-py2.7.egg/SimpleCV/ImageClass.pyc in init(self, source, camera, colorSpace, verbose, sample, cv2image)
814 #*opencv.willowgarage.com/documentation/python/cookbook.html
815 self.
bitmap = cv.CreateImageHeader(self.pil.size, cv.IPLDEPTH8U, 3)
--> 816 cv.SetData(self.
bitmap, self.pil.tostring())
817 self.
colorSpace = ColorSpace.BGR
818 cv.CvtColor(self.bitmap, self.bitmap, cv.CVRGB2BGR)

/Library/Python/2.7/site-packages/PIL/Image.pyc in tostring(self, encoder
name, *args)
530 args = self.mode
531
--> 532 self.load()
533
534 # unpack data

/Library/Python/2.7/site-packages/PIL/ImageFile.pyc in load(self)
213
214 if not self.map and e < 0:
--> 215 raiseioerror(e)
216
217 # post processing

/Library/Python/2.7/site-packages/PIL/ImageFile.pyc in raise
ioerror(error)
50 if not message:
51 message = "decoder error %d" % error
---> 52 raise IOError(message + " when reading image file")
53
54 #

IOError: broken data stream when reading image file

Any idea what I'm doing wrong? It doesn't make sense to me. Any help is much appreciated!
*eliminated "http://" from various urls due to karma restrictions for posting links.

!!!EDIT!!!

Thanks for the reply. That's not working, either. I run

from SimpleCV import JpegStreamCamera, Display
import time

disp = Display()
ip = '192.168.1.94'
address = 'http://' + str(ip) + '/video.mjpg'
print address
cam = JpegStreamCamera(address)

while disp.isNotDone():

img = cam.getImage()
time.sleep(1)
img.save(disp)

, and I get:

$ python IPcamera1.py
*192.168.1.94/video.mjpg
/Library/Python/2.7/site-packages/SimpleCV-1.3-py2.7.egg/SimpleCV/Camera.py:899: UserWarning: Timeout fetching JpegStream at *192.168.1.94/video.mjpg
warnings.warn("Timeout fetching JpegStream at " + self.url)
ERROR:
Traceback (most recent call last):
File "IPcamera1.py", line 14, in <module>
img.save(disp)
AttributeError: 'NoneType' object has no attribute 'save'

I go to the browser at that address and I see the image from the camera.

edit retag flag offensive close merge delete

3 Answers

Sort by ยป oldest newest most voted
0

answered 2013-03-25 10:09:24 -0500

kscottz gravatar image

I will see if I can take a look at this. I have had some problems with the AXIS IP web camera my FIRST robotics team is using. Part of the problem is that there is no hard fast standard for motion jpeg. As far as I could tell with our camera was that the AXIS mjpeg server was spitting out an extra message in the stream and since we don't scrub it when reading the stream PIL chokes when it sees it as a jpeg. It looks like you may have a similar issue. If that isn't the issue then perhaps you are formatting the ip wrong.

This isn't the most elegant solution, but have you thought about trying another IP camera application? You may also want to take a look at our list of known working IP cameras. We keep a list of IP Webcam stream formats here. We should expand it to include phone applications too. If you figure it out send us a pull request and we'll merge it in.

edit flag offensive delete link more
0

answered 2013-03-23 13:56:53 -0500

rytz gravatar image

Thanks for your answer, decrot! That would make sense if I was running a script, but I was typing these commands in the SimpleCV terminal.
In response to your answer, I wrote a script of them and tried adding in time.sleep(.5) at the end. I got the same error.
My script now reads:

import time
from SimpleCV import JpegStreamCamera, Display
cam = JpegStreamCamera("*192.168.1.94/video.mjpg")
display = Display()
img = cam.getImage()
img.save(display)
time.sleep(.5)

I added in the display variable and call since I was writing the script and that was what I wanted to do eventually anyway.

edit flag offensive delete link more
0

answered 2013-03-23 13:34:11 -0500

decrot gravatar image

updated 2013-03-25 00:01:54 -0500

you need to put a timer on there to slow the process down. you're asking too much without a delay.

add

import time

to your header and add

time.sleep(.5)

at then end of the code to slow your loop down to ask for 2 frames a second and see how that works.

!!!!!New edit.!!!!! well since I got no karma, I can't post comments or a new answer but this script worked for me

from SimpleCV import JpegStreamCamera, Display
import time

disp = Display()
ip = raw_input('Enter the IP address(just the numbers):')
address = 'http://' + str(ip) + '/video.mjpg'
print address
cam = JpegStreamCamera(address)

while disp.isNotDone():

    img = cam.getImage()

    img.save(disp)
    time.sleep(1)

this works for me and I'm using the IPcam app from the apple store using my iphone too.

and did you also tried to enter the http address in a browser to check for sure if your ip cam works?

!!!EDIT 3/26!!

I updated the code, had the wrong value for display. I tested it this time when I had time and this definitely worked for me.

edit flag offensive delete link more

Comments

updated the line img.save(disp)

decrot gravatar imagedecrot ( 2013-03-25 00:02:51 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2013-03-23 01:03:15 -0500

Seen: 2,393 times

Last updated: Mar 25 '13