* This program demonstrates the effect of using the
* generic parameter 'recompute_score' of the operator
* find_shape_model_3d.
*
* By setting 'recompute_score' to 'true', the score
* is recomputed after the pose refinement, which
* may lead to slightly different (but more consistent)
* score values at the cost of a slightly larger
* execution time.
*
* For this, a 3D shape model of a cube is searched in
* a sequence of artificially created images by using
* find_shape_model_3d. The images are created by
* changing the longitude of the camera in the object
* centered spherical coordinate system.
*
* The matching is performed twice. In the first run,
* 'recompute_score' is set to 'false', while in the
* second run, 'recompute_score' is set to 'true'. The
* score is stored for each of the two runs over all
* images. Finally, the score values are plotted with
* respect to the camera longitude.
*
* Note that the variation of the score values is
* significantly higher when setting 'recompute_score'
* to 'false'. Also note that in real images typically
* the variation of the score is lower.
*
gen_cam_par_area_scan_division (0.01, 0, 7e-6, 7e-6, 320, 240, 640, 480, CamParam)
get_cam_par_data (CamParam, 'image_width', Width)
get_cam_par_data (CamParam, 'image_height', Height)
dev_close_window ()
dev_open_window (0, 0, Width, Height, 'black', WindowHandle)
dev_set_part (0, 0, Height - 1, Width - 1)
set_display_font (WindowHandle, 14, 'mono', 'true', 'false')
dev_update_off ()
*
* Generate a cube
X := [-1,-1,1,1,-1,-1,1,1]
Y := [1,-1,-1,1,1,-1,-1,1]
Z := [-1,-1,-1,-1,1,1,1,1]
Polygons := [4,0,1,2,3,4,4,5,6,7,4,0,1,5,4,4,3,2,6,7,4,0,3,7,4,4,1,2,6,5]
gen_object_model_3d_from_points (X, Y, Z, ObjectModel3DID)
set_object_model_3d_attrib_mod (ObjectModel3DID, 'polygons', [], Polygons)
*
* Prepare the 3D object model for matching
prepare_object_model_3d (ObjectModel3DID, 'shape_based_matching_3d', 'true', [], [])
*
* Display the 3D object model
disp_object_model_3d_safe (WindowHandle, ObjectModel3DID, CamParam, [0,0,11,30,40,0,0], [], [])
disp_message (WindowHandle, '3D Object Model of a Cube', 'window', 12, 12, 'black', 'true')
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
*
*
* Generate the 3D shape model
create_cube_shape_model_3d (WindowHandle, ObjectModel3DID, CamParam, ShapeModel3DID)
clear_object_model_3d (ObjectModel3DID)
*
Scores1 := []
Scores2 := []
Times1 := []
Times2 := []
Longitudes := []
Latitude := rad(45)
Distance := 11.5
dev_set_color ('green')
dev_set_line_width (2)
for Longitude := rad(30) to rad(60) by rad(0.25)
convert_point_3d_spher_to_cart (Longitude, Latitude, Distance, '-y', '-z', CamX, CamY, CamZ)
create_cam_pose_look_at_point (CamX, CamY, CamZ, 0, 0, 0, '-y', 0, CamPose)
* Prevent flickering
set_system ('flush_graphic', 'false')
*
* Generate an artificial image of the cube
project_cube_image (Image, CamPose, CamParam, X, Y, Z, Polygons)
*
* Find the cube by using 3D shape-based matching
* ('recompute_score' = 'false')
count_seconds (Seconds1)
find_shape_model_3d (Image, ShapeModel3DID, 0.7, 0.9, 0, [], [], Pose1, CovPose1, Score1)
count_seconds (Seconds2)
Time1 := (Seconds2 - Seconds1) * 1000.0
* Find the cube by using 3D shape-based matching
* ('recompute_score' = 'true')
count_seconds (Seconds1)
find_shape_model_3d (Image, ShapeModel3DID, 0.7, 0.9, 0, 'recompute_score', 'true', Pose2, CovPose2, Score2)
count_seconds (Seconds2)
Time2 := (Seconds2 - Seconds1) * 1000.0
*
* Display the matching result
dev_display (Image)
if (|Score1| == 1 and |Score2| == 1)
* Display the match
project_shape_model_3d (ModelContours, ShapeModel3DID, CamParam, Pose1, 'true', rad(30))
dev_display (ModelContours)
* Display the matching time and score
disp_message (WindowHandle, 'Matching at Longitude: ' + deg(Longitude)$'3.1f' + ' deg (from 30 to 60 deg)', 'window', 12, 12, 'white', 'false')
gen_matching_result_message (Time1, Time2, Score1, Score2, Message)
disp_message (WindowHandle, Message, 'window', 420, 12, ['white','yellow','green'], 'false')
* Remember the score values
Longitudes := [Longitudes,deg(Longitude)]
Scores1 := [Scores1,Score1]
Scores2 := [Scores2,Score2]
Times1 := [Times1,Time1]
Times2 := [Times2,Time2]
endif
* Prevent flickering
set_system ('flush_graphic', 'true')
* Show what we painted in the loop by drawing a invisible line
disp_line (WindowHandle, -1, -1, -1, -1)
endfor
*
* Display the score values
dev_clear_window ()
Title := ['\'recompute_score\'=\'false\'','\'recompute_score\'=\'true\'']
Colors := ['yellow','green']
plot_tuple (WindowHandle, Longitudes, [Scores1,Scores2], 'Longitude [deg]', 'Matching score', Colors, ['ticks_x','ticks_y','end_y'], [6,.01,1])
disp_message (WindowHandle, Title, 'window', 12, 350, Colors, 'false')
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
dev_clear_window ()
plot_tuple (WindowHandle, Longitudes, [Times1,Times2], 'Longitude [deg]', 'Matching time [ms]', Colors, 'ticks_x', 6)
disp_message (WindowHandle, Title, 'window', 12, 350, Colors, 'false')
*
* Clear the 3D shape model
clear_shape_model_3d (ShapeModel3DID)