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