2
2
import numpy as np
3
3
import cv2
4
4
import tf .transformations
5
- # import resource_retriever
6
5
# from ..config_reader import read_yaml_file
7
6
from dope .inference .cuboid import Cuboid3d
8
7
from dope .inference .cuboid_pnp_solver import CuboidPNPSolver
15
14
from visualization_msgs .msg import Marker , MarkerArray
16
15
from geometry_msgs .msg import PoseStamped
17
16
from ._object_pose_estimator import ObjectPoseEstimator
18
-
17
+ from .. logger import logger
19
18
def rotate_vector (vector , quaternion ):
20
19
q_conj = tf .transformations .quaternion_conjugate (quaternion )
21
20
vector = np .array (vector , dtype = 'float64' )
@@ -35,7 +34,7 @@ def draw_estimated_frame(color_image, camera, rvec, tvec):
35
34
36
35
class DOPEPoseDetection (ObjectPoseEstimator ):#(object)
37
36
def __init__ (self ,
38
- # model_weights_path,
37
+ model_weights_path ,
39
38
dope_config_pose_file ,
40
39
object_model_name = "soup" ,
41
40
input_is_rectified = True ,
@@ -72,9 +71,7 @@ def __init__(self,
72
71
weights_url = self .config_dope_dict ["weights" ][model ]
73
72
74
73
self .dnn_model = ModelData (model ,
75
- "/root/git/dope/weights/soup_60.pth" )
76
- #resource_retriever.get_filename(weights_url,
77
- # use_protocol=False))
74
+ model_weights_path )
78
75
self .dnn_model .load_net_model ()
79
76
try :
80
77
M = np .array (self .config_dope_dict ["model_transform" ][model ], dtype = 'float64' )
@@ -102,7 +99,7 @@ def __init__(self,
102
99
self .pnp_solver = CuboidPNPSolver (model ,
103
100
cuboid3d = Cuboid3d (self .config_dope_dict ["dimensions" ][model ]))
104
101
105
- def estimate_pose (self , camera ):
102
+ def estimate_pose (self , camera , save_image_file_path = None ):
106
103
rgb_image = camera .get_current_rgb_frame ()
107
104
camera_matrix = camera .camera_matrix
108
105
dist_coeffs = camera .dist_coeffs
@@ -150,13 +147,13 @@ def estimate_pose(self, camera):
150
147
pose_msg .pose .orientation .w = transformed_ori [3 ]
151
148
152
149
# Draw the cube
153
- if None not in result ['projected_points' ]:
150
+ if None not in result ['projected_points' ] and save_image_file_path is not None :
154
151
points2d = []
155
152
for pair in result ['projected_points' ]:
156
153
points2d .append (tuple (pair ))
157
154
draw .draw_cube (points2d , self .draw_colors )
158
- im . show ( )
159
- im .save ("/root/git/scratchpad/test.png" )
155
+ logger . info ( "Image saved at " + save_image_file_path )
156
+ im .save (save_image_file_path )
160
157
161
158
class Draw (object ):
162
159
"""Drawing helper class to visualize the neural network output"""
0 commit comments