栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

Halcon图像处理入门篇(二)

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Halcon图像处理入门篇(二)

Halcon图像处理入门篇之C++
 上一篇说到过halcon的特点在于它实现了从halcon自创语言到C、C++、Java、Python、C#语言的转换,从而为基于图像类的开发节省了大量的宝贵时间。本篇开篇将以C++为例阐述Halcon从验证脚本和C++的无缝连接。

1、开发环境,VS2015,Halcon20.11
2、测试项目
开发环境搭建
1、关于halcon 的License,详情请见4y9b提取码:4y9b
2、halcon转换为C++

3、VS配置





  // Local iconic variables
  HObject  ho_Image, ho_ThreImage, ho_ConnectImage;
  HObject  ho_SelectImage, ho_GetRec, ho_ROIImage, ho_ImageLaplace;
  HObject  ho_Border, ho_ObjectSelected, ho_SmoothedContours;

  // Local control variables
  HTuple  hv_R1, hv_C1, hv_R2, hv_C2, hv_Row1, hv_Col1;
  HTuple  hv_Row2, hv_Col2, hv_errdist, hv_distRow, hv_a;
  HTuple  hv_e, hv_g, hv_KeyValue, hv_i, hv_result;

  ReadImage(&ho_Image, "C:/test.jpg");
  Threshold(ho_Image, &ho_ThreImage, 0, 4);
  Connection(ho_ThreImage, &ho_ConnectImage);
  SelectShape(ho_ConnectImage, &ho_SelectImage, ((HTuple("area").Append("inner_height")).Append("rect2_len1")), 
      "and", ((HTuple(2000).Append(30)).Append(20)), ((HTuple(10000).Append(100)).Append(60)));
  SmallestRectangle1(ho_SelectImage, &hv_R1, &hv_C1, &hv_R2, &hv_C2);
  if (0 != (int((hv_R1.TupleLength())==0)))
  {
  }
  GenRectangle1(&ho_GetRec, hv_R1-10, hv_C1, hv_R2, hv_C2);
  ReduceDomain(ho_Image, ho_GetRec, &ho_ROIImage);

  LaplaceOfGauss(ho_ROIImage, &ho_ImageLaplace, 0.5);
  ThresholdSubPix(ho_ImageLaplace, &ho_Border, 1);
  SelectObj(ho_Border, &ho_ObjectSelected, 1);
  SmoothContoursXld(ho_ObjectSelected, &ho_SmoothedContours, 15);
  GetContourXld(ho_SmoothedContours, &hv_Row1, &hv_Col1);
  GetContourXld(ho_ObjectSelected, &hv_Row2, &hv_Col2);

  hv_errdist = 0.5;
  hv_distRow = (((hv_Row1-hv_Row2)*(hv_Row1-hv_Row2))+((hv_Col1-hv_Col2)*(hv_Col1-hv_Col2))).TupleSqrt();
  hv_a = (hv_distRow.TupleGreaterElem(hv_errdist)).TupleFind(1);
  hv_e = HTuple(hv_Row2[hv_a]);
  hv_g = HTuple(hv_Col2[hv_a]);
  hv_KeyValue = 0;
  {
  HTuple end_val23 = (hv_e.TupleLength())-1;
  HTuple step_val23 = 1;
  for (hv_i=0; hv_i.Continue(end_val23, step_val23); hv_i += step_val23)
  {
    hv_KeyValue += HTuple(hv_e[hv_i]);
  }
  }
  hv_result = (hv_KeyValue/(220*(hv_e.TupleLength())))+3.2;

输入图像:

效果

结果:

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/344172.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号