当前位置:网站首页>Halcon principle: correlation matching
Halcon principle: correlation matching
2022-06-23 11:59:00 【Mr anhydrous】
One 、 The basic principle
NCC It is an algorithm based on statistics to calculate the correlation between two groups of samples , Its value range is 【-1,1】 Between , And for images , Each pixel is viewed as RGB Vector , The whole image is a sample set . If it has a subset , Match with another sample data , Then it's NCC The value is 1; It means that the correlation is very high , If it is -1, The table is completely irrelevant ; Based on this principle, template matching and recognition are realized , The first step is to normalize the data , The mathematical formula :

among ,f Express p Point gray value ,
Represents the average value of pixels in the window ,
Represents the standard deviation .
If t Represents the template pixel value , be :

among n Is the total number of template pixels ,n-1 It's the degree of freedom .
Two 、 Implementation method
1) Get the average value of template pixels 、 Standard deviation 、 Pixel and mean fiff Data samples .
2) According to the template size , On the target image , From top to bottom 、 Pan the template from left to right , Calculate every pixel moved , Template and image area NCC value , And record it at the center point . After completion , Of each point NCC Compare with the threshold , Beyond the threshold is the matching result .
3) Mark the matching position with a rectangular box .
4) Use UI Output .
3、 ... and 、Halcon Of NCC matching
Halcon Of ncc Templates use , This is done by two functions :create_ncc_model and find_ncc_model Cooperate to complete . Below we have prepared a picture , To explain this matching
3.1 create_ncc_model and find_ncc_model function
The function prototype :
- create_ncc_model(Template : : NumLevels, AngleStart, AngleExtent, AngleStep, Metric : ModelID)
Template: Image of the template , It can be a rectangle , It can also be a circle .
NumLevels: Is the hierarchy of templates , If one layer , Just use “auto”
AngleStart, AngleExtent, AngleStep: These three represent the rotation of the angle template , Starting angle 、 Termination angle 、 Rotation step .
Metric: Matching criteria
ModelID: Template label
- find_ncc_model(Image : : ModelID, AngleStart, AngleExtent, MinScore, NumMatches, MaxOverlap, SubPixel, NumLevels : Row, Column, Angle, Score)
Image: The detected image
ModelID: Template number
AngleStart, AngleExtent: angle
MinScore: Match points
NumMatches: matching , Number of templates hit
MaxOverlap,
SubPixel:
NumLevels: Number of formwork layers
Row, Column, Angle, Score: Return value , Hit rows 、 Column 、 angle 、 The score is .
Four 、 Case study
1 Open a grayscale image file :
read_image (Image, 'F:/images/hugeImg/gtexst.jpg')
get_image_size (Image, Width, Height)
dev_close_window ()
dev_open_window (0, 0, Width, Height, 'black', WindowHandle)
dev_update_window ('off')

2 Generate template
gen_circle (Circle, 210,692, 41)
area_center (Circle, Area, RowRef, ColumnRef)
reduce_domain (Image, Circle, ImageReduced1)
disp_image(ImageReduced1,WindowHandle)
gen_circle (Circle, 701,854, 59)
area_center (Circle, Area, RowRef, ColumnRef)
reduce_domain (Image, Circle, ImageReduced2)
disp_image(ImageReduced2,WindowHandle)
Generate two circular templates
create_ncc_model (ImageReduced1 , 5, 0, 10, 'auto', 'use_polarity', ModelID1)
get_ncc_model_params( ModelID1 ,NumLevels, AngleStart, AngleExtent, AngleStep, Metric)
create_ncc_model (ImageReduced2 , 5, 0, 10, 'auto', 'use_polarity', ModelID2)
get_ncc_model_params( ModelID2 ,NumLevels, AngleStart, AngleExtent, AngleStep, Metric)
3 Template matching
find_ncc_model (Image, ModelID1, 0, 10, 0.5, 1, 0.5, 'true', 0, Row1, Column1, Angle, Score1)
find_ncc_model (Image, ModelID2, 0, 10, 0.5, 1, 0.5, 'true', 0, Row2, Column2, Angle, Score2)
4 Mark the matching area
dev_set_draw ('margin')
dev_set_colored (12)
dev_set_line_width (3)
dev_display (Image)
gen_rectangle1(Rectangle1, Row1-41, Column1-41, Row1+41, Column1+41)
gen_rectangle1(Rectangle2, Row2-59, Column2-59, Row2+59, Column2+59)
dev_set_window(WindowHandle)
dev_display(Rectangle1)
dev_display(Rectangle2)
5、 ... and 、 Enumeration of related functions
5.1 Possible antecedents :
draw_region
reduce_domain
threshold
5.2 Possible post items :
find_ncc_model
get_ncc_model_params
clear_ncc_model
write_ncc_model
set_ncc_model_origin
set_ncc_model_param
5.3 Possible alternatives :
create_shape_model
create_scaled_shape_model
create_aniso_shape_model
create_template_rot
边栏推荐
- WC statistics are out of date, and every line of cloc code is valid
- Redis 入门-第四篇-数据结构与对象-跳跃表
- @Dark horse fans, haven't you received this "high temperature subsidy"?
- Leetcode 1209. Delete all adjacent duplicates II in the string
- [cloud based co creation] overview of the IOT of Huawei cloud HCIA IOT v2.5 training series
- 【云驻共创】无码时代,软件开发如何走向每个人?
- DuPont analysis: what is the investment value of Anyang Iron and Steel Co., Ltd?
- 全国进入主汛期,交通运输部:不具备安全运行条件的线路坚决停运!
- Halcon原理:auto_threshold算子
- 2022施工员-装饰方向-岗位技能(施工员)操作证考试题库模拟考试平台操作
猜你喜欢
随机推荐
汉源高科新一代绿色节能以太网接入工业交换机高效节能型千兆工业以太网交换机
10-- 根据中序遍历和后序遍历,构造二叉树
MySQL在一个字段中匹配多个值
想学习eTS开发?教你开发一款IQ-EQ测试应用
Open classes are short videos! Tonight, I will teach you how to realize accurately!
LinkedList 5-141. 环形链表
Mobile securities account opening transaction? Is it safe to open an account online now?
[cloud based co creation] overview of the IOT of Huawei cloud HCIA IOT v2.5 training series
Design of routing service for multi Activity Architecture Design
I am in Foshan. Where can I open an account? Is it safe to open a mobile account?
Halcon原理:auto_threshold算子
【云驻共创】华为云HCIA-IoT V2.5培训系列内容之物联网概览
ESP32-C3入门教程 问题篇⑦—— fatal error: esp_bt.h: No such file or directory 找不到esp_bt.h
基本数据类型和对应的包装类
@黑马粉丝,这份「高温补贴」你还没领?
Does the inductance have polarity?
【无标题】2022年压力管道巡检维护试题及在线模拟考试
ROS2知识(2):网络设施
Getting started with redis - Chapter 2 - data structures and objects - linked lists
32路电话+2路千兆以太网32路PCM电话光端机支持FXO口FXS语音电话转光纤








![[processes and threads]](/img/6b/ff1076a3809ecc412f2bf6517c278e.png)
