【发布时间】:2014-07-12 21:29:20
【问题描述】:
我在这里使用选择性搜索:http://koen.me/research/selectivesearch/
这给出了对象可能存在的可能感兴趣区域。我想做一些处理并只保留一些区域,然后删除重复的边界框以获得最终整齐的边界框集合。为了丢弃不需要/重复的边界框区域,我使用 opencv 的grouprectangles 函数进行修剪。
一旦我从上面链接中的“选择性搜索算法”中从 Matlab 中获得感兴趣的区域,我将结果保存在 .mat 文件中,然后在 python 程序中检索它们,如下所示:
import scipy.io as sio
inboxes = sio.loadmat('C:\\PATH_TO_MATFILE.mat')
candidates = np.array(inboxes['boxes'])
# candidates is 4 x N array with each row describing a bounding box like this:
# [rowBegin colBegin rowEnd colEnd]
# Now I will process the candidates and retain only those regions that are interesting
found = [] # This is the list in which I will retain what's interesting
for win in candidates:
# doing some processing here, and if some condition is met, then retain it:
found.append(win)
# Now I want to store only the interesting regions, stored in 'found',
# and prune unnecessary bounding boxes
boxes = cv2.groupRectangles(found, 1, 2) # But I get an error here
错误是:
boxes = cv2.groupRectangles(found, 1, 2)
TypeError: Layout of the output array rectList is incompatible with cv::Mat (step[ndims-1] != elemsize or step[1] != elemsize*nchannels)
怎么了? 我在另一段没有错误的代码中做了非常相似的事情。这是没有错误的代码:
inboxes = sio.loadmat('C:\\PATH_TO_MY_FILE\\boxes.mat')
boxes = np.array(inboxes['boxes'])
pruned_boxes = cv2.groupRectangles(boxes.tolist(), 100, 300)
我能看到的唯一区别是boxes 是一个 numpy 数组,然后我将其转换为一个列表。但在我有问题的代码中,found 已经是一个列表。
【问题讨论】:
标签: python arrays matlab opencv numpy