Ask Your Question

Amit Raj's profile - activity

2016-01-05 03:03:38 -0500 commented question Error using Flann matcher for BOWImgDescriptorExtractor in opencv-python

@berak thanks for your help :)

2016-01-05 02:54:09 -0500 commented question Error using Flann matcher for BOWImgDescriptorExtractor in opencv-python

@berak is there something else that i can do to get my bag of words descriptor..is the alternative brute force matcher as good as the flann

2016-01-05 02:28:25 -0500 commented question Error using Flann matcher for BOWImgDescriptorExtractor in opencv-python

@berak I have built opencv by cloning from the git repository and am also using py2.7. Could you tell me how you set up your ocv.

2016-01-05 01:55:33 -0500 asked a question Error using Flann matcher for BOWImgDescriptorExtractor in opencv-python

I am using opencv3 and python to implement the bag of words model for images. Here is my code.

import numpy as np
import cv2
import glob

img_cls = '/home/user/class_path'
imgs = glob.glob(img_cls + '*jpg')

sift = cv2.xfeatures2d.SIFT_create()

clusterCount = 200
termcrit = cv2.TermCriteria_EPS + cv2.TermCriteria_MAX_ITER, 10, 0.001
flags = cv2.KMEANS_RANDOM_CENTERS
attempts = 10

bowTrainer = cv2.BOWKMeansTrainer(clusterCount, termcrit, attempts, flags)

for i in imgs:
    img = cv2.imread(i, 0)
    kp  = sift.detect(img)
    kp, des = sift.compute(img, kp)
    bowTrainer.add(des)

voc = bowTrainer.cluster()

FLANN_INDEX_KDTREE = 0
index_params = dict(algorithm = FLANN_INDEX_KDTREE, trees = 5)
search_params = dict(checks = 50)
matcher = cv2.FlannBasedMatcher(index_params, search_params)

bowDE = cv2.BOWImgDescriptorExtractor(sift, matcher)
bowDE.setVocabulary(voc)

img = cv2.imread('/home/user/test_img.jpg', 0)
kp = sift.detect(img)
bdes = bowDE.compute(img, kp)

After running the program, I get the following error. Could anyone point out what I might be doing wrong.

OpenCV Error: Assertion failed (The data should normally be NULL!) in allocate, file /home/user/opencv/modules/python/src2/cv2.cpp, line 163
Traceback (most recent call last):
   File "ImgBow.py", line 31, in <module>
     bowDE.setVocabulary(voc)
cv2.error: /home/user/opencv/modules/python/src2/cv2.cpp:163: error: (-215) The data should normally be NULL! in function allocate