ObjectDatasetTools代码链接: link.
该方法用于RGB-D 相机拍摄的对象序列创建目标的分割、边界框标签和 3D 重建对象网格 (.ply)。
安装:环境是Ubuntu16.04和python2.7
1.更新安装

sudo apt-get update
sudo apt-get upgrade

2.建议创建python2.7的conda虚拟环境,并安装如下包

sudo apt install build-essential cmake git pkg-config libssl-dev libgl1-mesa-glx
pip install numpy Cython==0.19 pypng scipy scikit-learn open3d==0.9.0 scikit-image tqdm pykdtree opencv-python==3.3.0.10 opencv-contrib-python==3.3.0.10  trimesh==2.38.24

3.我是用了Realsense D455深度相机进行rgb和深度图的收集,执行程序如下:

import pyrealsense2 as rs
import numpy as np
import cv2

# Configure depth and color streams
pipeline = rs.pipeline()
config = rs.config()
config.enable_stream(rs.stream.depth, 640, 480, rs.format.z16, 30)
config.enable_stream(rs.stream.color, 640, 480, rs.format.bgr8, 30)

# Start streaming
pipeline.start(config)
align_to = rs.stream.color
align = rs.align(align_to)

i = 0
try:
    while True:

        # Wait for a coherent pair of frames: depth and color
        frames = pipeline.wait_for_frames()
        depth_frame = frames.get_depth_frame()
        color_frame = frames.get_color_frame()
        if not depth_frame or not color_frame:
            continue

        # Convert images to numpy arrays
        depth_image = np.asanyarray(depth_frame.get_data())
        color_image = np.asanyarray(color_frame.get_data())

        cv2.imwrite(r'D:\PoseEstimationDatasets\shoe\depth\\'+str(i)+'.png', depth_image)
        cv2.imwrite(r'D:\PoseEstimationDatasets\shoe\color\\'+str(i)+'.jpg', color_image)
        i = i+1

        # Apply colormap on depth image (image must be converted to 8-bit per pixel first)
        depth_colormap = cv2.applyColorMap(cv2.convertScaleAbs(depth_image, alpha=0.03), cv2.COLORMAP_JET)

        # Stack both images horizontally
        images = np.hstack((color_image, depth_colormap))

        # Show images
        cv2.namedWindow('RealSense', cv2.WINDOW_AUTOSIZE)
        cv2.imshow('RealSense', images)

        key = cv2.waitKey(1)
        # Press esc or 'q' to close the image window
        if key & 0xFF == ord('q') or key == 27:
            cv2.destroyAllWindows()
            break


finally:

    # Stop streaming
    pipeline.stop()

将收集到的rgb图像和深度图像分别放入“JPEGImages”和“depth”文件夹下,通过以下程序获取相机参数并保存:

import pyrealsense2 as rs
import json

pipeline = rs.pipeline()

folder = r'E:\PoseEstimationDatasets\cup'
cfg = pipeline.start() # Start pipeline and get the configuration it found
profile = cfg.get_stream(rs.stream.depth) # Fetch stream profile for depth stream
intr = profile.as_video_stream_profile().get_intrinsics() # Downcast to video_stream_profile and fetch intrinsics
camera_parameters = {'fx': intr.fx, 'fy': intr.fy,
                     'ppx': intr.ppx, 'ppy': intr.ppy,
                     'height': intr.height, 'width': intr.width,
                     'depth_scale': cfg.get_device().first_depth_sensor().get_depth_scale()}

with open(folder + 'intrinsics.json', 'w') as fp:
    json.dump(camera_parameters, fp)

在项目根目录下,创建“LINEMOD”文件夹,将以上生成的内容放入该文件夹。
接下来,进入制作环节:
第一步,生成每个图像的位姿矩阵(N44)的npy文件

python compute_gt_poses.py LINEMOD/sugar

第二步,生成3D模型。有两个方法
第一个方法生成的ply文件需要用meshlab进行处理并生成非二进制文件才能用于后续制作。处理过程可参考该链接: link.

python register_scene.py LINEMOD/sugar

第二种方法可直接生成ply文件,但是效果一般都不太好,我自己的尝试过程中

python register_segmented.py LINEMOD/sugar

总之,我生成ply文件的过程中都不太好,像公开数据集中那样的模型都需要专业的3D重建软件来完成。
第三步,创建目标的分割图像和标签文件以及新的位姿文件,这一步创建出来的位姿数据是4*4的。

python create_label_files.py LINEMOD/sugar
Logo

瓜分20万奖金 获得内推名额 丰厚实物奖励 易参与易上手

更多推荐