打开halcon,按下ctrl+e打开halcon自带例程。方法->二维码识别->2d_data_codesrectify_symbol.hdev

*This program demonstrates how to read a slanted
* 2d data code by preprocessing with rectification
*
dev_update_off()
dev_close_window()
* Get the image and display it
*读取并显示图像
read_image(Image_slanted, 'datacode/ecc200/ecc200_to_preprocess_001')
dev_open_window_fit_image(Image_slanted, 0, 0, -1, -1, WindowHandle)
set_display_font(WindowHandle, 14, 'mono', 'true', 'false')
*设置画笔颜色与宽度
dev_set_color('green')
dev_set_line_width(3)
*定义一些显示信息变量
Message : = 'This program demonstrates how to preprocess'Message[1] : = 'a slanted 2d data code with rectification'Message[2] : = 'before reading the data code symbol.'*显示信息disp_message(WindowHandle, Message, 'window', 12, 12, 'black', 'true')disp_continue_message(WindowHandle, 'black', 'true')stop()* Initialize coordinates*定义坐标变量,这是需要进行变换的原始图像的四个边角坐标,在实际项目中这些数据可以通过blob分析或其他方式获取到XCoordCorners : = [130, 225, 290, 63]YCoordCorners : = [101, 96, 289, 269]** Display the slanted image and the corners of the symbol*生成十字叉,方便显示在图像上*第一个参数输出变量*第二个参数十字的X坐标*第三个参数十字的Y坐标*第四个参数十字叉大小*第五个参数十字叉的方向gen_cross_contour_xld(Crosses, XCoordCorners, YCoordCorners, 6, 0.785398)*显示dev_display(Image_slanted)dev_display(Crosses)disp_message(WindowHandle, 'Slanted image', 'window', 12, 12, 'black', 'true')Message : = 'The marked corners are used to generate a'Message[1] : = 'homogeneous transformation matrix which'Message[2] : = 'defines the projective transformation for'Message[3] : = 'the rectification of the symbol.'disp_message(WindowHandle, Message, 'window', 380, 12, 'black', 'true')disp_continue_message(WindowHandle, 'black', 'true')stop()** First generate a transformation matrix using the given points* of the corners of the data code symbol and the corresponding points* of a quare.*求出投影变换矩阵*第一个参数原图像的X坐标*第二个参数原图像的Y坐标*第三个参数原图像的W坐标,因为是在同一个平面上,全设置为1,*第四个参数目标图像上的X坐标*第五个参数目标图像上的Y坐标*第六个参数目标图像上的W坐标*第七个参数变换方式选择,对于常规几何问题,选择'normalized_dlt'*第八个参数输出的投影变化矩阵hom_vector_to_proj_hom_mat2d(XCoordCorners, YCoordCorners, [1, 1, 1, 1], [70, 270, 270, 70], [100, 100, 300, 300], [1, 1, 1, 1], 'normalized_dlt', HomMat2D)** Now rectifiy the slanted image by applying the projective transformation*对原图像进行投影变换*第一个参数输入的倾斜图像*第二个参数输出矫正后的图像*第三个参数求出的投影变换矩阵*第四个参数投影后的图像插值方式*第五个参数是否适应图像大小,false是变换图跟原图一样大小*第五个参数是否对原图像所有像素进行投影变换projective_trans_image(Image_slanted, Image_rectified, HomMat2D, 'bilinear', 'false', 'true')** Create the data code model and search* for the data code in the rectified imagecreate_data_code_2d_model('Data Matrix ECC 200', [], [], DataCodeHandle)*寻找二维码轮廓与解析二维码数据find_data_code_2d(Image_rectified, SymbolXLDs, DataCodeHandle, [], [], ResultHandles, DecodedDataStrings)** Display resultdev_display(Image_slanted)dev_display(Image_rectified)dev_display(SymbolXLDs)disp_message(WindowHandle, 'Decoding successful ', 'window', 12, 12, 'black', 'true')set_display_font(WindowHandle, 12, 'mono', 'true', 'false')disp_message(WindowHandle, DecodedDataStrings, 'window', 350, 70, 'forest green', 'true')

测试用于矫正的原图像

较矫正后测试的二维码图像

上面的官方的例子个人感觉不是很直观,下面是我自己写的一个例程,矫正一个放置倾斜的二维码,思路跟上面是完全一样的

