在一系列图像中搜索局部可变形模型
CSDN 2024-08-16 12:07:03 阅读 66
dev_update_off ()
read_image (ModelImage, ‘food/cocoa_package_model’)
dev_close_window ()
dev_open_window_fit_image (ModelImage, 0, 0, -1, -1, WindowHandle)
set_display_font (WindowHandle, 16, ‘mono’, ‘true’, ‘false’)
*
Create and display the local deformable model
create_local_deformable_model (ModelImage, ‘auto’, rad(-15), rad(30), ‘auto’, 1, 1, ‘auto’, 1, 1, ‘auto’, ‘none’, ‘use_polarity’, [40,60], ‘auto’, [], [], ModelID)
get_deformable_model_contours (ModelContours, ModelID, 1)
area_center (ModelImage, Area, Row, Column)
hom_mat2d_identity (HomMat2DIdentity)
hom_mat2d_translate (HomMat2DIdentity, Row, Column, HomMat2DTranslate)
affine_trans_contour_xld (ModelContours, ContoursAffinTrans, HomMat2DTranslate)
dev_set_line_width (2)
dev_set_color (‘yellow’)
dev_display (ModelImage)
dev_display (ContoursAffinTrans)
disp_message (WindowHandle, ‘Model image and contours’, ‘window’, 12, 12, ‘black’, ‘true’)
disp_continue_message (WindowHandle, ‘black’, ‘true’)
stop ()
Smoothness := 19
NumImages := 13
for Index := 1 to NumImages by 1
read_image (Image, ‘food/cocoa_packages_’ + Index
′
0
2
′
)
d
e
v
r
e
s
i
z
e
w
i
n
d
o
w
f
i
t
i
m
a
g
e
(
I
m
a
g
e
,
0
,
0
,
−
1
,
−
1
)
d
e
v
d
i
s
p
l
a
y
(
I
m
a
g
e
)
d
i
s
p
m
e
s
s
a
g
e
(
W
i
n
d
o
w
H
a
n
d
l
e
,
′
S
e
a
r
c
h
.
.
.
′
,
′
w
i
n
d
o
w
′
,
12
,
12
,
′
b
l
a
c
k
′
,
′
t
r
u
e
′
)
c
o
u
n
t
s
e
c
o
n
d
s
(
S
1
)
∗
F
i
n
d
t
h
e
m
o
d
e
l
i
n
t
h
e
d
e
f
o
r
m
e
d
s
e
a
r
c
h
i
m
a
g
e
.
∗
A
s
r
e
s
u
l
t
,
t
h
e
r
e
c
t
i
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
p
l
a
y
(
W
a
r
p
e
d
M
e
s
h
)
F
o
u
n
d
[
I
n
d
e
x
]
:
=
∣
S
c
o
r
e
∣
d
e
v
s
e
t
l
i
n
e
w
i
d
t
h
(
2
)
d
e
v
s
e
t
c
o
l
o
r
(
′
g
r
e
e
n
′
)
d
e
v
d
i
s
p
l
a
y
(
D
e
f
o
r
m
e
d
C
o
n
t
o
u
r
s
)
d
i
s
p
m
e
s
s
a
g
e
(
W
i
n
d
o
w
H
a
n
d
l
e
,
∣
S
c
o
r
e
∣
+
′
m
a
t
c
h
e
s
f
o
u
n
d
i
n
′
+
T
i
m
e
'02') dev_resize_window_fit_image (Image, 0, 0, -1, -1) dev_display (Image) disp_message (WindowHandle, 'Search ...', 'window', 12, 12, 'black', 'true') count_seconds (S1) * Find the model in the deformed search image. * As result, the rectified image, the respective * vector field, and the found contours are queried. find_local_deformable_model (Image, ImageRectified, VectorField, DeformedContours, ModelID, rad(-14), rad(28), 1, 1, 1, 1, 0.78, 0, 0, 0, 0.45, ['image_rectified','vector_field','deformed_contours'], ['deformation_smoothness','expand_border','subpixel'], [Smoothness,0,0], Score, Row, Column) count_seconds (S2) Time := S2 - S1 * Visualize the deformation as a mesh generated from * the returned vector field gen_warped_mesh (VectorField, WarpedMesh, Smoothness / 2) dev_set_line_width (1) dev_set_color ('yellow') dev_display (WarpedMesh) Found[Index] := |Score| dev_set_line_width (2) dev_set_color ('green') dev_display (DeformedContours) disp_message (WindowHandle, |Score| + ' matches found in ' + Time
′02′)devresizewindowfitimage(Image,0,0,−1,−1)devdisplay(Image)dispmessage(WindowHandle,′Search...′,′window′,12,12,′black′,′true′)countseconds(S1)∗Findthemodelinthedeformedsearchimage.∗Asresult,therectifiedimage,therespective∗vectorfield,andthefoundcontoursarequeried.findlocaldeformablemodel(Image,ImageRectified,VectorField,DeformedContours,ModelID,rad(−14),rad(28),1,1,1,1,0.78,0,0,0,0.45,[′imagerectified′,′vectorfield′,′deformedcontours′],[′deformationsmoothness′,′expandborder′,′subpixel′],[Smoothness,0,0],Score,Row,Column)countseconds(S2)Time:=S2−S1∗Visualizethedeformationasameshgeneratedfrom∗thereturnedvectorfieldgenwarpedmesh(VectorField,WarpedMesh,Smoothness/2)devsetlinewidth(1)devsetcolor(′yellow′)devdisplay(WarpedMesh)Found[Index]:=∣Score∣devsetlinewidth(2)devsetcolor(′green′)devdisplay(DeformedContours)dispmessage(WindowHandle,∣Score∣+′matchesfoundin′+Time’1.2f’ + ’ s’, ‘window’, 12, 12, ‘black’, ‘true’)
for J := 0 to |Score| - 1 by 1
disp_message (WindowHandle, ‘Score: ’ + Score[J]$’.2f’, ‘image’, 350, Column[J] - 80, ‘black’, ‘true’)
endfor
if (Index < NumImages)
disp_continue_message (WindowHandle, ‘black’, ‘true’)
stop ()
endif
endfor
*
Clean up
clear_deformable_model (ModelID)
如下是model:
如下是采样图片
以下是程序运行结果:
以下是代码的逐行解释:
dev_update_off():关闭设备更新,以提高处理速度。
read_image (ModelImage, ‘food/cocoa_package_model’):读取模型图像。
dev_close_window ():关闭当前窗口。
dev_open_window_fit_image (ModelImage, , , -1, -1, WindowHandle):打开一个窗口,窗口大小自动调整以适应图像。
set_display_font (WindowHandle, 16, ‘mono’, ‘true’, ‘false’):设置窗口的显示字体。
创建并显示局部可变形模型:
create_local_deformable_model:创建一个局部可变形模型。
get_deformable_model_contours:获取模型的轮廓。
area_center:获取图像的中心点。
hom_mat2d_identity 和 hom_mat2d_translate:创建一个平移矩阵,将模型轮廓平移到图像中心。
affine_trans_contour_xld:使用平移矩阵变换模型轮廓。
dev_set_line_width (2):设置线条宽度为2。
dev_set_color (‘yellow’):设置线条颜色为黄色。
dev_display (ModelImage):显示模型图像。
dev_display (ContoursAffinTrans):显示变换后的模型轮廓。
disp_message:在窗口中显示消息。
disp_continue_message:在窗口中持续显示消息。
stop ():暂停执行。
循环搜索图像:
read_image:读取要搜索的图像。
dev_resize_window_fit_image:调整窗口大小以适应图像。
dev_display:显示图像。
disp_message:显示搜索消息。
count_seconds:计算搜索开始时间。
find_local_deformable_model:在图像中搜索局部可变形模型。
count_seconds:计算搜索结束时间。
Time := S2 - S1:计算搜索时间。
gen_warped_mesh:生成变形网格。
dev_display:显示变形网格。
Found[Index] := |Score|:记录搜索得分。
disp_message:显示搜索结果。
if (Index < NumImages):如果还有图像未搜索,显示继续消息并暂停。
clear_deformable_model (ModelID):清除局部可变形模型。
这个脚本的主要功能是创建一个局部可变形模型,并在一系列图像中搜索这个模型,然后显示搜索结果和搜索时间。
声明
本文内容仅代表作者观点,或转载于其他网站,本站不以此文作为商业用途
如有涉及侵权,请联系本站进行删除
转载本站原创文章,请注明来源及作者。