当前位置:网站首页>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


边栏推荐
- 【c】 Digital bomb
- Oak-d raspberry pie cloud project [with detailed code]
- 4. Data splitting of Flink real-time project
- jvm jni 及 pvm pybind11 大批量数据传输及优化
- [Yugong series] February 2022 Net architecture class 004 ABP vNext used in WPF project
- 2022 low voltage electrician examination and low voltage electrician simulation examination question bank
- Global and Chinese market of full authority digital engine control (FADEC) 2022-2028: Research Report on technology, participants, trends, market size and share
- 2166. Design bit set
- Preliminary practice of niuke.com (11)
- Day6 merge two ordered arrays
猜你喜欢

In 2021, the global foam protection packaging revenue was about $5286.7 million, and it is expected to reach $6615 million in 2028

2022 safety officer-c certificate examination and safety officer-c certificate registration examination
![[Yu Yue education] basic reference materials of manufacturing technology of Shanghai Jiaotong University](/img/95/5baf5c8bedb00e67394a6c0a8234ff.png)
[Yu Yue education] basic reference materials of manufacturing technology of Shanghai Jiaotong University
![AI enhanced safety monitoring project [with detailed code]](/img/a9/cb93f349229e86cbb05ad196ae9553.jpg)
AI enhanced safety monitoring project [with detailed code]

Battle drag method 1: moderately optimistic, build self-confidence (1)

Commands related to files and directories

The 15 year old interviewer will teach you four unique skills that you must pass the interview

Wargames study notes -- Leviathan

It is discussed that the success of Vit lies not in attention. Shiftvit uses the precision of swing transformer to outperform the speed of RESNET

How to do Taobao full screen rotation code? Taobao rotation tmall full screen rotation code
随机推荐
Sword finger offer 30 Stack containing min function
Teach you how to quickly recover data by deleting recycle bin files by mistake
Pat grade B 1009 is ironic (20 points)
Recommendation of books related to strong foundation program mathematics
HCIA-USG Security Policy
Plan for the first half of 2022 -- pass the PMP Exam
【leetcode】1027. Longest arithmetic sequence (dynamic programming)
How to improve data security by renting servers in Hong Kong
Thread, thread stack, method stack, the difference of creating thread
How to do Taobao full screen rotation code? Taobao rotation tmall full screen rotation code
AcWing 1460. Where am i?
Leetcode daily question solution: 540 A single element in an ordered array
【c】 Digital bomb
Microservice knowledge sorting - search technology and automatic deployment technology
Get log4net log file in C - get log4net log file in C
浅议.NET遗留应用改造
11-grom-v2-05-initialization
Rad+xray vulnerability scanning tool
2022 safety officer-c certificate examination and safety officer-c certificate registration examination
1.5 learn to find mistakes first