Skip to content

Commit 7e55f89

Browse files
committed
added DOPE class and test script
1 parent 3b38586 commit 7e55f89

File tree

2 files changed

+10
-12
lines changed

2 files changed

+10
-12
lines changed

Diff for: robot_toolkit/robot_arm_algos/src/inference/dope.py

+7-10
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import numpy as np
33
import cv2
44
import tf.transformations
5-
# import resource_retriever
65
# from ..config_reader import read_yaml_file
76
from dope.inference.cuboid import Cuboid3d
87
from dope.inference.cuboid_pnp_solver import CuboidPNPSolver
@@ -15,7 +14,7 @@
1514
from visualization_msgs.msg import Marker, MarkerArray
1615
from geometry_msgs.msg import PoseStamped
1716
from ._object_pose_estimator import ObjectPoseEstimator
18-
17+
from ..logger import logger
1918
def rotate_vector(vector, quaternion):
2019
q_conj = tf.transformations.quaternion_conjugate(quaternion)
2120
vector = np.array(vector, dtype='float64')
@@ -35,7 +34,7 @@ def draw_estimated_frame(color_image, camera, rvec, tvec):
3534

3635
class DOPEPoseDetection(ObjectPoseEstimator):#(object)
3736
def __init__(self,
38-
# model_weights_path,
37+
model_weights_path,
3938
dope_config_pose_file,
4039
object_model_name = "soup",
4140
input_is_rectified = True,
@@ -72,9 +71,7 @@ def __init__(self,
7271
weights_url = self.config_dope_dict["weights"][model]
7372

7473
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)
7875
self.dnn_model.load_net_model()
7976
try:
8077
M = np.array(self.config_dope_dict["model_transform"][model], dtype='float64')
@@ -102,7 +99,7 @@ def __init__(self,
10299
self.pnp_solver = CuboidPNPSolver(model,
103100
cuboid3d=Cuboid3d(self.config_dope_dict["dimensions"][model]))
104101

105-
def estimate_pose(self, camera):
102+
def estimate_pose(self, camera, save_image_file_path=None):
106103
rgb_image = camera.get_current_rgb_frame()
107104
camera_matrix = camera.camera_matrix
108105
dist_coeffs = camera.dist_coeffs
@@ -150,13 +147,13 @@ def estimate_pose(self, camera):
150147
pose_msg.pose.orientation.w = transformed_ori[3]
151148

152149
# 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:
154151
points2d = []
155152
for pair in result['projected_points']:
156153
points2d.append(tuple(pair))
157154
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)
160157

161158
class Draw(object):
162159
"""Drawing helper class to visualize the neural network output"""

Diff for: robot_toolkit/test_dope.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55

66
def main():
77
rs_camera = RealSenseCamera()
8-
dope_obj = DOPE(dope_config_pose_file = "config/dope_config_pose.yaml" )
8+
dope_obj = DOPE(dope_config_pose_file = "config/dope_config_pose.yaml",
9+
model_weights_path = "/root/git/dope/weights/soup_60.pth")
910
plt.imshow(rs_camera.get_current_rgb_frame())
1011
plt.show(block=False)
1112
plt.pause(4.0)
1213
plt.close()
13-
dope_obj.estimate_pose(rs_camera)
14+
dope_obj.estimate_pose(rs_camera, save_image_file_path = "/root/git/scratchpad/test.jpg")
1415

1516
if __name__ == "__main__":
1617
main()

0 commit comments

Comments
 (0)