Halcon 使用直线划分轮廓线

模仿clip_contours_xld算子,用任意直线(矩形)分割一个轮廓点集合

假设已经有一个轮廓,这里手绘一个

gen_region_runs (TMP_Region, [59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,143,144,144,145,145,146,146,147,147,148,148,149,149,150,150,151,151,152,152,153,153,154,154,155,155,156,156,157,157,158,158,159,159,160,160,161,161,162,162,163,163,164,164,165,165,166,166,167,167,168,168,169,169,170,170,171,171,172,172,173,173,174,174,175,175,176,176,177,177,178,178,179,179,180,180,181,181,182,182,183,183,184,184,185,185,186,186,187,187,188,188,189,189,190,190,191,191,192,192,193,193,194,194,195,195,196,196,197,197,198,198,199,199,200,200,201,201,202,202,203,203,204,204,205,205,206,206,207,207,208,208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,255,256,256,257,257,258,258,259,259,260,260,261,261,262,262,263,263,264,264,265,265,266,266,267,267,268,268,269,269,270,270,271,271,272,272,273,273,274,274,275,275,276,276,277,277,278,278,279,279,280,280,281,281,282,282,283,283,284,284,285,285,286,286,287,287,288,288,289,289,290,290,291,291,292,292,293,293,294,294,295,295,296,296,297,297,298,298,299,299,300,300,301,301,302,302,303,303,304,304,305,305,306,306,307,307,308,308,309,309,310,310,311,311,312,312,313,313,314,314,315,315,316,316,317,317,318,318,319,319,320,320,321,321,322,322,323,323,324,324,325,325,326,326,327,327,328,328,329,329,330,330,331,331,332,332,333,333,334,334,335,335,336,336,337,337,338,338,339,339,340,340,341,341,342,343,344,345,346,347,348,349,350,351,352,353,354,355,356,357,358,359,360,361,362,363,364,365,366,367,368,369,370,371,372,373,374,375,376,377,378,379,380,381,382,383,384,385,386,387,388,389,390,391,392,393,394,395,396,397,398,399], [-120,-120,-121,-121,-121,-121,-121,-121,-121,-121,-121,-122,-122,-122,-123,-123,-124,-124,-124,-124,-125,-125,-126,-127,-127,-128,-128,-128,-128,-129,-129,-129,-130,-130,-130,-131,-131,-131,-132,-132,-132,-132,-133,-133,-133,-134,-134,-134,-135,-135,-136,-136,-137,-137,-138,-138,-138,-139,-139,-140,-140,-141,-141,-142,-142,-143,-143,-144,-144,-145,-145,-146,-146,-147,-147,-147,-148,-148,-148,-149,-149,-150,-150,-150,-151,-32,-151,-33,-151,-33,-152,-34,-152,-34,-153,-34,-153,-35,-154,-35,-154,-36,-155,-37,-155,-37,-156,-38,-156,-38,-157,-39,-157,-39,-157,-40,-157,-40,-158,-41,-158,-42,-158,-42,-159,-43,-159,-43,-159,-44,-160,-45,-160,-45,-160,-46,-161,-47,-161,-47,-162,-48,-162,-49,-162,-49,-163,-50,-163,-50,-163,-51,-164,-52,-164,-52,-164,-53,-165,-54,-165,-54,-166,-55,-166,-55,-166,-56,-166,-57,-167,-57,-167,-58,-167,-59,-167,-59,-168,-60,-168,-60,-168,-61,-169,-61,-169,-62,-169,-62,-169,-63,-170,-64,-170,-64,-170,-65,-170,-65,-171,-66,-171,-66,-171,-67,-171,-67,-171,-68,-171,-68,-171,-69,-171,-70,-70,-71,-71,-72,-73,-73,-74,-74,-75,-75,-76,-76,-77,-77,-77,-78,-78,-79,-79,-79,-79,-80,-80,-80,-80,-81,-81,-81,-81,-82,-82,-82,-82,-82,-83,-83,-83,-83,-83,-84,-84,-84,-84,-85,-85,-85,-85,110,-85,111,-85,111,-85,111,-86,111,-86,111,-86,111,-86,111,-86,111,-86,111,-86,111,-86,111,-86,111,-86,111,-86,111,-87,111,-87,111,-87,111,-87,111,-87,111,-87,111,-87,111,-87,111,-87,111,-87,111,-87,112,-88,112,-88,112,-88,112,-88,112,-88,112,-88,113,-88,113,-88,113,-88,113,-88,114,-88,115,-88,115,-88,116,-88,117,-88,117,-88,117,-88,117,-88,117,-88,117,-88,117,-89,118,-89,118,-89,118,-89,118,-89,118,-89,118,-89,118,-89,118,-89,119,-89,119,-89,119,-89,119,-89,120,-89,120,-89,120,-89,120,-89,121,-89,121,-89,121,-89,121,-89,121,-89,121,-89,121,-89,122,-89,122,-89,122,-89,122,-89,122,-89,122,-89,122,-89,122,-89,122,-89,123,-89,123,-89,123,-89,123,-89,123,-88,123,-88,123,-87,123,-87,123,123,124,124,124,124,124,124,124,124,124,124,124,124,124,124,124,124,124,124,124,124,124,125,125,125,125,125,125,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,126,127,127,128,128,128,129,129,130,130,130,130,131,131], [-106,-76,-46,-16,14,44,74,104,134,164,194,224,253,283,313,343,373,403,433,463,493,523,553,583,613,630,629,627,626,624,622,621,619,618,616,614,613,611,610,608,607,605,603,602,600,599,597,595,594,592,591,589,588,586,584,583,581,580,578,576,575,573,572,570,569,567,565,564,562,561,559,557,556,554,553,551,550,548,546,545,543,542,540,538,-37,537,-40,535,-42,534,-45,532,-47,530,-49,529,-53,527,-57,526,-61,524,-64,523,-66,521,-68,519,-70,518,-72,516,-74,515,-77,513,-80,511,-82,510,-85,508,-88,507,-90,505,-92,504,-95,502,-97,500,-99,499,-101,497,-103,496,-104,494,-106,492,-108,491,-110,489,-112,488,-114,486,-116,485,-119,483,-121,481,-123,480,-126,478,-128,477,-131,475,-134,473,-136,472,-138,470,-139,469,-141,467,-143,466,-146,464,-148,462,-149,461,-151,459,-152,458,-154,456,-155,454,-157,453,-158,451,-159,450,-161,448,-162,447,-163,445,-164,443,-165,442,-166,440,-167,439,-168,437,-169,435,-170,434,432,431,429,428,426,424,423,421,420,418,416,415,413,412,410,409,407,405,404,402,401,399,397,396,394,393,391,390,388,386,385,383,382,380,378,377,375,374,372,370,369,367,366,364,363,361,105,359,97,358,90,356,85,355,80,353,75,351,69,350,65,348,61,347,56,345,51,344,47,342,44,340,42,339,39,337,36,336,34,334,32,332,30,331,28,329,26,328,24,326,22,325,20,323,18,321,15,320,13,318,11,317,9,315,7,313,5,312,4,310,2,309,1,307,0,306,-2,304,-3,302,-5,301,-7,299,-9,298,-11,296,-13,294,-15,293,-17,291,-19,290,-21,288,-23,287,-24,285,-26,283,-27,282,-28,280,-30,279,-31,277,-33,275,-34,274,-35,272,-37,271,-38,269,-39,268,-41,266,-42,264,-43,263,-45,261,-46,260,-48,258,-50,256,-52,255,-54,253,-56,252,-58,250,-60,249,-61,247,-63,245,-64,244,-65,242,-67,241,-69,239,-70,237,-72,236,-74,234,-76,233,-78,231,-80,230,-82,228,-84,226,-86,225,-87,223,222,220,218,217,215,214,212,210,209,207,206,204,203,201,199,198,196,195,193,191,190,188,187,185,184,182,180,179,177,176,174,172,171,169,168,166,165,163,161,160,158,157,155,153,152,150,149,147,146,144,142,141,139,138,136,134,133,131])
gen_contour_region_xld (TMP_Region, Contour, 'border')

