Ask Your Question
0

Python. Compute keypoints and descriptor with multiple images

asked 2016-04-05 22:03:17 -0600

sotoglzz gravatar image

I'm trying to compute keypoints and descriptors for a given set of images with cv2.xfeatures2d.SIFT. I want to create an array with all keypoints from every images and another array for descriptors too:

kp = numpy.empty([]) 
dsc = numpy.empty([])
        for imagesFiles in range(0, len(imagesCoast)):
        sift = cv2.xfeatures2d.SIFT_create()
        kp[imagesFiles], dsc[imagesFiles] = sift.detectAndCompute(imagesCoast[imagesFiles], None)

When I run it, output says:

keypts[imagesFiles], descriptor[imagesFiles] = `sift.detectAndCompute(imagesCoast[imagesFiles], None)`IndexError: 0-d arrays can't be indexed

What I'm doing wrong? If I delete [imagesFiles] from kp and dsc it computes everything for each imagesFiles, but them only keeps keypoits and descriptor for last one? I would like to know also, what does mean IndexError: 0-d arrays

Thanks in advance José Soto

edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted
0

answered 2016-04-06 02:10:04 -0600

berak gravatar image

this is more a python / numpy problem, you simply cannot index an empty array, same as:

A = []
A[3] = 17 # error

rather, start with empty lists, and append :

kp = [] 
dsc = []
for imagesFiles in range(0, len(imagesCoast)):
     sift = cv2.xfeatures2d.SIFT_create()
     k,d = sift.detectAndCompute(imagesCoast[imagesFiles], None)
     kp.append(k)
     dsc.append(d)
edit flag offensive delete link more

Comments

Hi Darek, this solved my problem, Thanks for your answer.

sotoglzz gravatar imagesotoglzz ( 2016-04-06 10:01:08 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2016-04-05 21:58:23 -0600

Seen: 1,646 times

Last updated: Apr 06 '16