我在这里使用了选择性搜索:http://koen.me/research/selectivesearch/ 这给出了可能的对象所在的区域。我想要做一些处理并只保留一些区域,然后删除重复的边界框以获得最终整齐的边界框集合。为了丢弃不需要/重复的边界框区域,我使用了opencv的grouprectangles
函数进行修剪。python opencv TypeError:输出数组的布局与cv不兼容:: Mat
有一次,我从上面的链接“选择性搜索算法”得到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
已经是一个列表。
简单地复制数组为我工作的一个类似的错误,以及。 –
可以证实这一点,似乎没有明显的区别,寿。 – Pwnna
此解决方案适用于由cv2.ellipse()函数产生的类似错误 – DanGoodrick