halcon联合C#测量十字Mark中心

halcon联合C#测量十字Mark中心

函数说明

public void FitRectangleMeasure(HWindow 窗口句柄, HImage 图像, out double 中心Y坐标, out double 中心X坐标)

操作步骤,首先绘制两个矩形测量框;之后就可进行自动计算。

public void FitRectangleMeasure(HWindow hWindow, HImage hImage, out double Row, out double Col){try{int rtCount = 2;double[] rtRows = new double[rtCount];double[] rtCols = new double[rtCount];double[] rtAngles = new double[rtCount];double[] rtLen1s = new double[rtCount];double[] rtLen2s = new double[rtCount];hWindow.SetColor("red");hWindow.SetDraw("margin");HTuple hv_Row1, hv_Column1, hv_Row2, hv_Column2, hv_RectangleParameter;//绘制测量矩形for (int rtIndex = 0; rtIndex < rtCount; rtIndex++){HOperatorSet.DrawRectangle1Mod(hWindow, 1000, 1000, 1200, 1200, out hv_Row1, out hv_Column1, out hv_Row2, out hv_Column2);double dRowCenter = (hv_Row1.D + hv_Row2.D) / 2;double dColCenter = (hv_Column1.D + hv_Column2.D) / 2;double dL1 = (hv_Column2.D - hv_Column1.D) / 2;double dL2 = (hv_Row2.D - hv_Row1.D) / 4;rtRows[rtIndex] = dRowCenter;rtCols[rtIndex] = dColCenter;rtAngles[rtIndex] = 0;rtLen1s[rtIndex] = dL1;rtLen2s[rtIndex] = dL2;}//测量宽度int nHalfBorder = (int)(Math.Min(rtLen1s[0], rtLen2s[0]) + Math.Min(rtLen1s[1], rtLen2s[1])) / 2;//矩形测量句柄的创建HTuple hv_MetrologyHandle = null, hv_MetrologyRectangleIndices = null;HOperatorSet.CreateMetrologyModel(out hv_MetrologyHandle);HOperatorSet.AddMetrologyObjectRectangle2Measure(hv_MetrologyHandle, new HTuple(rtRows),new HTuple(rtCols), new HTuple(rtAngles), new HTuple(rtLen1s), new HTuple(rtLen2s), nHalfBorder, nHalfBorder / 4,1, 10, new HTuple(), new HTuple(), out hv_MetrologyRectangleIndices);HOperatorSet.SetMetrologyObjectParam(hv_MetrologyHandle, hv_MetrologyRectangleIndices, "num_instances", 1);HOperatorSet.SetMetrologyObjectParam(hv_MetrologyHandle, hv_MetrologyRectangleIndices, "min_score", 0.1);HOperatorSet.SetMetrologyObjectParam(hv_MetrologyHandle, hv_MetrologyRectangleIndices, "measure_transition", "uniform");HOperatorSet.ApplyMetrologyModel(hImage, hv_MetrologyHandle);//测量出的信息HObject ho_MeasureContours;//测量框 HObject ho_Cross;   //测量出来的交界点HOperatorSet.GenEmptyObj(out ho_MeasureContours);HOperatorSet.GenEmptyObj(out ho_Cross);ho_MeasureContours.Dispose();ho_Cross.Dispose();HOperatorSet.GetMetrologyObjectMeasures(out ho_MeasureContours, hv_MetrologyHandle, "all", "all", out hv_Row1, out hv_Column1);HOperatorSet.GenCrossContourXld(out ho_Cross, hv_Row1, hv_Column1, 20, 0.785398);hWindow.DispObj(ho_MeasureContours);//hWindow.DispObj(ho_Cross);HOperatorSet.GetMetrologyObjectResult(hv_MetrologyHandle, "all", "all", "result_type","all_param", out hv_RectangleParameter);//测量出来的矩形框HObject ho_ResultContour;HOperatorSet.GenEmptyObj(out ho_ResultContour);ho_ResultContour.Dispose();HOperatorSet.GetMetrologyObjectResultContour(out ho_ResultContour, hv_MetrologyHandle, "all", "all", 1.5);hWindow.DispObj(ho_ResultContour);//测量出矩形的数据HTuple hv_Sequence, hv_RectangleRow, hv_RectangleColumn, hv_RectanglePhi, hv_RectangleLength1, hv_RectangleLength2;hv_Sequence = HTuple.TupleGenSequence(0, (new HTuple(hv_RectangleParameter.TupleLength())) - 1, 5);hv_RectangleRow = hv_RectangleParameter.TupleSelect(hv_Sequence);hv_RectangleColumn = hv_RectangleParameter.TupleSelect(hv_Sequence + 1);hv_RectanglePhi = hv_RectangleParameter.TupleSelect(hv_Sequence + 2);hv_RectangleLength1 = hv_RectangleParameter.TupleSelect(hv_Sequence + 3);hv_RectangleLength2 = hv_RectangleParameter.TupleSelect(hv_Sequence + 4);if (hv_RectangleRow.TupleLength() == rtCount){Row = (hv_RectangleRow[0].D + hv_RectangleRow[1].D) / 2;Col = (hv_RectangleColumn[0].D + hv_RectangleColumn[1].D) / 2;}else{Row = 0;Col = 0;}HOperatorSet.ClearMetrologyModel(hv_MetrologyHandle);//释放HObjectho_MeasureContours.Dispose();ho_Cross.Dispose();ho_ResultContour.Dispose();}catch{Row = 0;Col = 0;}}

不懂的话可以问我哦,下边评论看到了第一时间回复。如果觉得有用点赞哦。

PS

我的博客不定时分享日常工作中觉得有价值的内容,包括C#、C++、halcon、运动控制等等内容,喜欢的点赞,关注我。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/254682.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

x264 struct 学习

x264_t结构体维护着CODEC的诸多重要信息其中成员frames是一个指示和控制帧编码过程的结构。其中current是已经准备就绪可以编码的帧&#xff0c;其类型已经确定&#xff1b;next是尚未确定类型的帧&#xff1b;unused用于回收不使用的frame结构体以备今后再次使用。 structx26…

单例模式的新实现

单例模式的新实现 jdk1.5 之前 单例模式的两种方式&#xff0c;两种方法都是要把构造器保持私有的&#xff0c;并导出公有的静态成员&#xff0c;以便允许客户端能够访问该类的唯一实例。 第一种方法中&#xff0c;公有的静态成员是个final域: //Singleton with public final f…

有关莫比乌斯反演

对于两个定义域为整数的函数F(x)和f(x); 若有: 然后F(x)可以快速求出&#xff1b; 如何用F求解f呢&#xff1f; 莫比乌斯反演&#xff1a; 对于两个定义域为整数的函数F(x)和f(x); 若有: 则有&#xff1a; 其中μ(x)为莫比乌斯函数&#xff0c;其定义为&#xff1a; 对于&#…

(原创)JS点击事件——Uncaught TypeError: Cannot set property 'onclick' of null

html部分代码&#xff1a; JS部分代码&#xff1a; 需要实现的效果&#xff1a;点击图片&#xff0c;来回相互切换。 我开始的错误做法&#xff1a;代码如上图所示&#xff08;逻辑上看起来是没有错误的&#xff09; 尝试过程&#xff1a;把JS代码放在</body>闭合标签之前…

事务传播机制/数据库异常解析——2016-8-13分享总结

一. 事务的传播机制&#xff0f;required 跟 required new 的使用与区别 基础回顾 1.1 事务的隔离级别&#xff1a; ISOLATION_READ_UNCOMMITTED&#xff08;读未提交&#xff09; ISOLATION_READ_COMMITTED&#xff08;读已提交&#xff09; ISOLATION_REPEATABLE_READ&#x…

console类详细解释

console类详细解释 微软链接https://docs.microsoft.com/zh-cn/dotnet/api/system.console?viewnetframework-4.8 C#中没有标准输入输出关键字&#xff0c;要调用console类下的方法。 练习与解释代码 using System; using System.Collections.Generic; using System.Linq; …

VC下调用x264进行视频编码,

4.X264.c中,h x264_encoder_open( param ) )是用来复制参数并验证参数的有效性,在CCS下应该是不需要验证参数的(参数都是在程序中设置好的),因此此处只作复制参数param和初始化X264_T h的操作.(VC下程序修改记录080106下午)修改COMMON.C中的void x264_param_default( x264_…

UploadRTOS.exe

UploadRTOS.exe类似于一个启动并为VxWin运行做准备的工具程序。VxWin安装之后&#xff0c;可以使用 上传工具程序 启动实时操作系统。 利用命令行参数,您可以使它执行不同的功能。该 上传工具程序 包含两个文件: UploadRTOS.exe (命令行程序) UploadR…

20155307 2016-2017 《Java程序设计》第三次实验报告

&#xff08;一&#xff09;敏捷开发与XP 敏捷开发是一种以人为核心、迭代、循序渐进的开发方法。“敏捷流程”是一系列价值观和方法论的集合。从2001年开始&#xff0c;一些软件界的专家开始倡导“敏捷”的价值观和流程&#xff0c;他们肯定了流行做法的价值&#xff0c;但是强…

ElasticSearch创建、修改、获取、删除、索引Indice mapping和Index Template案例

为什么80%的码农都做不了架构师&#xff1f;>>> The best elasticsearch highlevel java rest api-----bboss ElasticSearch客户端框架bboss的ClientInterface 接口提供了创建/修改、获取、删除索引Indice和IndexTemplate的方法&#xff0c;本文举例说明其使用方法…

ASCII码与string的相互转换

ASCII码与string的相互转换 思路&#xff1a; 1&#xff09;ASCII码转string&#xff1a;把字符&#xff08;串&#xff09;直接转换为int类型&#xff0c;即可得到ASCII码&#xff1b; 2&#xff09;string转ASCII码&#xff1a;将数字转换为字符串转出&#xff1b; {//将字…

X264代码中一些参数的意义

Main&#xff08;int argc&#xff0c;char *argv[]&#xff09;; 为了方便起见&#xff0c;不妨改写为&#xff1a; Main(void){ ...... intargc5; char*argv[]{ "main","-o","test.264","foreman.yuv","352x288" }; …

spring mvc注解@RequestMapping

1、url路径映射 基本功能 2、窄化请求映射 根路径子路径 注意setViewName的路径。 3、限制http请求方法 get和 post 如果是get 转载于:https://www.cnblogs.com/jway1101/p/5773923.html

Start application automatically during controller boot-up

&#xfeff;&#xfeff; Tip English •German Start application automatically during controller boot-up Description It is possible to start any program automatically during the boot-up procedure of the KR C4 controller. Precondition •User group “Exper…

C#using static

平常用法&#xff1a; using 命名空间&#xff1b; using System; Console.WriteLine("Hello&#xff0c;World&#xff01;");using static用法&#xff1a; C#6中支持这种写法&#xff0c;这样定义后可以可以访问类的静态成员 WriteLine是Console类的静态函数&am…

redis数据迁移

一&#xff1a;AOF方式 需求&#xff1a; 一个没有数据的redis。 清空redis数据方法 bash> echo "keys *" | redis-cli --raw -p 6378 |sed -r s/(.*)/redis-cli --raw -p 6378 del \1 /g |bash 1.备份 bash> redis-cli --raw -p 6378 redis> config get di…

阿里云OSS 上传文件SDK

Aliyun OSS SDK for C# 上传文件 另外&#xff1a;查找的其他实现C#上传文件功能例子&#xff1a; 1、WPF用流的方式上传/显示/下载图片文件(保存在数据库) &#xff08;文末有案例下载链接&#xff09; 2、WPF中利用WebClient向服务器上传文件 3、C#文件上传的简单实现 4、C#实…

关于level_idc和Profile_IDC的解释

2010-01-21 15:51:40| 分类&#xff1a; windows mobile开 |字号 订阅 Description: Set bitstream Profile IDC. Default is 88. Note: Some profiles cannot support certain features. See MPEG-4 AVC for supported features for each profile. Reference software may…

老婆的驾照要下来了,形容下我此刻的心情

&#xfeff;&#xfeff; 老婆的驾照要下来了&#xff0c;形容下我此刻的心情&#xff1a; 路上遇到的女人&#xff0c;大部分是不用眼睛和脑子开车的&#xff0c;完全是凭自己的感觉开车。凡是看到前车奇慢、路口犹豫不决、不打灯缓慢变线、不该…

ADO.NET改进防注入

static void Main1(string[] args) { //用户输入一个需要查询的条件 car表 Console.WriteLine("请输入"); string code Console.ReadLine(); SqlConnection conn new SqlConnection("server.;databasemydb;usersa;pwd100867"); SqlCommand cmd conn.Crea…