Ask Your Question

Revision history [back]

Help with OpenCV image classification by ORB features

Hi all. I need help with classifying images by ORB functions. I have 3 etalon images. I have to classify images by ORB functions (compare images with etalons, not show matching). This should be the Jupyter Notebook Python 3 solution at Google Colab Laboratory. In the first, I tried the following solution. But the classification was incorrect. I cannot figure out which way to compare ORB functions is the right one. I tried to remake this example for ORB, but this code was not working. Please help me with this task. Describe me how I should compare control poins and descriptors.

Thanks in advance.

Help with OpenCV image classification by ORB features

Hi all. I need help with classifying images by ORB functions. I have 3 etalon images. I have to classify images by ORB functions (compare images with etalons, not show matching)etalons). This should be the Jupyter Notebook Python 3 solution at Google Colab Laboratory. . In the first, I tried the following solution. But the classification was incorrect. I cannot figure out not understand which way to compare ORB functions is the right one. correct. I tried to remake this example for ORB, but this code was not working. Please help me with this task. Describe me how I should compare control poins and descriptors.

descriptors. Thanks in advance.

Help with OpenCV image classification by ORB features

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()

control points ORB

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()

First sample image ORB control points

# 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))

Results

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.

Help with OpenCV image classification by ORB features

Hi all. I need help with classifying images by 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 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()

control points ORB

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()

First sample image ORB control points

# 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))

ResultsResults

But the classification was incorrect (image with camera was classified as lamp). I not understand which way to compare ORB functions is correct. Please help me with this task. Describe me how I should compare control poins and descriptors. Thanks in advance.