前提
python3.8
ubuntu20.04をしようしています
実現したいこと
yolo関数に変数color_imageとdepth_imageを渡したいと考えています。
ですが、下記のコードではcolor_imageやdepth_imageが定義されていないためエラーがでてしまいます。
そこで、クラスの外にcolor_image = None,depth_image = Noneと書くと
'NoneType' object has no attribute 'shape'となってしまいます。
この場合、どのように渡せばよいのでしょうか。
申し訳ございませんがご教示お願いいたします。
該当のソースコード
class Yolo: def __init__(self): rospy.init_node('yolo', anonymous=True) self.bridge = CvBridge() sub_rgb = message_filters.Subscriber("/camera/color/image_raw",Image) sub_depth = message_filters.Subscriber("/camera/depth/image_rect_raw",Image) self.mf = message_filters.ApproximateTimeSynchronizer([sub_rgb, sub_depth], 100, 0.5) self.mf.registerCallback(self.ImageCallback) def ImageCallback(self, rgb_data , depth_data): global color_image,depth_image try: cv_color_image = self.bridge.imgmsg_to_cv2(rgb_data, 'rgb8') color_image = np.array(cv_color_image) cv_depth_image = self.bridge.imgmsg_to_cv2(depth_data, '32FC1') depth_image = np.array(cv_depth_image) print(depth_image[int((640+0)/2)][int((480+0)/2)]) except CvBridgeError as e: rospy.logerr(e) def yolo(self,color_image,depth_image): try: while not rospy.is_shutdown(): img, orig_im, dim = self.prep_image(color_image, inp_dim) im_dim = torch.FloatTensor(dim).repeat(1,2) if CUDA: im_dim = im_dim.cuda() img = img.cuda() output = model(Variable(img), CUDA) output = write_results(output, confidence, num_classes, nms = True, nms_conf = nms_thesh) output[:,1:5] = torch.clamp(output[:,1:5], 0.0, float(inp_dim))/inp_dim im_dim = im_dim.repeat(output.size(0), 1) output[:,[1,3]] *= self.color_image.shape[1] output[:,[2,4]] *= self.color_image.shape[0] list(map(lambda x: self.write(x, orig_im,depth_image,color_image), output)) if __name__ == '__main__': try: Y = Yolo() Y.yolo(color_image,depth_image) rospy.spin() except rospy.ROSInterruptException: pass
試したこと
ここに問題に対して試したことを記載してください。
補足情報(FW/ツールのバージョンなど)
ここにより詳細な情報を記載してください。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。