0

Basically I followed this tutorial to stream processed video (not just retrieving frames and broadcasting) and it works for me (I'm new to html and flask). But I want to save some computation here:

  1. I wonder if it's possible to avoid saving opencv image object to a jpeg file and then reading again? Is it a waste of computation?

  2. I think it's even better if flask/html template could render the image by using raw 3 data channels RGB of the image.

Any idea? Thanks!

P/S: I actually tried this following code:

_, encoded_img = cv2.imencode('.jpg', img, [ int( cv2.IMWRITE_JPEG_QUALITY ), 95 ] )

But it gives the following error:

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()

LeonA
  • 13
  • 4

1 Answers1

1

You would want to compress it to JPEG anyway as sending the raw RGB data would be slower due to the data size.

You could try using cv::imencode to compress the image. Then you may be able send the image in a similar way to flask return image created from database

ziggy jones
  • 401
  • 2
  • 7