当前位置:网站首页>Measurement fitting based on Halcon learning -- Practice [1]
Measurement fitting based on Halcon learning -- Practice [1]
2022-07-03 20:30:00 【BoomBiuBiu】
This example is to correct the rotating charging head , When the position of the measuring rectangle remains unchanged ;
It can be compared with the examples of measuring chip pins in the previous two articles
* Image Acquisition 01: Code generated by Image Acquisition 01
open_framegrabber ('DirectShow', 1, 1, 0, 0, 0, 0, 'default', 8, 'gray', -1, 'false', 'default', '[0] Web Camera', 0, -1, AcqHandle)
grab_image_start (AcqHandle, -1)
while (true)
grab_image_async (Image, AcqHandle, -1)
* location
* Two valued
threshold (Image, Regions, 115, 253)
* Form different connected domains
connection (Regions, ConnectedRegions)
* Using area features to select areas
select_shape (ConnectedRegions, SelectedRegions, 'area', 'and', 45321.1, 200000)
* Get the row and column coordinates of the area
area_center (SelectedRegions, Area, Row, Column)
* Get the angle of the area
orientation_region (SelectedRegions, Phi)
* Affine transformation
vector_angle_to_rigid (Row, Column, Phi, Row, Column, rad(90), HomMat2D)
affine_trans_image (Image, ImageAffineTrans, HomMat2D, 'constant', 'false')
affine_trans_region (SelectedRegions, RegionAffineTrans, HomMat2D, 'nearest_neighbor')
* Cutout
reduce_domain (ImageAffineTrans, RegionAffineTrans, ImageReduced)
* Measure 01: Code generated by Measure 01
* Measure 01: Prepare measurement
AmplitudeThreshold := 12
RoiWidthLen2 := 21
set_system ('int_zooming', 'true')
* Measure 01: Coordinates for line Measure 01 [0]
LineRowStart_Measure_01_0 := 244.681
LineColumnStart_Measure_01_0 := 874.067
LineRowEnd_Measure_01_0 := 241.673
LineColumnEnd_Measure_01_0 := 1323.72
* Measure 01: Convert coordinates to rectangle2 type
TmpCtrl_Row := 0.5*(LineRowStart_Measure_01_0+LineRowEnd_Measure_01_0)
TmpCtrl_Column := 0.5*(LineColumnStart_Measure_01_0+LineColumnEnd_Measure_01_0)
TmpCtrl_Dr := LineRowStart_Measure_01_0-LineRowEnd_Measure_01_0
TmpCtrl_Dc := LineColumnEnd_Measure_01_0-LineColumnStart_Measure_01_0
TmpCtrl_Phi := atan2(TmpCtrl_Dr, TmpCtrl_Dc)
TmpCtrl_Len1 := 0.5*sqrt(TmpCtrl_Dr*TmpCtrl_Dr + TmpCtrl_Dc*TmpCtrl_Dc)
TmpCtrl_Len2 := RoiWidthLen2
* Measure 01: Create measure for line Measure 01 [0]
* Measure 01: Attention: This assumes all images have the same size!
gen_measure_rectangle2 (TmpCtrl_Row, TmpCtrl_Column, TmpCtrl_Phi, TmpCtrl_Len1, TmpCtrl_Len2, 1920, 1080, 'nearest_neighbor', MsrHandle_Measure_01_0)
* Set the way of drawing
dev_set_draw ('margin')
gen_measure_rectangle2 (TmpCtrl_Row, TmpCtrl_Column, TmpCtrl_Phi, TmpCtrl_Len1, TmpCtrl_Len2, 1920, 1080, 'nearest_neighbor', MsrHandle_Measure_02_0)
* Get measurement rectangle
gen_rectangle2 (Rectangle, TmpCtrl_Row, TmpCtrl_Column, TmpCtrl_Phi, TmpCtrl_Len1, TmpCtrl_Len2)
* Measure 01: Execute measurements
measure_pos (Image, MsrHandle_Measure_01_0, 1, AmplitudeThreshold, 'all', 'all', Row_Measure_01_0, Column_Measure_01_0, Amplitude_Measure_01_0, Distance_Measure_01_0)
* Measure 01: Do something with the results
* Measure 01: Clear measure when done
close_measure (MsrHandle_Measure_01_0)
endwhile
close_framegrabber (AcqHandle)Turn on the camera to operate :
* Image Acquisition 01: Code generated by Image Acquisition 01
open_framegrabber ('DirectShow', 1, 1, 0, 0, 0, 0, 'default', 8, 'gray', -1, 'false', 'default', '[0] Web Camera', 0, -1, AcqHandle)
grab_image_start (AcqHandle, -1)
while (true)
grab_image_async (Image, AcqHandle, -1)
endwhile
close_framegrabber (AcqHandle)
* Two valued
threshold (Image, Regions, 115, 253)
* Form different connected domains
connection (Regions, ConnectedRegions)
* Using area features to select areas
select_shape (ConnectedRegions, SelectedRegions, 'area', 'and', 45321.1, 200000)
* Get the row and column coordinates of the area
area_center (SelectedRegions, Area, Row, Column)
* Get the angle of the area
orientation_region (SelectedRegions, Phi)
* Affine transformation
vector_angle_to_rigid (Row, Column, Phi, Row, Column, rad(90), HomMat2D)
affine_trans_image (Image, ImageAffineTrans, HomMat2D, 'constant', 'false')
affine_trans_region (SelectedRegions, RegionAffineTrans, HomMat2D, 'nearest_neighbor')
* Cutout
reduce_domain (ImageAffineTrans, RegionAffineTrans, ImageReduced)