在这里插入图片描述
再画一条直线

gen_region_line (ROI_0, 22.67907, 96.41089, 416.2082, 403.2624)

在这里插入图片描述
然后用划分函数处理,这里相当于用一个带角度的矩形框,将轮廓线划分出来

get_contour_xld (Contour, Rows, Cols)
Bias := 20 //直线的宽度
separate_points_by_line (Rows, Cols, Row1, Col1, Row2, Col2, Bias, RowsAbove, ColsAbove, RowsBelow, ColsBelow)
gen_cross_contour_xld (CrossAbove, RowsAbove, ColsAbove, 15, 0.785398)
gen_cross_contour_xld (CrossBelow, RowsBelow, ColsBelow, 15, 0.785398)```

![在这里插入图片描述](https://img-blog.csdnimg.cn/direct/71692a78cdf648f8bb44b128ca29554a.png)
函数资源链接在这里:
https://download.csdn.net/download/Yoto_Jo/89225786
Halcon是一个商业机器视觉软件库,提供了一系列用于图像处理、分析、视觉检测和图像识别的工具。在Halcon中,轮廓线对象通常是指通过边缘检测算法得到的物体边缘的表示。轮廓线对象在图像分析中非常重要,因为它们可以帮助识别和测量物体的形状、大小、方向等属性。 轮廓线对象通常有以下特点和处理方法: 1. 提取:使用Halcon提供的边缘检测算子(如`edges_sub_pix`、`sobel_amp`等)来识别图像中物体的边缘。 2. 连接:将检测到的边缘点按照一定的规则连接起来形成轮廓线对象,这些规则可能涉及边缘点之间的距离、角度等。 3. 表示:轮廓线对象可以用链码(chain)或者区域(region)的形式来表示,链码记录了轮廓上相邻点的相对位置,而区域则提供了闭合的轮廓内部的像素集合。 4. 分析:可以对轮廓线对象进行分析,以获取轮廓的特征,比如长度、曲率、角度、形状描述符等。 在Halcon中处理轮廓线对象通常涉及以下几个步骤: - 使用边缘检测算子识别图像中的物体边缘。 - 使用`threshold`或其他阈值处理算子对边缘图像进行二值化。 - 使用`connection`算子将二值化后的边缘点连接成轮廓线对象。 - 对轮廓线对象进行分析和测量。 轮廓线对象在机器视觉中的应用非常广泛,包括但不限于物体识别、尺寸测量、缺陷检测等。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

多巴胺耐受

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值