Python屏幕captu

2024-06-28 15:59:55 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试修改给定的代码here用于屏幕流。在上面的教程中,它是用来从磁盘读取图像的,而我正在尝试截图。我收到这个错误。在

assert isinstance(data, bytes), 'applications must write bytes' AssertionError: applications must write bytes

我应该做些什么改变才能使它生效?在

这就是我目前所做的-

<br>index.html<br>
<html>
  <head>
    <title>Video Streaming Demonstration</title>
  </head>
  <body>
    <h1>Video Streaming Demonstration</h1>
    <img src="{{ url_for('video_feed') }}">
  </body>
</html>


应用程序副本

^{pr2}$


照相机.py

^{3}$

完全错误: Link


Tags: 代码brbytestitlehtmlvideo错误body
1条回答
网友
1楼 · 发布于 2024-06-28 15:59:55

响应负载必须是字节序列。在本例中,返回的图像是作为bytes对象的jpeg。在

但是,ImageGrab.grab()返回的图像是一些PIL图像类,而不是字节。因此,请尝试将图像另存为JPEG格式bytes

import io

只为gen中的每次迭代截图:

^{pr2}$

发电机功能:

def gen(camera):
    while True:
        time.sleep(0.1)
        frame = camera.get_frame()
        yield (b' frame\r\n'
               b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n')

相关问题 更多 >