Open the measurement assistant to insert the code :
* Measure 01: Code generated by Measure 01
* Measure 01: Prepare measurement
AmplitudeThreshold := 12
RoiWidthLen2 := 21
set_system ('int_zooming', 'true')
* Measure 01: Coordinates for line Measure 01 [0]
LineRowStart_Measure_01_0 := 244.681
LineColumnStart_Measure_01_0 := 874.067
LineRowEnd_Measure_01_0 := 241.673
LineColumnEnd_Measure_01_0 := 1323.72
* Measure 01: Convert coordinates to rectangle2 type
TmpCtrl_Row := 0.5*(LineRowStart_Measure_01_0+LineRowEnd_Measure_01_0)
TmpCtrl_Column := 0.5*(LineColumnStart_Measure_01_0+LineColumnEnd_Measure_01_0)
TmpCtrl_Dr := LineRowStart_Measure_01_0-LineRowEnd_Measure_01_0
TmpCtrl_Dc := LineColumnEnd_Measure_01_0-LineColumnStart_Measure_01_0
TmpCtrl_Phi := atan2(TmpCtrl_Dr, TmpCtrl_Dc)
TmpCtrl_Len1 := 0.5*sqrt(TmpCtrl_Dr*TmpCtrl_Dr + TmpCtrl_Dc*TmpCtrl_Dc)
TmpCtrl_Len2 := RoiWidthLen2
* Measure 01: Create measure for line Measure 01 [0]
* Measure 01: Attention: This assumes all images have the same size!
gen_measure_rectangle2 (TmpCtrl_Row, TmpCtrl_Column, TmpCtrl_Phi, TmpCtrl_Len1, TmpCtrl_Len2, 1920, 1080, 'nearest_neighbor', MsrHandle_Measure_01_0)
* Measure 01: Execute measurements
measure_pos (Image, MsrHandle_Measure_01_0, 1, AmplitudeThreshold, 'all', 'all', Row_Measure_01_0, Column_Measure_01_0, Amplitude_Measure_01_0, Distance_Measure_01_0)
* Measure 01: Do something with the results
* Measure 01: Clear measure when done
close_measure (MsrHandle_Measure_01_0)
Add a code to display the measurement rectangle :
gen_measure_rectangle2 (TmpCtrl_Row, TmpCtrl_Column, TmpCtrl_Phi, TmpCtrl_Len1, TmpCtrl_Len2, 1920, 1080, 'nearest_neighbor', MsrHandle_Measure_01_0)
* Set the way of drawing
dev_set_draw ('margin')
gen_measure_rectangle2 (TmpCtrl_Row, TmpCtrl_Column, TmpCtrl_Phi, TmpCtrl_Len1, TmpCtrl_Len2, 1920, 1080, 'nearest_neighbor', MsrHandle_Measure_02_0)
* Get measurement rectangle
gen_rectangle2 (Rectangle, TmpCtrl_Row, TmpCtrl_Column, TmpCtrl_Phi, TmpCtrl_Len1, TmpCtrl_Len2)
How many degrees does the charging head rotate around the center , Can automatically correct , And draw the measuring rectangle


边栏推荐
- PR notes:
- About unregistered transfer login page
- Detailed and not wordy. Share the win10 tutorial of computer reinstallation system
- 强化学习-学习笔记1 | 基础概念
- Use nodejs+express+mongodb to complete the data persistence project (with modified source code)
- thrift go
- Change deepin to Alibaba image source
- Interval product of zhinai sauce (prefix product + inverse element)
- 2.5 conversion of different data types (2)
- Thread, thread stack, method stack, the difference of creating thread
猜你喜欢

JVM JNI and PVM pybind11 mass data transmission and optimization

你真的知道自己多大了吗?

浅议.NET遗留应用改造

2.6 formula calculation

Wechat applet quick start (including NPM package use and mobx status management)

2.7 format output of values

How to do Taobao full screen rotation code? Taobao rotation tmall full screen rotation code

IP address is such an important knowledge that it's useless to listen to a younger student?

Camera calibration (I): robot hand eye calibration

In 2021, the global foam protection packaging revenue was about $5286.7 million, and it is expected to reach $6615 million in 2028
随机推荐
CesiumJS 2022^ 源码解读[7] - 3DTiles 的请求、加载处理流程解析
P5.js development - setting
【c】 Digital bomb
How to handle wechat circle of friends marketing activities and share production and release skills
Assign the CMD command execution result to a variable
【leetcode】1027. Longest arithmetic sequence (dynamic programming)
Sparse matrix (triple) creation, transpose, traversal, addition, subtraction, multiplication. C implementation
Global and Chinese market of charity software 2022-2028: Research Report on technology, participants, trends, market size and share
[raid] [simple DP] mine excavation
Q&A:Transformer, Bert, ELMO, GPT, VIT
[Yugong series] February 2022 Net architecture class 004 ABP vNext used in WPF project
How to improve data security by renting servers in Hong Kong
Change deepin to Alibaba image source
Day6 merge two ordered arrays
Analysis of gas fee setting under eip1559
Instructions for common methods of regular expressions
About callback function and hook function
2022 melting welding and thermal cutting examination materials and free melting welding and thermal cutting examination questions
Microsoft: the 12th generation core processor needs to be upgraded to win11 to give full play to its maximum performance
Leetcode daily question solution: 540 A single element in an ordered array