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


边栏推荐
- QT tutorial: signal and slot mechanism
- Cap and base theory
- Global and Chinese market of two in one notebook computers 2022-2028: Research Report on technology, participants, trends, market size and share
- [effective Objective-C] - block and grand central distribution
- Microservice framework - frequently asked questions
- 1.4 learn more about functions
- Global and Chinese markets of cast iron diaphragm valves 2022-2028: Research Report on technology, participants, trends, market size and share
- 浅议.NET遗留应用改造
- PR notes:
- Nacos usage of micro services
猜你喜欢

MPLS configuration

Preliminary practice of niuke.com (11)

Detailed and not wordy. Share the win10 tutorial of computer reinstallation system

Machine learning support vector machine SVM

Test panghu was teaching you how to use the technical code to flirt with girls online on Valentine's Day 520

Wargames study notes -- Leviathan

Shortest path problem of graph theory (acwing template)

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

AcWing 1460. Where am i?

Introduction to golang garbage collection
随机推荐
Task of gradle learning
Assign the CMD command execution result to a variable
[Yu Yue education] basic reference materials of manufacturing technology of Shanghai Jiaotong University
Micro service knowledge sorting - cache technology
Ruby replaces gem Alibaba image
First knowledge of database
Day6 merge two ordered arrays
Rad+xray vulnerability scanning tool
Sword finger offer 30 Stack containing min function
44. Concurrent programming theory
C 10 new feature [caller parameter expression] solves my confusion seven years ago
47. Process lock & process pool & Collaboration
2022 melting welding and thermal cutting examination materials and free melting welding and thermal cutting examination questions
Teach you how to quickly recover data by deleting recycle bin files by mistake
Battle drag method 1: moderately optimistic, build self-confidence (1)
Based on laravel 5.5\5.6\5 X solution to the failure of installing laravel ide helper
AcWing 1460. Where am i?
2022 low voltage electrician examination and low voltage electrician simulation examination question bank
Instructions for common methods of regular expressions
Global and Chinese market of micro positioning technology 2022-2028: Research Report on technology, participants, trends, market size and share