Mayank Gajpal
Mayank Gajpal

Reputation: 62

How to get key points or pixel coordinates of an image from descriptor produced by SIFT algorithm

I have used SIFT algorithm to produce descriptor. After doing some processing to descriptor I got some selected descriptor. Now I want to draw lines between those descriptors, for that I want key points or pixel coordinates back from those descriptors.

I am trying to implement copy move forgery detection using opencv. Using key point concept, I got matched pairs of descriptor. Just want to draw line between those matched descriptor.

Code for producing descriptor:

sift = cv2.xfeatures2d.SIFT_create()
kp2, desc2 ift.detectAndCompute(gtemp,None)

The final descriptor I got, between which I want to draw lines:

[ 1. 64. 131. 1. 2. 9. 1. 0. 4. 80. 131. 0. 0. 3. 14. 12. 1. 52. 131. 0. 0. 0. 7. 9. 2. 25. 131. 0. 0. 0. 0. 0. 19. 12. 20. 3. 48. 54. 1. 8. 92. 28. 38. 0. 0. 2. 58. 108. 8. 18. 63. 0. 0. 43. 131. 28. 15. 18. 65. 0. 0. 31. 115. 33. 33. 2. 3. 47. 61. 8. 0. 7. 131. 24. 0. 0. 1. 0. 12. 47. 77. 4. 0. 0. 0. 27. 91. 22. 1. 0. 0. 0. 0. 28. 113. 19. 10. 0. 2. 9. 1. 2. 79. 55. 131. 1. 0. 0. 0. 0. 17. 131. 47. 0. 0. 0. 0. 0. 1. 25. 0. 0. 0. 0. 0. 0. 3. 1.] [ 23. 22. 31. 4. 0. 1. 8. 8. 26. 41. 40. 25. 4. 2. 13. 19. 11. 42. 46. 48. 8. 17. 15. 7. 4. 25. 28. 42. 38. 74. 34. 2. 68. 21. 24. 25. 2. 10. 11. 14. 14. 17. 119. 50. 12. 15. 11. 12. 87. 35. 36. 21. 14. 10. 7. 39. 8. 5. 14. 72. 119. 25. 3. 6. 5. 11. 13. 6. 1. 61. 113. 21. 8. 4. 7. 8. 9. 93. 119. 44. 69. 16. 13. 13. 15. 28. 45. 59. 5. 3. 7. 119. 119. 7. 0. 0. 0. 119. 119. 0. 0. 10. 28. 3. 0. 100. 119. 0. 0. 29. 54. 6. 0. 20. 55. 36. 52. 62. 24. 3. 2. 0. 4. 119. 119. 8. 1. 1.]

I think if I could get pixel coordinates back from this descriptors then it will be easier to draw lines between them. Using python 3.6 with OpenCV.

Upvotes: 1

Views: 2171

Answers (1)

s1rsimon
s1rsimon

Reputation: 61

I understand that you want to draw lines between the two images that you are matching.
For this purpose OpenCV has cv.drawMatches. The documentation for this method is here.

Use it like this image3 = cv2.drawMatches(image1, kp1, image2, kp2, matches, None, flags=2).

Also if you need pixel coordinates for your matched keypoints you have to read the pt attribute for cv2.KeyPoint.

For example if you want the pixel coordinates of all you matched features in image 2:

for kp in kp2:
    for match in matches:
        print(kp2[match.trainIdx].pt)

In this case match.trainIdx is the id for a match in reference of image2 and the pt attribute refers to the pixel coordinate of that feature point. The same goes for image1 but you have to read kp1[match.queryIdx].pt.

Upvotes: 1

Related Questions