最佳答案
如果镜像始终保持良好连接,则可以根据组件的大小选择组件。我在Python中的代码(可能是一种更简单的方法,但这就是我的方法):
#get all connected components in the image with their stats (including their size, in pixel)
nb_edges, output, stats, _ = cv2.connectedComponentsWithStats(img, connectivity=8)
#output is an image where every component has a different value
size=stats[1:,-1] #extracting the size from the statistics
#selecting bigger components
for e in range(0,nb_edges-1):
#replace this line depending on your application, here I chose to keep
#all components above the mean size of components in the image
if size[e]>=np.mean(size):
th_up = e + 2
th_do = th_up
#masking to keep only the components which meet the condition
mask = cv2.inRange(output, th_do, th_up)
result = cv2.bitwise_xor(original_img, mask)
关于image - OpenCV-删除图像中的独立短线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41675940/