【问题标题】:Halcon - Affine transformation for NCC model matching with scale down image using image pyramidHalcon - NCC 模型的仿射变换与使用图像金字塔的缩小图像匹配
【发布时间】:2020-12-17 12:27:39
【问题描述】:

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

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

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

【问题讨论】:

  • 您好,图片有多大?你试过 Halcon XL 吗?它可以处理大于 32768 x 32768 的图像
  • 是的,我正在使用 HalconXL。问题是创建和搜索模型需要很长时间。
  • 假设您为函数 gen_gauss_pyramid 使用 scale =0.5。原始图像 640 x 480 到第 4 级是 80 x 60 像素。如果您在 80 x 60 的图像中找到对象,并且您犯了 1 个像素的位置误差,然后您直接进入原始图像,您会发现该对象的位置误差为 8 个像素。
  • 搜索算法在处理金字塔图像时将对象搜索到第 4 层,当找到它时,它将在第 3 层中搜索在第 4 层中找到的附近位置。之后,当它会在第 3 层找到对象时,它会在第 2 层中搜索在第 3 层找到的附近位置。这直到第 1 级。因此它将搜索对象 4 次(在级别 1 到 3 中,它将搜索具有缩减域的对象)。在这种情况下,误差将非常低。那么,您确定要从第 4 级直接转到第 1 级吗?
  • 我完全理解你的意思。我必须跳过不同级别的自动搜索算法。原因是 ROI/reduce domain 对于教学和搜索来说仍然太大。这需要很长时间。所以我所做的就是教和搜索都跳到按比例缩小的图像中,以加快教和搜索。

标签: halcon


【解决方案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()

【讨论】:

    猜你喜欢
    • 2011-10-04
    • 1970-01-01
    • 2016-11-05
    • 1970-01-01
    • 1970-01-01
    • 2016-08-20
    • 1970-01-01
    • 1970-01-01
    • 2016-11-26
    相关资源
    最近更新 更多