Hi.
I am using ORB features instead of SIFT features.
I am facing an issue while performing clustering on the images.
Please find the code snippet.
``
Create feature extraction and keypoint detector objects
orb = cv2.ORB()
List where all the descriptors are stored
des_list = []
for image_path in image_paths:
im = cv2.imread(image_path)
is_cv3 = cv2.version.startswith("3.")
if(is_cv3):
detector = cv2.ORB_create()
else:
detector = cv2.ORB()
kpts = detector.detect(im)
kpts, des = detector.compute(im,kpts)
img_temp = np.zeros((1,1))
img_four = cv2.drawKeypoints(im,kpts,img_temp,color = (0,255,0), flags = 0)
des_list.append((image_path, des))
Stack all the descriptors vertically in a numpy array
descriptors = des_list[0][1]
for image_path, descriptor in des_list[1:]:
descriptors = np.vstack((descriptors, descriptor))
Perform k-means clustering
k = 100
voc, variance = kmeans(descriptors, k, 1)
Calculate the histogram of features
im_features = np.zeros((len(image_paths), k), "float32")
for i in xrange(len(image_paths)):
words, distance = vq(des_list[i][1],voc)
for w in words:
im_features[i][w] += 1
I am facing the following error:-
Traceback (most recent call last):
File "findFeatures.py", line 133, in
words, distance = vq(des_list[i][1],y_kmeans[:500,])
File "/usr/local/lib/python3.5/dist-packages/scipy/cluster/vq.py", line 211, in vq
return _vq.vq(c_obs, c_code_book)
File "_vq.pyx", line 211, in scipy.cluster._vq.vq
ValueError: observation and code should have same number of dimensions.
Please provide me with the solution to the problem.
Hi. I am using ORB features instead of SIFT features.
I am facing an issue while performing clustering on the images. Please find the code snippet.
``
Create feature extraction and keypoint detector objects
orb = cv2.ORB()
List where all the descriptors are stored
des_list = []
for image_path in image_paths: im = cv2.imread(image_path) is_cv3 = cv2.version.startswith("3.") if(is_cv3): detector = cv2.ORB_create() else: detector = cv2.ORB() kpts = detector.detect(im) kpts, des = detector.compute(im,kpts) img_temp = np.zeros((1,1)) img_four = cv2.drawKeypoints(im,kpts,img_temp,color = (0,255,0), flags = 0) des_list.append((image_path, des))
Stack all the descriptors vertically in a numpy array
descriptors = des_list[0][1] for image_path, descriptor in des_list[1:]: descriptors = np.vstack((descriptors, descriptor))
Perform k-means clustering
k = 100 voc, variance = kmeans(descriptors, k, 1)
Calculate the histogram of features
im_features = np.zeros((len(image_paths), k), "float32") for i in xrange(len(image_paths)): words, distance = vq(des_list[i][1],voc) for w in words: im_features[i][w] += 1
I am facing the following error:-
Traceback (most recent call last): File "findFeatures.py", line 133, in
words, distance = vq(des_list[i][1],y_kmeans[:500,])
File "/usr/local/lib/python3.5/dist-packages/scipy/cluster/vq.py", line 211, in vq
return _vq.vq(c_obs, c_code_book)
File "_vq.pyx", line 211, in scipy.cluster._vq.vq
ValueError: observation and code should have same number of dimensions.
Please provide me with the solution to the problem.