新手求助!! 有关3D_matching_clamps
halcon吧
全部回复
仅看楼主
level 1
DerPrinze 楼主
我想以螺母为目标,在图片中找到螺母,并对位姿进行定位
因为是初学者,所以对halcon自带的示例程序3D_matching_clamps 进行了简单的修改,仅仅替换了程序中的模型路径和图片路径,其余的没变
运行后,三维模型打开正常,但是进行到图片匹配的时候,左上角显示发现目标为0, 其次在图像变量栏中 model contour 变量也是:未定义
恳请大神指点,问题出在哪里? 我需要做哪些修改?
(程序 在图片后面)
程序:
ReCreateShapeModel3D := false
*ReCreateShapeModel3D := true
*
* Set the camera parameters (can be obtained by using calibrate_cameras)
CamParam := [0.01221,-2791,7.3958e-6,7.4e-6,308.21,245.92,640,480]
*
get_camera_type_and_parameter_positions (CamParam, CameraType, LenCP, PosF, PosDistortion, PosTilt, PosRot, PosSx, PosSy, PosCx, PosCy, PosWidth, PosHeight, PosVx, PosVy, PosVz)
Width := CamParam[PosWidth]
Height := CamParam[PosHeight]
dev_close_window ()
dev_open_window (0, 0, Width, Height, 'black', WindowHandle)
set_display_font (WindowHandle, 14, 'mono', 'true', 'false')
dev_update_off ()
*
* Read the object model from a DXF file
read_object_model_3d ('C:/Users/aa/Desktop/nut_6x9.stl', 'mm', [], [], ObjectModel3DID, DxfStatus)
* Prepare the object model for the use within the 3d shape-based matching
prepare_object_model_3d (ObjectModel3DID, 'shape_based_matching_3d', 'true', [], [])
*
* Read some example images that can be passed to inspect_object_model_3d
gen_empty_obj (Images)
for Index := 1 to 7 by 1
read_image (Image, 'C:/Users/aa/Desktop/' + Index$'02')
concat_obj (Images, Image, Images)
endfor
*
* Inspect the 3D object model and specify the desired pose range
* in which the 3D shape model is to be created
inspect_object_model_3d (Images, ObjectModel3DID, CamParam, RefRotX, RefRotY, RefRotZ, LongitudeMin, LongitudeMax, LatitudeMin, LatitudeMax, CamRollMin, CamRollMax, DistMin, DistMax, MinFaceAngle)
*
dev_clear_window ()
if (ReCreateShapeModel3D)
* If desired re-create the 3D shape model. Note that this may take
* several minutes dependent on the hardware and the pose range.
Message := 'Creating the 3D shape model (may take several minutes) ...'
disp_message (WindowHandle, Message, 'window', 12, 12, 'black', 'true')
create_shape_model_3d (ObjectModel3DID, CamParam, RefRotX, RefRotY, RefRotZ, 'gba', LongitudeMin, LongitudeMax, LatitudeMin, LatitudeMax, 0, rad(360), DistMin, DistMax, 10, 'min_face_angle', MinFaceAngle, ShapeModel3DID)
write_shape_model_3d (ShapeModel3DID, 'clamp_sloped_user.sm3')
else
* If desired read the 3D shape model from disk
Message := 'Reading the 3D shape model file from disk ...'
disp_message (WindowHandle, Message, 'window', 12, 12, 'black', 'true')
dev_set_check ('~give_error')
dev_error_var (ErrorVar, 1)
read_shape_model_3d ('C:/Users/aa/Desktop/clamp_sloped_user.sm3', ShapeModel3DID)
Error := ErrorVar
dev_set_check ('give_error')
if (Error != H_MSG_TRUE)
* Create the 3D shape model if it is not available on disk
Message := 'Reading the 3D shape model file from disk ... not found!'
Message[1] := 'Creating the 3D shape model (may take several minutes) ...'
disp_message (WindowHandle, Message, 'window', 12, 12, 'black', 'true')
create_shape_model_3d (ObjectModel3DID, CamParam, rad(180), 0, rad(90), 'gba', -rad(35), rad(35), -rad(35), rad(35), 0, rad(360), 0.2, 0.25, 10, [], [], ShapeModel3DID)
write_shape_model_3d (ShapeModel3DID, 'clamp_sloped_35.sm3')
endif
* Uncomment the following line of code if the user-generated
* model is to be used
* read_shape_model_3d ('clamp_sloped_user.sm3', ShapeModel3DID)
endif
*
* After creating the 3D shape model we do not longer need
* the 3D object model.
clear_object_model_3d (ObjectModel3DID)
*
dev_set_line_width (2)
*
* Find instances of a 3D shape model in some run-time images
for ImageNo := 1 to 7 by 1
read_image (Image, 'C:/Users/aa/Desktop/' + ImageNo$'02')
dev_display (Image)
count_seconds (Seconds1)
* Find up to two instances of the 3D shape model
find_shape_model_3d (Image, ShapeModel3DID, 0.7, 0.9, 5, ['num_matches','pose_refinement'], [2,'least_squares_very_high'], Pose, CovPose, Score)
count_seconds (Seconds2)
Time := Seconds2 - Seconds1
Message := |Score| + ' Match(es) found in ' + Time$'4.3f' + ' s'
disp_message (WindowHandle, Message, 'window', 12, 12, 'black', 'true')
Time := Seconds2 - Seconds1
for I := 0 to |Score| - 1 by 1
PoseI := Pose[I * 7:I * 7 + 6]
CovPoseI := CovPose[I * 6:I * 6 + 5]
ScoreI := Score
* Visualize the found matches in the image by
* - projecting the 3D shape model with the pose of the match
project_shape_model_3d (ModelContours, ShapeModel3DID, CamParam, PoseI, 'true', 0.523599)
dev_set_color ('blue')
dev_display (ModelContours)
* - projecting the coordinate system of the 3D object model
dev_set_color ('coral')
disp_3d_coord_system (WindowHandle, CamParam, PoseI, 0.015)
* Display the parameters of the found pose
dev_set_color ('magenta')
display_match_pose (ShapeModel3DID, PoseI, WindowHandle)
endfor
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
endfor
*
Message := 'Program terminated. Press \'Run\' to clear the 3D shape model.'
disp_message (WindowHandle, Message, 'window', Height - 30, 12, 'black', 'true')
*
stop ()
* Free the 3D shape model if it is not longer needed
clear_shape_model_3d (ShapeModel3DID)
dev_update_on ()
2018年05月08日 06点05分 1
level 1
问题解决了吗?我也是把DXF文件改为STL的来做,但是create_shape_model_3d 的时候总是wrong value of control parameter 14
2018年05月31日 14点05分 2
1