Skip to content
TheChatArchiveThe Chat Archive
DeepSeekdeepseek-v3-0324· DeepSeekHugging Face LMArena Human Preference 140K

3d pose estimation, RGB-D 카메라 가지고 하려고 하는데, 전체 계획 설계 및 핵심 코드 수두 코드까지 짜줘

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with Coherecommand-a-03-2025’s answer.
  1. User

    3d pose estimation, RGB-D 카메라 가지고 하려고 하는데, 전체 계획 설계 및 핵심 코드 수두 코드까지 짜줘

  2. DeepSeek Assistant

    3D Pose Estimation with RGB-D Camera: 전체 계획 및 코드 구현

    전체 계획 설계

    1. 하드웨어 구성

      • RGB-D 카메라 (Kinect, RealSense 등) 설정
      • 컴퓨팅 장치 (PC 또는 임베디드 시스템) 연결
    2. 소프트웨어 스택

      • OpenCV, Open3D, PyTorch/TensorFlow 설치
      • 카메라 SDK 설치 (예: pyrealsense2, libfreenect2)
    3. 처리 파이프라인

      1. RGB-D 데이터 획득
      2. 전처리 (노이즈 제거, 정렬, 배경 제거)
      3. 인체 검출 (2D 또는 3D)
      4. 3D 포즈 추정
      5. 후처리 및 시각화
      
    4. 실행 옵션

      • 실시간 처리 vs 오프라인 처리
      • 정확도 vs 속도 트레이드오프

    핵심 코드 구현

    1. RGB-D 데이터 획득 (Intel RealSense 예제)

    import pyrealsense2 as rs
    import numpy as np
    import cv2
    
    # 파이프라인 설정
    pipeline = rs.pipeline()
    config = rs.config()
    config.enable_stream(rs.stream.color, 640, 480, rs.format.bgr8, 30)
    config.enable_stream(rs.stream.depth, 640, 480, rs.format.z16, 30)
    
    # 시작
    pipeline.start(config)
    
    try:
        while True:
            # 프레임 대기
            frames = pipeline.wait_for_frames()
            color_frame = frames.get_color_frame()
            depth_frame = frames.get_depth_frame()
            
            if not color_frame or not depth_frame:
                continue
                
            # 이미지 변환
            color_image = np.asanyarray(color_frame.get_data())
            depth_image = np.asanyarray(depth_frame.get_data())
            
            # 시각화
            depth_colormap = cv2.applyColorMap(
                cv2.convertScaleAbs(depth_image, alpha=0.03), 
                cv2.COLORMAP_JET
            )
            
            cv2.imshow('RGB', color_image)
            cv2.imshow('Depth', depth_colormap)
            
            if cv2.waitKey(1) & 0xFF == ord('q'):
                break
                
    finally:
        pipeline.stop()
        cv2.destroyAllWindows()
    

    2. 전처리 및 배경 제거

    def preprocess_data(color_img, depth_img, depth_scale=0.001):
        # 노이즈 제거
        depth_img = cv2.medianBlur(depth_img, 5)
        
        # 배경 제거 (예: 1.5m 이외는 제거)
        max_distance_mm = 1500
        mask = depth_img < (max_distance_mm / depth_scale)
        masked_color = cv2.bitwise_and(color_img, color_img, mask=mask.astype(np.uint8))
        
        return masked_color, depth_img
    

    3. 3D 포즈 추정 (MediaPipe + Open3D)

    import mediapipe as mp
    import open3d as o3d
    from mediapipe.tasks import python
    from mediapipe.tasks.python import vision
    
    def setup_pose_estimator():
        base_options = python.BaseOptions(model_asset_path='pose_landmarker_heavy.task')
        options = vision.PoseLandmarkerOptions(
            base_options=base_options,
            output_segmentation_masks=True,
            min_pose_detection_confidence=0.5,
            min_pose_presence_confidence=0.5,
            min_tracking_confidence=0.5
        )
        return vision.PoseLandmarker.create_from_options(options)
    
    def estimate_3d_pose(pose_landmarker, color_img, depth_img, intrinsics):
        # MediaPipe로 2D 포즈 추정
        mp_image = mp.Image(image_format=mp.ImageFormat.SRGB, data=color_img)
        detection_result = pose_landmarker.detect(mp_image)
        
        if not detection_result.pose_landmarks:
            return None
        
        # 3D 포즈 계산
        pose_3d = []
        for landmark_2d in detection_result.pose_landmarks[0]:
            # 2D 좌표에서 depth 값 가져오기
            x, y = int(landmark_2d.x * color_img.shape[1]), int(landmark_2d.y * color_img.shape[0])
            z = depth_img[y, x] if 0 <= y < depth_img.shape[0] and 0 <= x < depth_img.shape[1] else 0
            
            # 2D + depth -> 3D 변환
            fx, fy, cx, cy = intrinsics
            x_3d = (x - cx) * z / fx
            y_3d = (y - cy) * z / fy
            z_3d = z
            
            pose_3d.append([x_3d, y_3d, z_3d])
        
        return np.array(pose_3d)
    

    4. 시각화 (Open3D)

    def visualize_3d_pose(pose_3d):
        vis = o3d.visualization.Visualizer()
        vis.create_window()
        
        # 포즈 포인트 클라우드 생성
        pcd = o3d.geometry.PointCloud()
        pcd.points = o3d.utility.Vector3dVector(pose_3d)
        
        # 뼈대 연결선
        connections = [
            [0,1],[1,2],[2,3],[3,7],  # 얼굴
            [0,4],[4,5],[5,6],[6,8],   # 왼쪽 팔
            [0,9],[9,10],[10,11],[11,12],  # 오른쪽 팔
            [0,13],[13,14],[14,15],[15,16], # 왼쪽 다리
            [0,17],[17,18],[18,19],[19,20]  # 오른쪽 다리
        ]
        
        lineset = o3d.geometry.LineSet()
        lineset.points = pcd.points
        lineset.lines = o3d.utility.Vector2iVector(connections)
        
        # 시각화
        vis.add_geometry(pcd)
        vis.add_geometry(lineset)
        
        # 뷰 설정
        ctr = vis.get_view_control()
        ctr.set_front([0, -1, 0])
        ctr.set_up([0, 0, 1])
        
        vis.run()
        vis.destroy_window()
    

    5. 메인 실행 루프

    def main():
        # 카메라 초기화
        pipeline, config = initialize_camera()
        
        # 포즈 추정기 초기화
        pose_landmarker = setup_pose_estimator()
        
        # 카메라 내부 파라미터 (실제 값으로 교체 필요)
        intrinsics = [616.5, 616.5, 320.0, 240.0]  # fx, fy, cx, cy
        
        try:
            while True:
                # 데이터 획득
                color_img, depth_img = get_frames(pipeline)
                
                # 전처리
                color_img, depth_img = preprocess_data(color_img, depth_img)
                
                # 3D 포즈 추정
                pose_3d = estimate_3d_pose(pose_landmarker, color_img, depth_img, intrinsics)
                
                if pose_3d is not None:
                    # 2D 시각화
                    annotated_image = draw_2d_landmarks(color_img.copy(), pose_3d, intrinsics)
                    cv2.imshow('2D Pose', annotated_image)
                    
                    # 3D 시각화 (주기적으로 또는 키 입력 시)
                    if cv2.waitKey(1) & 0xFF == ord('v'):
                        visualize_3d_pose(pose_3d)
                
                if cv2.waitKey(1) & 0xFF == ord('q'):
                    break
                    
        finally:
            pipeline.stop()
            cv2.destroyAllWindows()
    
    if __name__ == "__main__":
        main()
    

    추가 고려 사항

    1. 성능 최적화

      • 다중 스레딩으로 센서 데이터 수집과 처리 분리
      • ONNX 런타임으로 모델 추론 속도 향상
      • GPU 가속 활용
    2. 정확도 향상

      • 시간적 일관성을 위한 필터링 (칼만 필터 등)
      • 다중 프레임 정보 융합
      • 포즈 후처리 (물리적 제약 조건 적용)
    3. 배포 옵션

      • ROS 패키지로 통합
      • 웹 인터페이스 구축
      • 모

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.