Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 有什么快速算法可以找到图形的最大外轮廓吗?_Python_Image_Algorithm_Contour_Marching Cubes - Fatal编程技术网

Python 有什么快速算法可以找到图形的最大外轮廓吗?

Python 有什么快速算法可以找到图形的最大外轮廓吗?,python,image,algorithm,contour,marching-cubes,Python,Image,Algorithm,Contour,Marching Cubes,我有一个从scipy.measure.label获得的标记矩阵。现在,对于每个特征,我需要获得其外部轮廓。我试过cv2.findContours,但发现它与标签不符。我认为应该有一个简单的算法来实现这一点,但不幸的是,找不到。对不起,我将行和列合并使用(为什么在opencv中它们的顺序相反?) 代码如下: #!/usr/bin/env python # -*- coding: utf-8 -*- import cv2 import scipy import numpy as np from sk

我有一个从scipy.measure.label获得的标记矩阵。现在,对于每个特征,我需要获得其外部轮廓。我试过cv2.findContours,但发现它与标签不符。我认为应该有一个简单的算法来实现这一点,但不幸的是,找不到。

对不起,我将行和列合并使用(为什么在opencv中它们的顺序相反?) 代码如下:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import cv2
import scipy
import numpy as np
from skimage import filters, feature, io
from skimage.color import rgb2grey
def find_bounds(im):
    edges1 = filters.scharr(im)
    gt=filters.threshold_otsu(edges1)
    edges1 = edges1>gt
    return scipy.ndimage.measurements.label(edges1)
def object_filter(img, considered):
    def func(t): return 255 if t==considered else 0
    func=np.vectorize(func)
    return func(img).astype('uint8')
im=io.imread('gesture.jpg')
im=rgb2grey(im)
labels, num_of_labels=find_bounds(im)
contours,_ = cv2.findContours(object_filter(labels, 1),2,1)
cnt = contours[0]

hull = cv2.convexHull(cnt,returnPoints = False)
contour_matrix=np.zeros(im.shape, 'uint8')
for t in cnt:
    print t, labels[t[0][1]][t[0][0]]
    contour_matrix[t[0][1]][t[0][0]]=1
print '====================='
print contour_matrix

“contour it find not contour with labels”:你的意思是什么?我在寻找一个2xN数组,由N对x,y组成,这样(x1,y1)-(x2,y2)可以取一个值(-1,0),(0,-1),(1,-1),(-1,1),(1,1)和m[x,y]=l,其中m被标记为矩阵,l被认为是标签。例如,对于标记为1的要素,轮廓坐标(x,y)对应于标记为1的单元。
cv2。FindOntours
返回坐标向量。转换为delta向量并检索标签是很简单的。我尝试了这个方法,但它返回的不是标签。我在第一篇文章中写到了这一点。请仔细阅读每一次开始的文章。你是指“轮廓它发现不符合标签”?请仔细写。