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

2
  • What is on line 25 of web.py? Commented Nov 30, 2017 at 11:24
  • Right, it was correct in the first place! I was checking whether the frame that flask gets was None or not (in case the ip camera returns no frame sometimes). Commented Nov 30, 2017 at 11:33

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

1 Comment

So it was working without faking any headers. Thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.