How to find object on video using OpenCV

15,164

Solution 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.

Solution 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.

Share:
15,164

Related videos on Youtube

Thar1988
Author by

Thar1988

Updated on September 15, 2022

Comments

  • Thar1988
    Thar1988 over 1 year

    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?

    • karlphillip
      karlphillip almost 12 years
      Is your algorithm too slow for real-time video processing?
  • Thar1988
    Thar1988 almost 12 years
    Sir Thank you very much for your reply. Yeah,Now i could understand that using two steps will take more time. so i thought that using one step is good for a real time project. Sir, according to the your answer of stackoverflow.com/questions/3907028/… i studied about video processing and but i could not understand that how to track object from the processed video frame. could you please explain that how to identify object of that processed video frame. and Sir i would glad if you provide some coding on c++ interface.
  • Thar1988
    Thar1988 almost 12 years
    Sir Thank you for your reply.Yeah. Now i can understand that there is no point to doing two steps(first storing frames and then track object for those frame). is SIFT algorithm is should do using matlab and java?
  • Thar1988
    Thar1988 almost 12 years
    sir,could you please explain that does that require separate two threads for writing both video frame processing part and object tracking part in one program. i would be glad if you give some example for that.
  • karlphillip
    karlphillip almost 12 years
    Let's keep one question per thread, you are starting to hijack your own thread. If you have other questions, feel free to ask them in separate threads. Stackoverflow is not aimed at 1x1 support. I summarized what needs to be done and provided a few references with code. There's very little left for you to do. There are other posts here that talk about implementing multithreading system for capturing and processing frames from the camera using OpenCV. keyword: circular buffer.
  • Jav_Rock
    Jav_Rock almost 12 years
    Yes, as long as you have SIFT implemented, it will work. I think matlab should be slower, but it is great to play with data and learn the process. Debuging OpenCV is a bit annoying.
  • Thar1988
    Thar1988 almost 12 years
    but the thing is the project is implementing using opencv and c++ . are there any good algorithms that can be using for opencv
  • Jav_Rock
    Jav_Rock almost 12 years
    OpenCV has got all the good algorithms. SIFT, FAST, SURF,RANSAC,... For detecting an object you need first "features" that describe it (which you can obtain with SIFT) and a matching algorithm (matchTemplate, e.j.). Google a bit, search posts here in stackoverflow and you will practicaly get the codes, but first try something by yourself. At the beggining is tricky, but you can ask for help here.
  • Thar1988
    Thar1988 almost 12 years
    in SURF that detect key points of the video. how i can change that to detect only an rectangular objects?
  • Thar1988
    Thar1988 almost 12 years
    i would be glad if you help me for following question about SURF link
  • Rui Marques
    Rui Marques almost 12 years
    That is a whole different question, to go from SURF to a rectangle of the object, there is a sample: docs.opencv.org/doc/tutorials/features2d/feature_homography/‌​…