Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How should I use OpenCV 3.1 ORB in Python3?

I'm new to CV,I have a lot of images and I want to compare one images with the others in my images dataset.So I decide to index all the images,after I do some search and know ORG,SIFT,SURF is I was looking for.But I don't know how to use the keypoint and descriptor,below is my code:

import cv2

nfeatures = 1
cv2.ocl.setUseOpenCL(False)
img = cv2.imread('images/forest-copyright.jpg', 0)
img2 = cv2.imread('images/forest-high.jpg', 0)

def kpdes(img):
    orb = cv2.ORB_create(nfeatures=nfeatures)
    kp = orb.detect(img, None)
    kp,des = orb.compute(img, kp)
    print(kp,des)

kpdes(img)
kpdes(img2)

Some parts of output:

[KeyPoint 0000000002A2EF00] [[252 48 188 124 41 124 81 184 161 63 167 25 87 63 74 91 192 213 237 0 60 79 243 0 219 235 112 93 224 225 78 67]]

How should I use the descriptor like “[[252 48 188 124 41 124 81 184 161 63 167 25 87 63 74 91 192 213 237 0 60 79 243 0 219 235 112 93 224 225 78 67]]”,what dose it mean? How can I store them in Elasticsearch and query them? I found the descriptor would be changed if I increase nfeatures. Yes,there are so many questions for me,waiting for helper!

How should I use OpenCV 3.1 ORB in Python3?

I'm new to CV,I have a lot of images and I want to compare one images image with the others in my images dataset.So I decide to index all the images,after I do some search and know ORG,SIFT,SURF is I was looking for.But I don't know how to use the keypoint and descriptor,below is my code:

import cv2

nfeatures = 1
cv2.ocl.setUseOpenCL(False)
img = cv2.imread('images/forest-copyright.jpg', 0)
img2 = cv2.imread('images/forest-high.jpg', 0)

def kpdes(img):
    orb = cv2.ORB_create(nfeatures=nfeatures)
    kp = orb.detect(img, None)
    kp,des = orb.compute(img, kp)
    print(kp,des)

kpdes(img)
kpdes(img2)

Some parts of output:

[KeyPoint 0000000002A2EF00] [[252 48 188 124 41 124 81 184 161 63 167 25 87 63 74 91 192 213 237 0 60 79 243 0 219 235 112 93 224 225 78 67]]

How should I use the descriptor like “[[252 48 188 124 41 124 81 184 161 63 167 25 87 63 74 91 192 213 237 0 60 79 243 0 219 235 112 93 224 225 78 67]]”,what dose it mean? How can I store them in Elasticsearch and query them? I found the descriptor would be changed if I increase nfeatures. Yes,there are so many questions for me,waiting for helper!

How should I use OpenCV 3.1 ORB in Python3?

I'm new to CV,I have a lot of images and I want to compare one image with the others in my images dataset.So I decide to index all the images,after I do some search and know ORG,SIFT,SURF is I was looking for.But I don't know how to use the keypoint and descriptor,below is my code:

import cv2

nfeatures = 1
cv2.ocl.setUseOpenCL(False)
img = cv2.imread('images/forest-copyright.jpg', 0)
img2 = cv2.imread('images/forest-high.jpg', 0)

def kpdes(img):
    orb = cv2.ORB_create(nfeatures=nfeatures)
    kp = orb.detect(img, None)
    kp,des = orb.compute(img, kp)
    print(kp,des)

kpdes(img)
kpdes(img2)

Some parts of output:

[KeyPoint 0000000002A2EF00] [[252 48 188 124 41 124 81 184 161 63 167 25 87 63 74 91 192 213 237 0 60 79 243 0 219 235 112 93 224 225 78 67]]

How should I use the descriptor like “[[252 48 188 124 41 124 81 184 161 63 167 25 87 63 74 91 192 213 237 0 60 79 243 0 219 235 112 93 224 225 78 67]]”,what dose it mean? How can I store them in Elasticsearch and query them? I found the descriptor would be changed if I increase nfeatures. Yes,there are so many questions for me,waiting for helper!helper! After I read some docs,I convert the descriptor to 256 bits binary string like this "00101000010111000111110101111...",and calculate HAMMING-DISTANCE,below is my current code:

import numpy as np
import cv2


nfeatures = 1000
threshold = 150
cv2.ocl.setUseOpenCL(False)
img = cv2.imread('images/forest-copyright.jpg', 0)
img2 = cv2.imread('images/forest-high.jpg', 0)


def kpdes(img):
    orb = cv2.ORB_create(nfeatures=nfeatures)
    kp = orb.detect(img, None)
    kp, des = orb.compute(img, kp)
    des_bin_list = []
    for row in des:
        char_list = []
        for char in row:
            char_list.append(np.binary_repr(char, 8))
        des_bin_list.append(''.join(char_list))
    return des_bin_list


def get_ham_dis(str1, str2):
    distance = 0
    for char1, char2 in zip(str1, str2):
        if char1 != char2:
            distance += 1
    return distance


def dis(des1, des2):
    bad_points = 0
    index = 0
    for des_bin1, des_bin2 in zip(des1, des2):
        index += 1
        ham_dis = 0
        ham_dis = get_ham_dis(des_bin1, des_bin2)
        if ham_dis > threshold:
            bad_points += 1
    print(bad_points)
des_1 = kpdes(img)
des_2 = kpdes(img2)
dis(des_1, des_2)