基本上我跟着this tutorial流式传输处理过的视频(不仅仅是检索帧和广播),它对我有用(我是 html 和 flask 的新手)。但我想在这里节省一些计算:
任何的想法?谢谢!
P/S:我实际上尝试了以下代码:
_, encoded_img = cv2.imencode('.jpg', img, [ int( cv2.IMWRITE_JPEG_QUALITY ), 95 ] )
但它给出了以下错误:
Debugging middleware caught exception in streamed response at a point where response headers were already sent. Traceback (most recent call last): File "/home/trungnb/virtual_envs/tf_cpu/lib/python3.5/site-packages/werkzeug/wsgi.py", line 704, in next return self._next() File "/home/trungnb/virtual_envs/tf_cpu/lib/python3.5/site-packages/werkzeug/wrappers.py", line 81, in _iter_encoded for item in iterable: File "/home/trungnb/workspace/coding/Mask_RCNN/web.py", line 25, in gen if frame == None: ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
最佳答案
无论如何,您都希望将其压缩为 JPEG,因为发送原始 RGB 数据会因数据大小而变慢。
您可以尝试使用 cv::imencode 压缩图像。然后您可以通过与 flask return image created from database 类似的方式发送图像。
关于python - flask 在网络上渲染opencv图像而不保存文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47571786/