Create a new window on top of camera feed

asked 2015-07-31 09:30:37 -0500

updated 2015-08-01 03:01:31 -0500

I have an application for OpenCV where I am looking to create a camera feed and then draw on top of the camera feed. My first thought is that I probably need two windows or views. One to output the camera feed only and the other would be a transparent window sitting on top of the camera feed window that I could draw to. For performance reasons I figure it does not make sense to update the cv::Mat in the window that is outputting the camera feed so I will do it on top of the camera feed in a new window as I will be doing a lot of drawing, computation, and updating. Am I thinking about this in the correct way? Is this something that can be done in OpenCV? If so, how would something like this be setup?

edit retag flag offensive close merge delete

Comments

"it does not make sense to update the cv::Mat that is being displayed in the camera feed." - hmm, that sounds like 'premature optimization' don't be afraid of drawing a few lines, it's dead cheap.

berak gravatar imageberak ( 2015-08-01 02:57:42 -0500 )edit

So do you think it would be a better idea to draw directly onto the cv::Mat that is being output from my camera? Do you think that this will slow down my FPS if I do all of this logic inside of my camera loop?

agnosticdev gravatar imageagnosticdev ( 2015-08-01 03:05:17 -0500 )edit

compared to what ? ;)

again, profile, and then worry.

berak gravatar imageberak ( 2015-08-01 03:12:27 -0500 )edit

So here is the reason that I am concerned. I am performing a SURF detection for keypoints on every cv::Mat that comes off the camera feed. When I detect that I have a good set of matches I need to draw to the cv::Mat. That is all fine except when I was performing SURF detection inside that camera loop I was getting around 3-4 FPS so to increase performance I move the entire SURF detection process to a background thread and now I am getting 12-13 FPS. This is why I am concerned. I feel that to not slow down the camera feed it might be a good idea to draw on top of the camera feed instead of directly to it.

agnosticdev gravatar imageagnosticdev ( 2015-08-01 03:24:42 -0500 )edit

yes, SURF keypoint detection is very expensive, drawing is cheap.

again, profile , don't just guess.

berak gravatar imageberak ( 2015-08-01 03:26:35 -0500 )edit

OK, will do. Thank you. I will look into drawing directly to the camera frame.

agnosticdev gravatar imageagnosticdev ( 2015-08-01 03:37:57 -0500 )edit

here's some code:

int64 t0 = cv::getTickCount();
// some operation
int64 t1 = cv::getTickCount();
double timeSpent = (t1-t0)/cv::getTickFrequency();
berak gravatar imageberak ( 2015-08-01 03:42:12 -0500 )edit

Thank you. I am using this in my camera feed already, but as I rework my background SURF computations I may want to use it there too.

agnosticdev gravatar imageagnosticdev ( 2015-08-01 03:54:58 -0500 )edit

The tracking code running on the background thread takes 0.234629 sec to run the computation so keeping the cv::Mat's updated in the camera thread lags a bit.

agnosticdev gravatar imageagnosticdev ( 2015-08-01 21:14:28 -0500 )edit