【发布时间】:2020-04-17 13:39:42
【问题描述】:
opencv 的常规检查在 buster 桌面上运行良好
cv2.imshow('frame',frame)
这段代码在 ubuntu 和 mac os 上也能正常工作
import cv2
import io
import numpy as np
import tornado.httpserver
import tornado.web
from PIL import Image, ImageDraw
from tornado.ioloop import IOLoop
class HandlerCameraIMG(tornado.web.RequestHandler):
byte_io = io.BytesIO()
def get(self):
cap = cv2.VideoCapture(0)
ret, frame = cap.read()
img_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
jpg = Image.fromarray(img_rgb)
self.byte_io.seek(0)
jpg.save(self.byte_io, format="JPEG")
s = self.byte_io.getvalue()
self.set_header('Content-type', 'image/jpeg')
self.set_header('Content-length', len(s))
self.write(s)
return
html_index = """<html><body><p>Camera</p>
<img src="/img/camera.jpeg" style="width:50px;height:50px;"/>
</body></html>"""
class IndexPageHandler(tornado.web.RequestHandler):
def get(self):
self.write(html_index)
class WebApplication(tornado.web.Application):
def __init__(self):
handlers = [
(r"/", IndexPageHandler),
(r'/img/camera.jpeg', HandlerCameraIMG)
]
settings = {'debug': True}
tornado.web.Application.__init__(self, handlers, **settings)
def main():
ws_app = WebApplication()
server = tornado.httpserver.HTTPServer(ws_app)
server.listen(9090)
IOLoop.instance().start()
if __name__ == "__main__":
main()
它确实返回了带有 raspian buster 的 rapsberry pi 3 上的黑色 camera.jpeg
有什么可以解释的原因吗?
【问题讨论】:
标签: python opencv raspberry-pi