问题陈述:在 yolo 中成功获取对象周围的边界框后,我想将背景与对象本身分开。
我的解决方案:我有一个 RGB-D 相机,它返回深度图以及图像(图像提供给 yolo obv),使用深度图,我做了一个简单的函数来获取深度(四舍五入)和多少像素具有相同的值
def GetAllDepthsSortedMeters(depth_image_ocv):
_depth = depth_image_ocv[np.isfinite(depth_image_ocv)]
_depth= -np.sort(-depth_image_ocv)[:int(len(_depth)/2)]
_depth= np.round(_depth,1)
unique, counts = np.unique(_depth, return_counts=True)
return dict(zip(counts, unique))
并绘制它们,我注意到有一些主峰,其余的位于它们周围,经过一些过滤后,我每次都能成功获得这些峰。
#get the values of depths and their number of occurences
counts,values = GetKeysAndValues(_depths)
#find the peaks of depths in those values
peaks = find_peaks_cwt(counts, widths=np.ones(counts.shape)*2)-1
使用这些峰值,我能够通过检查该值接近哪些峰值来从背景中分割所需的对象,并为每个峰值(及其周围的像素)制作一个掩模。
def GetAcceptedMasks(h,w,depth_map,depths_of_accepted_peaks,accepted_masks):
prev=None
prev_index=None
for pos in product(range(h), range(w)):
pixel = depth_map.item(pos)
if ( (prev is not None) and (round(prev,1) == round(pixel,1)) ):
accepted_masks[prev_index][pos[0],pos[1]]= 255
else:
_temp_array = abs(depths_of_accepted_peaks-pixel)
_min = np.amin(_temp_array)
_ind = np.where( _temp_array == _min )[0][0]
accepted_masks[_ind][pos[0],pos[1]]= 255
prev_index = _ind
prev = pixel
return accepted_masks
将图像传递给 YOLOv3 并应用过滤和深度分割后,需要 0.8 秒,这远非最佳,这主要是上述函数的结果,任何帮助都会很棒。谢谢
宝慕林4294392
陪伴而非守候
随时随地看视频慕课网APP
相关分类