码迷,mamicode.com
首页 > 其他好文 > 详细

【halcon】学习记录

时间:2018-02-02 23:18:36      阅读:273      评论:0      收藏:0      [点我收藏+]

标签:win   object   ssi   code   决定   handle   nec   display   txt   

 

图像采集和二值化等处理

* Image Acquisition 01: Code generated by Image Acquisition 01
open_framegrabber (USB3Vision, 0, 0, 0, 0, 0, 0, progressive, -1, default, -1, false, default, 2E03187A8340_MachineVision_MVA5402MU90, 0, -1, AcqHandle)
grab_image_start (AcqHandle, -1)
dev_close_window ()
dev_open_window (0, 0, 512, 512, black, WindowHandle)

while (true)
    grab_image_async (Image, AcqHandle, -1)
    * Image Acquisition 01: Do something
    * rgb转灰度
    rgb1_to_gray (Image, GrayImage)
    * 灰度显示
    dev_display (GrayImage)
    * 二值化 打开灰度直方图
    threshold (GrayImage, Regions, 113, 255)
    * 连接 区域内的连通区域
    connection (Regions, ConnectedRegions)
    * 选择特定图像  打开特征直方图
    select_shape (ConnectedRegions, SelectedRegions, area, and, 195661, 430454) 
    * 区域中心坐标
    area_center (SelectedRegions, Area, Row, Column)
    * 显示以上信息
    disp_message (WindowHandle, 面积: + Area + 坐标: + Row + , + Column, window, 0, 0, blue, true)
endwhile
close_framegrabber (AcqHandle)

 

数组和文件操作

* ***************************************
* 思路决定出路,方向导论  方法论 
* ***************************************
tuple  := [1, 2, 3, 4, 5]
Number := |tuple|
SingleElement := tuple[3]
part := tuple[1:3]
copy := tuple[0:|tuple|-1]

* 读图
read_image (Image, fabrik)
* 区域分割
regiongrowing (Image, Regions, 3, 3, 6, 100)
* 区域数量
count_obj (Regions, Number)

open_file (D:/text1.txt, output, FileHandle)
for i := 1 to Number by 1
    * 选择第i块区域
    select_obj (Regions, ObjectSelected, i) 
    * 计算第i块的面积
    area_center (ObjectSelected, Area, Row, Column)
    * 写文件
    fwrite_string (FileHandle, i +   + Area)
    * 创建换行符  清除输出缓冲区
    fnew_line (FileHandle) 
endfor
close_file (FileHandle)

open_file (D:/text2.txt, output, FileHandle)
* select_obj (Regions, ObjectSelected, 1)
* 计算所有块的面积
area_center (Regions, Area, Row, Column)
fwrite_string (FileHandle, Area +  )
fnew_line (FileHandle)
close_file (FileHandle)

 

【halcon】学习记录

标签:win   object   ssi   code   决定   handle   nec   display   txt   

原文地址:https://www.cnblogs.com/-Mr-y/p/8407152.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!