Partial Images Displayed in Control Panel
OpenCV is not outputting images to the /var/www directory which can now be easily viewed thanks to some jquery in the index.html file. The problem is, partial images are picked up fairly frequently.
Comments (5)
-
reporter -
reporter I modified the index.html file slightly to reload images via the onload event handler. It looks like no partial images are showing up anymore. I think this is because the browser is now waiting for OpenCV to finish writing the file and uploading the whole think before trying to upload the next image. However, there's still an error every once in a while that causes everything to freeze unless the onerror event handler is added to the mix. With the onerror event handler in place, there's only a quick flash which is distracting but still an improvement.
I like the simplicity of this approach, but I'd like to improve upon it in two ways:
- More intelligent error handling that doesn't cause a flash by showing the previous image. Orion Lawlor suggested toggling between the two most recent images.
-
reporter Some addition reading online suggests that this approach will result in high memory usage as browser cache the images being sent. Would using socket.io fix this problem?
-
reporter In commit 1b31d8e, RoboBeagleBot.cpp is able to display images generated by OpenCV with a lag of just under a second. To prevent flickering, I had to embed the cv code within Wt so that I would know when the image was generated and could update it immediately afterward.
I'd like to be able to run RoboBeagleBot.cpp without a gui when it comes time to complete (for performance reasons), so I'd like to separate the OpenCV code from the Wt interface using threads. The question is how to go about calling a function within Wt from an OpenCV thread. boost::thread looks promising as does Wt's server::post and triggerUpdate(). The trick is passing a reference to the Wt app object to the OpenCV thread so that I can reference the functions.
http://antonym.org/2009/05/threading-with-boost---part-i-creating-threads.html
-
reporter - changed status to resolved
RoboBeagleBot.cpp now pushes the image to the client. No flickering and a relatively short delay (less than a second using the Genius 320 Widecam).
- Log in to comment
Looks like the creator of mjpg-streamer ran into the same problem and came up with a way of using two images to avoid flicker: https://code.google.com/p/mjpg-streamer/source/browse/trunk/mjpg-streamer-2.0/www/javascript_simple.html lines 18-38. Perhaps a good way to handle this is to have OpenCV generate a hand full of images and then use javascript/jquery to pick up the most recent complete pick.