drawing a line between feature points without using "drawmatches" function

sy456 picture sy456 · Feb 23, 2014 · Viewed 7.2k times · Source

I got the feature points from two consecutive by using different detectors in features2d framework:

In the first frame, the feature points are plotted in red enter image description here

In the next frame, the feature points are plotted in blue enter image description here

I want to draw a line between these red and blue (matched) points inside the first frame (the image with red dots). drawmatches function in opencv doesn't help as it shows a window with two consecutive frames next to each other for matching. Is it possible in OpenCV?

Thanks in advance

Answer

rookiepig picture rookiepig · Feb 23, 2014

I guess that you want to visualize how each keypoint moves between two frames. According to my knowledge, there is no built-in function in OpenCV meeting your requirement.

However, as you have called the drawMatches() function, you already have the two keypoint sets (take C++ code as example) vector<KeyPoint>& keypoints1, keypoints2 and the matches vector<DMatch>& matches1to2. Then you can get the pixel coordinate of each keypoint from Point keypoints1.pt and draw lines between keypoints by calling the line() function.

You should be careful that since you want to draw keypoints2 in the first frame, the pixel coordinate may exceed the size of img1.

There is a quick way to get a sense of the keypoints' motion. Below is the result shown by imshowpair() in Matlab: enter image description here