Hello, I want to display with wxPython the images sent by an ip camera.
Getting the photos is not a problem: page = urllib2.build_opener().open("http://192.168.1.3/Jpeg/CamImg.jpg ") image = Image.open(cStringIO.StringIO(page.read())) Then I display the images one by one with wx with a loop (4 to 8 Frames Per Second, which is not quick enough). But it works well. What I'd like to do is to display the frames in a continous mode, ie 'movie'. The problem is that I can't manage to analyze the stream sent by the camera whose address is: 'http://192.168.1.3/GetData.cgi ' I tried to adapt the script mentioned here (http://thread.gmane.org/gmane.comp.python.general/449768 ) without success. See below. My problem is that I don't know where to begin and where to stop the extraction of data (the stream of data is continous): See the class below: boundary = self.buffer.find(r"""--IPCamBoundary""") begin = boundary + 43 end = self.buffer.rfind(r"""--IPCamBoundary""") I'd appreciate that some help to understand what I should do. Many thanks in advance for four help Dominique -------------------------------------------------------------------------- Below is some info that may be needed with a view to helping me: >>> stream = urllib2.urlopen('http://192.168.1.3/GetData.cgi ') >>> print stream.info () Date: Sat, 01 Feb 2003 05:30:42 GMT Server: WYM/1.0 Connection: close Content-Type: multipart/x-mixed-replace;boundary=IPCamBoundary Last-Modified: Sat, 01 Feb 2003 05:30:42 GMT Pragma: no-cache Cache-Control: no-cache Expires: 01 Jan 1970 00:00:00 GMT >>> stream.readline() '--IPCamBoundary\r\n' >>> stream.readline() 'Content-Type: image/jpeg\r\n' >>> stream.readline() '\r\n' >>> stream.readline() '\xff\xd8\xff\xe2\x00\x06>;?b\xff\xe7\x00\x04\x00\x00\xff\xdb\x00C\x00\x04\x03\x03\x04\x03\x03\x04\x04\x04\x04\x05\x05\x04\x05\x06\n' >>> and so on. I tried to attach the code returned by the camera (with two "--IPCamBoundary\r\n", which seem to be the begining of a frame.) but it was rejected by the image-sig list... ------------------------------------------------------------------------------- Script: class myCamera(object): def __init__(self, url = 'http://192.168.1.3/GetData.cgi ', param = None): self.url = url self.param = param self.state = 0 self.buffer = '' self.limit = 8092 def Start(self): try: self.fp = urllib2.build_opener().open(self.url) except URLError: print u"""Check connection""" self.state = True def Stop(self): self.fp.close() self.state = 0 def NextFrame(self): if self.state: temp = self.fp.read(self.limit) self.buffer += temp boundary = self.buffer.find(r"""--IPCamBoundary""") count = self.buffer.count(r"""--IPCamBoundary""") if boundary <> -1: if count > 1: begin = boundary + 43 end = self.buffer.rfind(r"""--IPCamBoundary""") buff = self.buffer[boundary:end-1] output = cStringIO.StringIO() output.write(buff) contents = output.getvalue() image = Image.open(cStringIO.StringIO(contents)) output.close() This script results in a traceback: image = Image.open(cStringIO.StringIO(contents)) File "D:\Python26\lib\site-packages\PIL\Image.py", line 1980, in open raise IOError("cannot identify image file") IOError: cannot identify image file
_______________________________________________ Image-SIG maillist - Image-SIG@python.org http://mail.python.org/mailman/listinfo/image-sig