Halcon Knowledge: Rectangle Measurement

Publisher:数据舞者Latest update time:2023-04-23 Source: 机器人及PLC自动化应用Author: Lemontree Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

First, let's ask a question: How do you get the measurement of a rectangle in the picture below, that is, do you need more accurate rectangle position parameters? The general method provided by halcon is to first frame the rectangle, and then use the measurement object to measure accurately. Therefore, the approximate center point, length, width, and direction angle of the rectangle should be basically given, see

First, give the code, and then explain the meaning of the code one by one:

re_image (Image, 'rect2')

rgb1_to_gray(Image,Image)

create_metrology_model (MetrologyHandle)

get_image_size (Image, Width, Height)

set_metrology_model_image_size (MetrologyHandle, Width, Height)

add_metrology_object_rectangle2_measure (MetrologyHandle, 172.3, 239.2, rad(11.609), 146.7, 50.9, 30, 12, 1, 30, [], [], Index)

apply_metrology_model (Image, MetrologyHandle)

get_metrology_object_result (MetrologyHandle, Index, 'all', 'result_type', 'all_pa', Rectangle)

get_metrology_object_result_contour (Contour, MetrologyHandle, Index, 'all', 1.5)

clear_metrology_model (MetrologyHandle)

1) create_metrology_model (MetrologyHandle)

This statement defines a measurement container that can hold many different measurement objects. In this example, there is only one measurement object.

2) set_metrology_model_image_size (MetrologyHandle, Width, Height)

Define the measurement range for which the measurement container is intended, in this case the entire image.

3) add_metrology_object_rectangle2_measure( : : MetrologyHandle, Row, Column, Phi, Length1, Length2, *Define the outer containing rectangle MeasureLength1,MeasureLength2, *Define the measurement object

MeasureSigma, MeasureThreshold, GenParamName, GenParamValue: Index) *Defines the grayscale of the image being tested

To understand this statement, we must first understand the relationship between [the object to be inspected, the rectangular range box, and the object]. As shown in the following figure:

The corresponding parameters of [detected object, rectangular range frame, and detection object] are defined as follows:

* The geometry of a rectangular object is specified by its center (Row, Column), the direction of the principal axis φ, and the half-side lengths Length1 and Length2.

* Input values ​​for Phi are automatically mapped to intervals.

* The rectangular measurement area is perpendicular to the border of the area rectangle. The half-side lengths of the measurement area perpendicular and tangent to the rectangular border are set in "Length1" and "Length2".

* The center of the measurement area lies on the border of the rectangle. The parameter MeasureSigma specifies a standard deviation that the operator uses to apply a metrological model to smooth the grayscale values ​​of the image.

* You can select salient edges using the parameter MeasureThreshold, which constitutes an amplitude threshold, i.e. the absolute value of the first-order derivative of the edge.

Additionally, some common parameters can be adjusted in GenParamName and GenParamValue. In particular, all common parameters available in the operation set_metrology_object_param can be set. Note, however, that for many applications the default values ​​are sufficient and no adjustments are necessary.

The operator add_metrology_object_rectangle2_measure returns the Index index of the metrology object added to the metrology model in the parameter Index.

4)get_metrology_object_result( : : MetrologyHandle, Index, Instance, GenParamName, GenParamValue : Parameter)

Get the measurement results.

get_metrology_object_result allows access to the measurement results of a measurement measurement object MetrologyHandle obtained with apply_metrology_model. The parameter Index specifies the metrology object for which the result is queried (there are multiple metrology objects in MetrologyHandle). For Index set to "all", results for all metrology objects are returned. With the parameter Instance you can specify for which measurement instance the results are returned in the parameter. Setting the instance Instance to "all" will return results for all instances. Different generic parameters can be used to control the return value in the Parameter. The generic parameter name is passed as GenParamName. The corresponding value is passed as GenParamValue. The following parameters and values ​​are possible:

5)get_metrology_object_result_contour( : Contour : MetrologyHandle, Index, Instance, Resoluon : )

Get the measurement result, which is the contour line of the above measurement.

The final contour result is as follows:

If you still don't understand the principle, please refer to the following article, which continues to discuss this issue. You can also refer to the online article: Measurement Function

Measurement Problems

The contour line obtained above is not the measurement result. How to further solve the measurement problem? Because there are many situations, it is impossible to list them one by one. Here we only measure the rectangle mentioned in the case.

Method 1: Use fit_rectangle2_contour_xld to extract a rectangle from the contour line, based on the length and width that satisfy the measurement.

Method 2: Use gen_parallel_contour_xld(contour, parallelcontour, 'regression_normal', -Distance) to directly get the distance of parallel lines (one for length and one for width)

Reviewing Editor: Li Qian

Reference address:Halcon Knowledge: Rectangle Measurement

Previous article:Analysis of the servo motor structure of industrial robots
Next article:How to connect to different configurations of frame grabbers and cameras

Latest robot Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号