How to find object on video using OpenCV

2019-02-12 17:26发布

问题:

To track object on video frame, first of all I extract image frames from video and save those images to a folder. Then I am supposed to process those images to find an object. Actually I do not know if this is a practical thing, because all the algorithm did this for one step. Is this correct?

回答1:

Well, your approach will consume a lot of space on your disk depending on the size of the video and the size of the frames, plus you will spend a considerable amount of time reading frames from the disk.

Have you tried to perform real-time video processing instead? If your algorithm is not too slow, there are some posts that show the things that you need to do:

  • This post demonstrates how to use the C interface of OpenCV to execute a function to convert frames captured by the webcam (on-the-fly) to grayscale and displays them on the screen;
  • This post shows a simple way to detect a square in an image using the C++ interface;
  • This post is a slight variation of the one above, and shows how to detect a paper sheet;
  • This thread shows several different ways to perform advanced square detection.

I trust you are capable of converting code from the C interface to the C++ interface.



回答2:

There is no point in storing frames of a video if you're using OpenCV, as it has really handy methods for capturing frames from a camera/stored video real-time.

In this post you have an example code for capturing frames from a video.

Then, if you want to detect objects on those frames, you need to process each frame using a detection algorithm. OpenCV brings some sample code related to the topic. You can try to use SIFT algorithm, to detect a picture, for example.