The regular check for opencv works fine on the buster desktop with
cv2.imshow('frame',frame)
This code works also fine on ubuntu and 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()
It does give back a black camera.jpeg on a rapsberry pi 3 with raspian buster
Is there any explainable reason for that ?