首页 > 解决方案 > 从所有轮廓中删除选定的轮廓?

问题描述

我有一个轮廓列表(contours_list),它是 np.shape(contours_list)= (5,519) 并且轮廓的大小(在轮廓列表中)是不同的,例如:索引 0 1 2 3 4 大小(8,1,2)( 16,1,2) (3,1,2) (199,1,2) (9,1,2)。

我图像中的物体是不同长度的细丝。例如,我想删除带有 :len(contours)>12 的轮廓(这是细丝中选定边界点的数量)这是我的代码:

df=pd.DataFrame(contours_list)
extract=np.array(())
selected_contours_list=[]
for i in range(5):
    for j in range(519):      
        if len(df.loc[i][j])>=12:            
            extract=np.array(df.loc[i][j])
            selected_contours_list.append(extract)           

out_put: np.shape(selected_contours_list) : (1345,) 满足条件!但我认为有错!我不明白会发生什么?我的 5 个清单在哪里?我想要 np.shape(selected_contours_list)(5, output)

index: 0 1 2 和 size: (27, 1, 2) (28, 1, 2) (15, 1, 2) 分别。

标签: pythonimage-processingopencv-contour

解决方案


推荐阅读