dev_update_on()dev_close_window()* Get the image and display it*读取并显示图像read_image(Image_slanted, 'C:/Users/Administrator/Desktop/6.jpg')dev_open_window_fit_image(Image_slanted, 0, 0, -1, -1, WindowHandle)set_display_font(WindowHandle, 14, 'mono', 'true', 'false')dev_display(Image_slanted)stop()*blob分析找到二维码的位置create_data_code_2d_model('QR Code', [], [], DataCodeHandle)find_data_code_2d(Image_slanted, SymbolXLDs, DataCodeHandle, [], [], ResultHandles, DecodedDataStrings)dev_display(Image_slanted)dev_display(SymbolXLDs)get_contour_xld(SymbolXLDs, Rows, Cols)Rows: = remove(Rows, 4)Cols : = remove(Cols, 4)** First generate a transformation matrix using the given points* of the corners of the data code symbol and the corresponding points* of a quare.*求出投影变换矩阵*第一个参数原图像的X坐标*第二个参数原图像的Y坐标*第三个参数原图像的W坐标,因为是在同一个平面上,全设置为1,*第四个参数目标图像上的X坐标*第五个参数目标图像上的Y坐标*第六个参数目标图像上的W坐标*第七个参数变换方式选择,对于常规几何问题,选择'normalized_dlt'*第八个参数输出的投影变化矩阵hom_vector_to_proj_hom_mat2d(Rows, Cols, [1, 1, 1, 1], [100, 250, 250, 100], [250, 250, 100, 100], [1, 1, 1, 1], 'normalized_dlt', HomMat2D)** Now rectifiy the slanted image by applying the projective transformation*对原图像进行投影变换*第一个参数输入的倾斜图像*第二个参数输出矫正后的图像*第三个参数求出的投影变换矩阵*第四个参数投影后的图像插值方式*第五个参数是否适应图像大小,false是变换图跟原图一样大小*第五个参数是否对原图像所有像素进行投影变换projective_trans_image(Image_slanted, Image_rectified, HomMat2D, 'bilinear', 'false', 'true')** Create the data code model and search* for the data code in the rectified imagecreate_data_code_2d_model('QR Code', [], [], DataCodeHandle)*寻找二维码轮廓与解析二维码数据find_data_code_2d(Image_rectified, SymbolXLDs, DataCodeHandle, [], [], ResultHandles, DecodedDataStrings)** Display resultdev_display(Image_rectified)dev_display(SymbolXLDs)disp_message(WindowHandle, 'Decoding successful ', 'window', 12, 12, 'black', 'true')set_display_font(WindowHandle, 12, 'mono', 'true', 'false')disp_message(WindowHandle, DecodedDataStrings, 'window', 350, 70, 'forest green', 'true')

待矫正图像原图

矫正效果图

Halcon例程分析8:投影变换矫正倾斜图像相关推荐

  1. Halcon例程分析6:圆弧测量工具

    * Example for the application of the measure package * including a lot of visualization operators * ...

  2. Halcon例程学习:adaption_ocv.hev(光学字符检测)

    **************************************************************************************************** ...

  3. Halcon例程(基于多个标定图的单目相机标定)详解—— Camera_calibration_multi_image.hdev

    一.前言 在我的工业相机专栏里已经将相机标定涉及到的理论部分讲解完毕,为什么要标定以及标定要求出什么参数呢,用一个Halcon 例程来帮助理解. 这个例程是比较经典的标定程序,基本将标定过程讲的比较清 ...

  4. 【youcans 的 OpenCV 例程 200 篇】107. 退化图像的维纳滤波

    欢迎关注 『youcans 的 OpenCV 例程 200 篇』 系列,持续更新中 欢迎关注 『youcans 的 OpenCV学习课』 系列,持续更新中 [youcans 的 OpenCV 例程 2 ...

  5. Halcon例程学习:print_check.hev(光学字符检测)

    **************************************************************************************************** ...

  6. 【OpenCV 例程200篇】220.对图像进行马赛克处理

    文章目录:『youcans 的 OpenCV 例程200篇 - 总目录』 [youcans 的 OpenCV 例程200篇]220.对图像进行马赛克处理 9. 图像的马赛克处理 马赛克效果是广泛使用的 ...

  7. 一文弄懂halcon例程:rim.hdev

    一文弄懂halcon例程:rim.hdev 打怪的路上总是无聊的,但是也不能不打啊,我自己现在也在每天打怪升级呢.昨天就因为一个问题,我到视觉群问里面的大牛,结果,他不帮我解答,他不告诉我怎么解决就算 ...

  8. 【youcans 的 OpenCV 例程200篇】194.寻找图像轮廓(cv.findContours)

    OpenCV 例程200篇 总目录-202205更新 [youcans 的 OpenCV 例程200篇]194.寻找图像轮廓(cv.findContours) 1. 轮廓 轮廓是一系列相连的像素点组成 ...

  9. Hi3518EV300-venc例程分析

    Hi3518EV300-venc例程分析 前言: MAPI 层业务流程 VENC录像 流程: 1.定义要绑定的VCap,VProc,VENC变量 2.start vcap 3.start vproc( ...

最新文章

  1. Zynq ROM 加载Mode 图表
  2. Rundeck crontab格式
  3. Git 工具 - 子模块 外部引用
  4. Transformer 模型详解
  5. 互联网拥塞控制终极指南
  6. JVM系列之:Contend注解和false-sharing
  7. MySQL视图查询报错:Prepared statement needs to be re-prepared
  8. 使用foreach循环遍历集合元素
  9. spring @Scheduled 注解实现的定时任务 3步走
  10. keepalived详解(一)——keepalived理论基础
  11. unity用代码生成的物体或line renderer让其在确定的某一个层里面的方法
  12. 缠中说禅重新编排版《论语》(编撰版)
  13. 【SpringBoot 框架】- SpringBoot 配置文件,深入浅出mysql第三版pdf百度云
  14. 三个mplayer播放器mplayer mpv mplayer-ww
  15. java faker_Faker--伪造数据利器
  16. 极限、微分、积分 必会公式总结
  17. Python人脸识别——从入门到工程实践
  18. 百度的文心一言 ChatGTP 的对比
  19. C - Neko does Maths 数论
  20. C IN ARM64 汇编基础-变量与表达式-基于The C Programming Language - Second Edition

热门文章

  1. UE4 材质制作闪烁心脏起搏效果 学习笔记
  2. 研发管理:与员工一对一交流的执行与反思
  3. 电脑有网却打不开网页(能ping通)
  4. fseek() 函数
  5. Python面向对象之六:类的约束和super函数
  6. BI商业智能开启新时代,什么样的BI工具值得选?
  7. 一文读懂C#中的抽象类、抽象方法、virtual虚函数、override重写函数及父类子类构造函数和析构函数的执行顺序
  8. 华为HCNA之SNMP基础配置实验
  9. 使用C语言编写一个两个数的加减乘除程序
  10. android距离感应器控制屏幕灭屏白屏