halcon - Halcon - NCC 模型的仿射变换与使用图像金字塔的缩小图像匹配
问题描述
嗨,我有一个 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()
推荐阅读
- matlab - MATLAB coder app 2011版和2021版如何打开(MATLAB online)?
- linux - 如何确保 ffmpeg 库使用/不使用 GPU
- python - while 循环没有根据条件集正确运行
- c++ - createdefaultsubobject 函数不适用于 UWidgetComponent[UE4.26.2]
- sql - 如何减去多个日期?
- laravel - 我想获得下一个将被创建但尚未在 laravel 中创建的 id
- java - 如何将不同类别的面板放在框架上而不丢弃框架
- python - 有人可以帮我格式化函数的输出吗?
- networking - 我们可以使用一些工具将cisco命令发送到多个IP地址吗?
- python - 重新排序热图中的变量并仅使用高度相关的变量重新设计热图