0

I am trying to track object from video stream using SIFT algorithm. I want to detect the object and track it by drawing a rectangle surrounding it. The problem is, the rectangle gets skewed and not accurately drawn most of the time. I am using the following code to draw the rectangle around the detected object (videoImage is the frame from video stream).

line(videoImage, sceneCorners[0], sceneCorners[1], Scalar(255, 0, 0), 2);
line(videoImage, sceneCorners[1], sceneCorners[2], Scalar(255, 0, 0), 2);
line(videoImage, sceneCorners[2], sceneCorners[3], Scalar(255, 0, 0), 2);
line(videoImage, sceneCorners[3], sceneCorners[0], Scalar(255, 0, 0), 2);

I also tried the following code (imgMatches is the image with only the good matches)

line(imgMatches, sceneCorners[0] + Point2f( object.cols, 0), sceneCorners[1] + Point2f( object.cols, 0), Scalar(0, 255, 0), 2);
line(imgMatches, sceneCorners[1] + Point2f( object.cols, 0), sceneCorners[2] + Point2f( object.cols, 0), Scalar(0, 255, 0), 2);
line(imgMatches, sceneCorners[2] + Point2f( object.cols, 0), sceneCorners[3] + Point2f( object.cols, 0), Scalar(0, 255, 0), 2);
line(imgMatches, sceneCorners[3] + Point2f( object.cols, 0), sceneCorners[0] + Point2f( object.cols, 0), Scalar(0, 255, 0), 2);

Both seems give the same result. So, my question is, how do draw a rectangle bounding my tracked object which is consistent to the tracked object? By the way, I am using OpenCV (C++) with Visual Studio 2010 on Windows 7.

Andre Hofmeister
  • 3,185
  • 11
  • 51
  • 74
Nasir
  • 31
  • 4
  • A quick note about writing blocks of code in stack overflow: do not use the tilde, but leave 4 spaces before every line of code. – ChronoTrigger Mar 18 '14 at 02:39

2 Answers2

0

The problem is not drawing the rectangle, but detecting the object correctly. It is very common that detections in single images are noisy if you get only some keypoints, even if you filter them with RANSAC and a fundamental matrix or a homography.

If you want a more accurate rectangle around the object, you must write a better detection algorithm. For example, you can try to look for more correspondences when you have a first hint of the position of the object in the image.

ChronoTrigger
  • 8,459
  • 1
  • 36
  • 57
  • I also tried SURF and the result seems same. I will try to find more correspondences for the first key point matched. Can you please suggest any better detection algorithm? – Nasir Mar 18 '14 at 04:28
  • What type of objects are you trying to detect? – ivan_a Mar 18 '14 at 13:50
  • @ivan_a : can be any types of objects. For example, tracking a car in a video. – Nasir Mar 18 '14 at 13:56
0

Maybe have a look at this question SIFT matches and recognition?. It's about the same question. The solution is a 4D hough space.

Community
  • 1
  • 1
L4CK4
  • 21
  • 3