2017-12-11 91 views
0

Kinect v1을 사용하고 있는데 ROS의 "/ camera/depth_registered/image"에서 그레이 스케일 모드로 심도 이미지를 얻고 싶습니다. here을 발견 했으므로 imgmsg_to_cv2 함수를 사용하여이 작업을 수행 할 수 있습니다. 내 깊이 메시지의 기본 desired_encoding은 "32FC1"입니다. 문제는 그것을 보여주기 위해 cv2.imshow() 함수를 사용할 때 바이너리 이미지를 얻는다는 것입니다 ... RGB 이미지에 대해 동일한 작업을 수행하면 모든 것이 잘 보입니다 ...imgmsg_to_cv2를 사용하여 ROS에서 그레이 스케일로 깊이 이미지 가져 오기 [python]

Any 도움을 주셨습니다!

+0

적어도 C++ 버전에서 OpenCV는 '32FC1'이미지를 표시하는 데별로 좋지 않습니다. 적절한 범위 (0 ~ 255)로 스케일링하여 표시 목적으로 '8UC1'로 변환하십시오. – mikkola

+0

[여기] (https://answers.ros.org/question/58902/how-to-store-the-depth-data-from-kinectcameradepth_registreredimage_raw-as-gray-scale) 지침에 따라 (일종의) 작업을 수행했습니다. -영상/). 문제는 그 결과가 ROS의 ** image_view ** 패키지에서 ** image_view ** 노드로 얻은 이미지와 비교할 때 꽤 잡음이라는 것입니다. – lefos99

답변

0
그래서 결국, 나는 당신이 여기에서 볼 수있는 솔루션, 발견

:

def Depthcallback(self,msg_depth): # TODO still too noisy! 
try: 
    # The depth image is a single-channel float32 image 
    # the values is the distance in mm in z axis 
    cv_image = self.bridge.imgmsg_to_cv2(msg_depth, "32FC1") 
    # Convert the depth image to a Numpy array since most cv2 functions 
    # require Numpy arrays. 
    cv_image_array = np.array(cv_image, dtype = np.dtype('f8')) 
    # Normalize the depth image to fall between 0 (black) and 1 (white) 
    # http://docs.ros.org/electric/api/rosbag_video/html/bag__to__video_8cpp_source.html lines 95-125 
    cv_image_norm = cv2.normalize(cv_image_array, cv_image_array, 0, 1, cv2.NORM_MINMAX) 
    # Resize to the desired size 
    cv_image_resized = cv2.resize(cv_image_norm, self.desired_shape, interpolation = cv2.INTER_CUBIC) 
    self.depthimg = cv_image_resized 
    cv2.imshow("Image from my node", self.depthimg) 
    cv2.waitKey(1) 
except CvBridgeError as e: 
    print(e) 

그러나, 결과는 내가 ROS의 image_view 노드에서 얻을 것과 같은 완벽한 아니지만, 그것을 여전히 꽤 받아 들일 수 있습니다!