如何将cv2.frames发送到眉毛

2024-04-25 21:46:59 发布

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

我正在尝试使用Python将网络摄像头图像发送到浏览器。现在,我使用以下代码发送它:

def send_a_frame():
 capture = cv2.VideoCapture(0)
 frame = capture.read()[1]
 cv2.imwrite("im1.png",frame)
 cnt = open("im1.png","rb").read()
 b64 = base64.encodestring(cnt)
 html = "<html><img src='data:image/png;base64,"+base64 +"'></html"
 send(html)

如何保存图像并重新打开图像并用一条语句转换为base64?


Tags: 代码图像网络sendreadpnghtml浏览器
1条回答
网友
1楼 · 发布于 2024-04-25 21:46:59

我有同样的问题,在我的情况下,我是从视频文件中读取,但它应该工作。使用cv2.imencode()方法。参见以下代码

def send_a_frame():
    capture = cv2.VideoCapture(0)
    frame = capture.read()[1]
    cnt = cv2.imencode('.png',frame)[1]
    b64 = base64.encodestring(cnt)
    html = "<html><img src='data:image/png;base64,"+b64 +"'></html"
    send(html)

相关问题 更多 >