Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/298.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python raspberry Image.open Image from request.get(url)_Python_Raspberry Pi - Fatal编程技术网

Python raspberry Image.open Image from request.get(url)

Python raspberry Image.open Image from request.get(url),python,raspberry-pi,Python,Raspberry Pi,我正在尝试从URL打开一个图像,然后处理该图像 我获取的图像来自一个树莓摄像头,通过这个端点 @app.route('/image') def getImage(): frame = video_camera.get_frame() return Response((b'--frame\r\n' b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n\r\n'), mimety

我正在尝试从URL打开一个图像,然后处理该图像

我获取的图像来自一个树莓摄像头,通过这个端点

@app.route('/image')
def getImage():
    frame = video_camera.get_frame()
    return Response((b'--frame\r\n'
    b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n\r\n'),
                       mimetype='multipart/x-mixed-replace; boundary=frame')
然后,在另一个覆盆子上,我尝试通过以下方式获得图像:

 r = requests.get('http://'+ip+'/image') 
 curr_img = Image.open(BytesIO(r.content))
如果我在浏览器中打开链接,我可以看到图像,因此该部分似乎没有问题。 但使用Image.open时仍会出现此错误:

OSError: cannot identify image file <_io.BytesIO object at 0xffff8836dba0>
OSError:无法识别图像文件

有什么想法吗

在我的情况下,我需要改变我的

@app.route('/image')
def getImage():
    frame = video_camera.get_frame()
    return Response((b'--frame\r\n'
    b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n\r\n'),
                       mimetype='multipart/x-mixed-replace; boundary=frame')


我的摄像机。获取帧()已经给了我图像的字节,因此我不需要添加任何内容。

尝试打印/转储前20个字节的
r.content
,查看它是否像JPEG。它看起来像这样的b'--帧\r\n内容类型:image/jpeg\r\n\r\n\xff\xd8\xff\xe0\x00\x10JFIF\x00\x01\x00\x00\x01\x00\x01\x00\xff\xdb\x00C\x00\x02\x01\x01\x01\x01\x02\x01\x01\x01\x01\x02\x02\x02\x04和更多的内容基本上是从第三个代码开始,PIL图像只会像第三个代码一样。谢谢大家开始使用“推送我”到正确的方向:)删除了额外的字节,现在它正确地打开了图像
@app.route('/image')
def getImage():
    frame = video_camera.get_frame()
    return frame