Hi all. I need help with classifying images by ORB functions. extracted ORB features (vectors). I have 3 etalon images. I have to classify images by ORB functions (compare other images with these etalons).
In the first, I tried the following solution. next solution:
#get etalons (files)
camera = cv2.imread('/content/drive/My Drive/ColabNotebooks/images/etalons/camera.jpg')
phone = cv2.imread('/content/drive/My Drive/ColabNotebooks/images/etalons/phone.jpg')
lamp = cv2.imread('/content/drive/My Drive/ColabNotebooks/images/etalons/lamp.jpg')
gray_camera = cv2.cvtColor(camera, cv2.COLOR_BGR2GRAY)
gray_phone = cv2.cvtColor(phone, cv2.COLOR_BGR2GRAY)
gray_lamp = cv2.cvtColor(lamp, cv2.COLOR_BGR2GRAY)
# find the keypoints with ORB and compute the descriptors with ORB
camera_orb_kp, camera_des = orb.detectAndCompute(gray_camera, None)
phone_orb_kp, phone_des = orb.detectAndCompute(gray_phone, None)
lamp_orb_kp, lamp_des = orb.detectAndCompute(gray_lamp, None)
# draw only keypoints location,not size and orientation
camera2 = cv2.drawKeypoints(gray_camera,camera_orb_kp,outImage=None, color=(0,255,0), flags=0)
phone2 = cv2.drawKeypoints(gray_phone,phone_orb_kp,outImage=None, color=(0,255,0), flags=0)
lamp2 = cv2.drawKeypoints(gray_lamp,lamp_orb_kp,outImage=None, color=(0,255,0), flags=0)
plt.title('Camera Etalon ORB Features'),plt.imshow(camera2),plt.show()
plt.title('Phone Etalon ORB Features'),plt.imshow(phone2),plt.show()
plt.title('Lamp Etalon ORB Features'),plt.imshow(lamp2),plt.show()
img_test = cv2.imread('/content/drive/My Drive/ColabNotebooks/images/image_0045.jpg')
gray_test = cv2.cvtColor(img_test, cv2.COLOR_BGR2GRAY)
# find the keypoints with ORB and compute the descriptors with ORB
kpt, dest = orb.detectAndCompute(gray_test, None)
# ORB
img2_test = cv2.drawKeypoints(gray_test,kpt,outImage=None, color=(0,255,0), flags=0)
plt.title('First test image ORB features'),plt.imshow(img2_test),plt.show()
# ORB matches
camera_matches = bf.match(camera_des,dest)
phone_matches = bf.match(phone_des,dest)
lamp_matches = bf.match(lamp_des,dest)
# Sort them in the order of their distance.
camera_matches = sorted(camera_matches, key = lambda x:x.distance)
phone_matches = sorted(phone_matches, key = lambda x:x.distance)
lamp_matches = sorted(lamp_matches, key = lambda x:x.distance)
# print('matches/kp:')
print('ORB matches: ')
print(len(camera_matches), len(phone_matches), len(lamp_matches))
But the classification was incorrect. incorrect (image with camera was classified as lamp). I not understand which way to compare ORB functions is correct.
I tried to remake this example for ORB, but this code was not working. correct. Please help me with this task. Describe me how I should compare control poins and descriptors.
Thanks in advance.