我正在使用scikit-image进行计算机视觉。 我将使用查找轮廓来获得灰度图像输入的轮廓,但返回的列表将图像的轮廓全部放在第一个位置。 我想要获得的结果是图像的唯一轮廓,因此,我尝试使用for循环将轮廓分开,但是这需要很长时间,因此效果不佳。谁能帮我? 该代码报告如下:
import numpy as np
from skimage.io import imread
from skimage.measure import moments, moments_hu, find_contours, approximate_polygon
from skimage.feature import canny
from matplotlib import pyplot as plt
#%% Opening image section
reference_image = imread('referenceImage.jpg', as_gray= True)
reference_contours = find_contours(reference_image, 0.8, fully_connected='high')
first = True
added = False
reference_contours_list = []
for contours in reference_contours:
for con in contours:
if first:
first = False
reference_contours_list.append(np.array(np.array([con])))
else:
for index, past_con in enumerate(reference_contours_list):
for past_c in past_con:
if con[0] in range(int(round(past_c[0])) - 1, int(round(past_c[0])) + 2):
reference_contours_list[index] = np.append(reference_contours_list[index], np.array(np.array([con])), axis=0)