Halcon - NCC 模型的仿射变换与使用图像金字塔的缩小图像匹配

Halcon - Affine transformation for NCC model matching with scale down image using image pyramid

您好,我有一个 NCC 模型匹配的仿射变换问题(NumLevel 4,因为我有一个大图像)。

我在缩小图像金字塔 (GenGaussPyramid) 中创建了一个 NCC 模型 然后在缩小图像中找到NCC模型。

有谁知道如何将找到的模型区域仿射转移回原始图像(NumLevel 1)?

我给你做了一个小演示。 核心是写反仿射变换的地方。

这里是代码

* test image with the pattern (circle)
gen_image_const (EmptyImage, 'byte', 640, 480)
OriginalRow :=240
OriginalColumn  := 400
OriginalRadius := 8
gen_circle (Circle, OriginalRow ,OriginalColumn, OriginalRadius)
gen_circle_contour_xld (CircleXLD, OriginalRow, OriginalColumn, OriginalRadius, 0, 6.28318, 'positive', 0.1)
paint_xld (CircleXLD, EmptyImage, OriginalTestImage, 255)

dev_display (OriginalTestImage)
dev_set_draw ('margin')
dev_set_color ('blue')
dev_display (CircleXLD)
stop()

* creation of pyramid image
Scale := 0.5
gen_gauss_pyramid (OriginalTestImage, ImagePyramid, 'weighted', Scale)

LevelIndex := 4
select_obj (ImagePyramid, Level, LevelIndex )

* ideal found circle
LevelScale := pow(Scale,LevelIndex-1)
hom_mat2d_identity (HomMat2DIdentity)
hom_mat2d_translate (HomMat2DIdentity, OriginalRow*LevelScale -OriginalRow, OriginalColumn*LevelScale - OriginalColumn, HomMat2DTranslate)
hom_mat2d_scale (HomMat2DTranslate, LevelScale, LevelScale, OriginalRow*LevelScale+0.5, OriginalColumn*LevelScale+0.5, HomMat2DScale)
affine_trans_contour_xld (CircleXLD, IdealFoundCircleXLD, HomMat2DScale)

* simulation of searching in the 4th level
threshold_sub_pix (Level, Border, 128)
area_center_xld (Border, Area, FoundRow, FoundColumn, _)
FoundRadius:= sqrt(Area/3.14)
gen_circle_contour_xld (FoundCircleXLD, FoundRow, FoundColumn, FoundRadius, 0, 6.28318, 'positive', 0.1)

dev_display (Level)
dev_set_draw ('margin')
dev_set_color ('green')
dev_display (IdealFoundCircleXLD)
dev_set_color ('red')
dev_display (FoundCircleXLD)
stop()

* reverse affine transformation
ReverseLevelScale := pow(1/Scale,LevelIndex-1)
hom_mat2d_identity (HomMat2DIdentity)
hom_mat2d_translate (HomMat2DIdentity, FoundRow*ReverseLevelScale -FoundRow, FoundColumn*ReverseLevelScale - FoundColumn, HomMat2DTranslate)
hom_mat2d_scale (HomMat2DTranslate, ReverseLevelScale, ReverseLevelScale, FoundRow*ReverseLevelScale+0.5, FoundColumn*ReverseLevelScale+0.5, HomMat2DScale)

affine_trans_contour_xld (IdealFoundCircleXLD, ReverseIdealFoundCircleXLD, HomMat2DScale)
affine_trans_contour_xld (FoundCircleXLD, ReverseFoundCircleXLD, HomMat2DScale)

dev_display (OriginalTestImage)
dev_set_draw ('margin')
dev_set_color ('blue')
dev_display (CircleXLD)
dev_set_color ('green')
dev_display (ReverseIdealFoundCircleXLD)
dev_set_color ('red')
dev_display (ReverseFoundCircleXLD)
stop()