当前位置:网站首页>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
边栏推荐
- How to improve data security by renting servers in Hong Kong
- [effective Objective-C] - block and grand central distribution
- 2022 low voltage electrician examination and low voltage electrician simulation examination question bank
- 2166. Design bit set
- Global and Chinese markets of lithium chloride 2022-2028: Research Report on technology, participants, trends, market size and share
- Global and Chinese market of electrolyte analyzers 2022-2028: Research Report on technology, participants, trends, market size and share
- MySQL 8.0 data backup and recovery
- Teach you how to quickly recover data by deleting recycle bin files by mistake
- Test changes in Devops mode -- learning and thinking
- 1.4 learn more about functions
猜你喜欢
Virtual machine installation deepin system
2.6 formula calculation
2.2 integer
An old programmer gave it to college students
Qtablewidget control of QT
AI enhanced safety monitoring project [with detailed code]
Use nodejs+express+mongodb to complete the data persistence project (with modified source code)
JMeter plug-in installation
Node MySQL serialize cannot rollback transactions
The global industrial design revenue in 2021 was about $44360 million, and it is expected to reach $62720 million in 2028. From 2022 to 2028, the CAGR was 5.5%
随机推荐
In 2021, the global foam protection packaging revenue was about $5286.7 million, and it is expected to reach $6615 million in 2028
你真的知道自己多大了吗?
1.4 learn more about functions
Global and Chinese market of high temperature Silver sintering paste 2022-2028: Research Report on technology, participants, trends, market size and share
Pat grade B 1009 is ironic (20 points)
2022 safety officer-c certificate examination and safety officer-c certificate registration examination
In 2021, the global revenue of syphilis rapid detection kits was about US $608.1 million, and it is expected to reach US $712.9 million in 2028
Thread, thread stack, method stack, the difference of creating thread
An old programmer gave it to college students
2.5 conversion of different data types (2)
Cap and base theory
How to read the source code [debug and observe the source code]
[effective Objective-C] - block and grand central distribution
PR notes:
Interval product of zhinai sauce (prefix product + inverse element)
Pytorch sets the weight and bias of the model to zero
Network security Kali penetration learning how to get started with web penetration how to scan based on nmap
Nacos usage of micro services
App compliance
浅议.NET遗留应用改造