首页 > 编程知识 正文

measure中文,halcon轮廓提取

时间:2023-05-06 07:41:48 阅读:133972 作者:905

分别属于cv2和skimage连的库

首先来看看函数的源代码说明:

deffind_contours(Array,level,fully_connected='low ', positive_orientation='low ' ) 3360 ' ' find iso-valuedcontoursina2darrayforagivenlevelvalue.uses the ' marching squares ' methodtocomputeatheiso-valuer inar rrayvaluesarelinearlyinterpolatedtoprovidebetterprecisionfortheoutputcontours.parameter---- array 33602 doprameter n tours.level : floatvaluealongwhichtofindcontoursintheaahe y _ connected : str,{'low ', ' high ' } indicateswhetherarrayelementsbelowthegivenlevelvaluearetobeconsideredfully-connected (andhenceelementsabovethevabovethevabled ) or vice-versa.(seenotesbelowfordetails.) positive _ orientation : either ' low ' or ' high ' indicateswhetheoutputcontourswillproducepositively-orientedpolygogon ncontourswillwindcounter-clockwisearoundelementsbelowtheiso-value.alternatellue thismeansthatlow-valuedelementsarealwayarealwayoue fordetails.) returns----contours3360 2)-ndarrayseachcontourisanndarrayofshape ` (n,2 ) ``,consistingofn ` column (` coordinatesalongthecontour.notes---- themarchingsquaresalgorithmisaspecialcaseofthemarchingcubesalgorithm _.asimpleexexexexasingesalextethm 358 www.essi.fr/~ lingrand/marching cubes/algo.htmlthereisasingleambiguouscaseinthemarchingsquaresalgorithm 3360 whenaresthm - elementsquarehastwohigh-valuedandtwolow-valued elements, eachpairdiagonallyadjacent.(where high-and low-valuediswithrespecttothecontourvaluesought.) In this case, either the high-valuedelementscanbe ' connected together ' viaathinisthmusthatseparatesthelow-valued elements, or vice-versa.whenelementsareconnectedtogetheracrossadiagonal,they are considered ' fully connected ' (alsoknownas ' face vece )

high-valued or low-valued elements can be fully-connected, the other set will be considered as 'face-connected' or '4-connected'. By default, low-valued elements are considered fully-connected; this can be altered with the 'fully_connected' parameter. Output contours are not guaranteed to be closed: contours which intersect the array edge will be left open. All other contours will be closed. (The closed-ness of a contours can be tested by checking whether the beginning point is the same as the end point.) Contours are oriented. By default, array values lower than the contour value are to the left of the contour and values greater than the contour value are to the right. This means that contours will wind counter-clockwise (i.e. in 'positive orientation') around islands of low-valued pixels. This behavior can be altered with the 'positive_orientation' parameter. The order of the contours in the output list is determined by the position of the smallest ``x,y`` (in lexicographical order) coordinate in the contour. This is a side-effect of how the input array is traversed, but can be relied upon. .. warning:: Array coordinates/values are assumed to refer to the *center* of the array element. Take a simple example input: ``[0, 1]``. The interpolated position of 0.5 in this array is midway between the 0-element (at ``x=0``) and the 1-element (at ``x=1``), and thus would fall at ``x=0.5``. This means that to find reasonable contours, it is best to find contours midway between the expected "light" and "dark" values. In particular, given a binarized array, *do not* choose to find contours at the low or high value of the array. This will often yield degenerate contours, especially around structures that are a single array element wide. Instead choose a middle value, as above. References ---------- .. [1] Lorensen, William and Harvey E. Cline. Marching Cubes: A High Resolution 3D Surface Construction Algorithm. Computer Graphics (SIGGRAPH 87 Proceedings) 21(4) July 1987, p. 163-170). Examples -------- >>> a = np.zeros((3, 3)) >>> a[0, 0] = 1 >>> a array([[ 1., 0., 0.], [ 0., 0., 0.], [ 0., 0., 0.]]) >>> find_contours(a, 0.5) [array([[ 0. , 0.5], [ 0.5, 0. ]])] """

参数介绍:

这个讲的好

array:这就是要输入的照片,,直接cv2.imread(name,0)读进来就能用。0的意思是读成灰度图

level:直译就是水平,当我用0.5的时候能探测出几百个,当我用1的时候有几十个,当我用10的时候有4个,100的时候只有两个。
一个颜色就是一个结果,越来越少对不对,

fully_connected:只能选low和high,这个参数解释的有点复杂,这个图是上面那个参数为1的时候,有好多的,当为high的时候检查出来的多一些,当为low的时候,斜着的挨着进的那些更容易合并到一起,建议用low,low就是默认的。可以不管这一项。

low:
high:

positive_orientation 这个应该没啥用,我也不知道。。求教

def findContours(image, mode, method):

这个cv2中的这个对函数的解释,就是没在这解释,

image这个参数上面的第一个参数一样,单通道图像矩阵,可以是灰度图,但更常用的是二值图像,一般是经过Canny、拉普拉斯等边缘检测算子处理过的二值图像

mode:定义轮廓的检索模式:
CV_RETR_EXTERNAL:只检测最外围轮廓,包含在外围轮廓内的内围轮廓被忽。
CV_RETR_LIST :检测所有的轮廓,包括内围、外围轮廓,但是检测到的轮廓不建立等级关系,彼此之间独立,没有等级关系,这就意味着这个检索模式下不存在父轮廓或内嵌轮廓, 所以hierarchy向量内所有元素的第3、第4个分量都会被置为-1。
CV_RETR_CCOMP :检测所有的轮廓,但所有轮廓只建立两个等级关系,外围为顶层,若外围 内的内围轮廓还包含了其他的轮廓信息,则内围内的所有轮廓均归属于顶层 。
CV_RETR_TREE: 检测所有轮廓,所有轮廓建立一个等级树结构。外层轮廓包含内层轮廓,内
层轮廓还可以继续包含内嵌轮廓。

RETR_LIST 从解释的角度来看,这中应是最简单的。它只是提取所有的轮廓,而不去创建任何父子关系。
RETR_EXTERNAL 如果你选择这种模式的话,只会返回最外边的的轮廓,所有的子轮廓都会被忽略掉。
RETR_CCOMP 在这种模式下会返回所有的轮廓并将轮廓分为两级组织结构。
RETR_TREE 这种模式下会返回所有轮廓,并且创建一个完整的组织结构列表。它甚至会告诉你谁是爷爷,爸爸,儿子,孙子等

method:
CV_CHAIN_APPROX_NONE:保存物体边界上所有连续的轮廓点到contours向量内
CV_CHAIN_APPROX_SIMPLE :仅保存轮廓的拐点信息,把所有轮廓拐点处的点保存入contours 向量内,拐点与拐点之间直线段上的信息点不予保留
CV_CHAIN_APPROX_TC89_L1,CV_CHAIN_APPROX_TC89_KCOS:使用teh-Chinl chain 近 似算法

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。