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


边栏推荐
- Basic command of IP address configuration ---ip V4
- Fingerprint password lock based on Hal Library
- Camera calibration (I): robot hand eye calibration
- Ruby replaces gem Alibaba image
- 2.6 formula calculation
- Qtablewidget control of QT
- JVM JNI and PVM pybind11 mass data transmission and optimization
- Thread, thread stack, method stack, the difference of creating thread
- Implementation of stack
- 11-grom-v2-05-initialization
猜你喜欢

Q&A:Transformer, Bert, ELMO, GPT, VIT

Example of peanut shell inner net penetration

thrift go

2022 low voltage electrician examination and low voltage electrician simulation examination question bank

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

Task of gradle learning

AcWing 1460. Where am i?

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

强基计划 数学相关书籍 推荐

2.1 use of variables
随机推荐
JVM JNI and PVM pybind11 mass data transmission and optimization
How to modify the network IP addresses of mobile phones and computers?
[effective Objective-C] - block and grand central distribution
Nacos usage of micro services
[Yu Yue education] basic reference materials of manufacturing technology of Shanghai Jiaotong University
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
1.5 learn to find mistakes first
Global and Chinese market of micro positioning technology 2022-2028: Research Report on technology, participants, trends, market size and share
Initialization and instantiation
19、 MySQL -- SQL statements and queries
1.4 learn more about functions
Test panghu was teaching you how to use the technical code to flirt with girls online on Valentine's Day 520
Get log4net log file in C - get log4net log file in C
Global and Chinese markets for medical temperature sensors 2022-2028: Research Report on technology, participants, trends, market size and share
Use nodejs+express+mongodb to complete the data persistence project (with modified source code)
An old programmer gave it to college students
2.3 other data types
Pat grade B 1009 is ironic (20 points)
Pytorch sets the weight and bias of the model to zero
2022 safety officer-c certificate examination and safety officer-c certificate registration examination