Halcon 重写Rectangle2及Arrow

验证目标:验证rotate_image后图像是否变形

获取信息:获取矩形中轴起点,终点,及四角位置信息

应用场景:1,找线找点算子封装后为检测极性指明方向

2,为二次定位提供位置信息

读取原图

复制代码
read_image (Image123, 'E:/Halcon数据/资源图片/34.png')

获取外接矩形,验证图像旋转后是否变形

复制代码
rotate_image (Image123, ImageRotate, 45, 'constant')
dev_set_color ('red')
dev_set_line_width (3)
gen_rectangle1 (ROI_0, 177.5, 213.5, 519.5, 759.5)
reduce_domain (ImageRotate, ROI_0, ImageReduced)
threshold (ImageReduced, Region, 0, 20)
smallest_rectangle2 (Region, Row, Col, Phi, Length1, Length2)
gen_rectangle2_contour_xld (Rectangle, Row, Col, Phi, Length1, Length2)

获取中轴起点,终点位置

复制代码
*中轴起点
RowStart := Row + sin(Phi) * Length1
*中轴终点
RowEnd := Row - sin(Phi) * Length1
*中轴起点
ColStart := Col - cos(Phi) * Length1
*中轴终点
ColEnd := Col + cos(Phi) * Length1
dev_display (ImageRotate)
gen_cross_contour_xld (Cross, RowStart, ColStart, 60, Phi)
gen_cross_contour_xld (Cross, RowEnd, ColEnd, 60, Phi)

获取矩形四顶点信息

复制代码
dev_display (ImageRotate)
drow := sin(rad(90) - Phi) * Length2
dcol := cos(rad(90) - Phi) * Length2
*左上
dev_set_color ('green')
RLeftUp:=Row + sin(Phi) * Length1 - sin(rad(90) - Phi) * Length2
CLeftUp:=Col - cos(Phi) * Length1 - cos(rad(90) - Phi) * Length2
gen_cross_contour_xld (Cross1, RLeftUp, CLeftUp, 60, Phi)
*右上
RRightUp:=Row - sin(Phi) * Length1 - sin(rad(90) - Phi) * Length2
CRightUp:=Col + cos(Phi) * Length1 - cos(rad(90) - Phi) * Length2
gen_cross_contour_xld (Cross2, RRightUp, CRightUp, 60, Phi)
*右下
RRightDown:=Row - sin(Phi) * Length1 + sin(rad(90) - Phi) * Length2
CRightDown:=Col + cos(Phi) * Length1 + cos(rad(90) - Phi) * Length2
gen_cross_contour_xld (Cross3, RRightDown, CRightDown, 60, Phi)
*左下
RLeftDown:= Row + sin(Phi) * Length1 + sin(rad(90) - Phi) * Length2
CLeftDown:=Col - cos(Phi) * Length1 +  cos(rad(90) - Phi) * Length2
gen_cross_contour_xld (Cross4, RLeftDown, CLeftDown, 60, Phi)

重写矩形2轮廓方式1

复制代码
dev_set_color ('blue')
gen_contour_polygon_xld (Contour, [RLeftUp,RRightUp,RRightDown,RLeftDown,RLeftUp], [CLeftUp,CRightUp,CRightDown,CLeftDown,CLeftUp])

重写矩形2轮廓方式2

复制代码
gen_contour_polygon_xld (Contour1, [RowStart - drow,RowEnd - drow,RowEnd + drow,RowStart + drow,RowStart - drow], [ColStart - dcol,ColEnd - dcol,ColEnd + dcol,ColStart + dcol,ColStart - dcol])

重写Arrow

复制代码
ArrowAngle := rad(45) / 2
ArrowLength := Length1 * 0.2
dev_display (ImageRotate)
gen_contour_polygon_xld (CProfile, [RowStart,RowEnd], [ColStart,ColEnd])
gen_contour_polygon_xld (CArrow, [RowEnd - sin(ArrowAngle - Phi) * ArrowLength,RowEnd,RowEnd + sin(ArrowAngle + Phi) * ArrowLength], [ColEnd - cos(ArrowAngle - Phi) * ArrowLength,ColEnd,ColEnd - cos(ArrowAngle + Phi) * ArrowLength])

过矩形2中点做垂直于中轴的指定长度线段

复制代码
PSize := Length2 * 0.2
gen_contour_polygon_xld (CMidPoint, [Row - sin(rad(90) + Phi) * PSize,Row - sin(Phi - rad(90)) * PSize], [Col + cos(rad(90) + Phi) * PSize,Col + cos(Phi - rad(90)) * PSize])

对于角度相对稳定目标可以采取直接偏移方式

复制代码
gen_rectangle2 (Rectangle, (RLeftUp + RLeftDown)/2-30, (CLeftUp + CLeftDown)/2+30, Phi, 30, 30)

检测目标矩形波动角度相当大时可以采用中轴点计算

以中轴点四分之一为例

复制代码
dev_display (ImageRotate)
gen_rectangle2 (Rectangle, (RowStart + Row)/2, (ColStart + Col)/2, Phi, 30, 30)
相关推荐
应用市场2 分钟前
OpenCV进阶:图像变换、增强与特征检测实战
人工智能·opencv·计算机视觉
说私域10 分钟前
开源链动2+1模式、AI智能名片与S2B2C商城小程序:社群经济的数字化重构路径
人工智能·小程序·开源
lingchen190610 分钟前
卷积神经网络中的卷积运算原理
深度学习·计算机视觉·cnn
rengang6613 分钟前
智能化的重构建议:大模型分析代码结构,提出可读性和性能优化建议
人工智能·性能优化·重构·ai编程
小龙报14 分钟前
《算法通关指南---C++编程篇(2)》
c语言·开发语言·数据结构·c++·程序人生·算法·学习方法
灵遁者书籍作品21 分钟前
语言的拓扑学约束公理:语言对实在的描述具有拓扑不变量——某些真理必须通过悖论、沉默或隐喻表达
人工智能·计算机视觉
一尘之中22 分钟前
觉醒的拓扑学:在量子纠缠与神经幻象中重构现实认知
人工智能·重构
金宗汉23 分钟前
《宇宙递归拓扑学:基于自指性与拓扑流形的无限逼近模型》
大数据·人工智能·笔记·算法·观察者模式
Joy T1 小时前
海南蓝碳:生态财富与科技驱动的新未来
大数据·人工智能·红树林·海南省·生态区建设
N0nename1 小时前
TR3--Transformer之pytorch复现
人工智能·pytorch·python