python - 解析 LINEMOD 6d 姿态估计数据集

标签 python c++ opencv graphics computer-vision

我正在尝试使用广泛引用的用于 6D 姿态估计的 LINEMOD 论文中的数据集。 他们的数据集可在 http://campar.in.tum.de/Main/StefanHinterstoisser 获取。

它们的深度数据似乎是一次性格式,需要特殊函数才能加载。我需要编写一个 C++ 程序来包装依赖于 OpenCV 的提供函数,并找出从对象中提取数字并导出的最佳方法。对于整天使用 Python 和其他高级语言的人来说,这很困难/费力。我想知道是否有其他人已经完成了将深度数字转换为更通用或 python 友好格式的工作?我环顾四周,但一无所获。

此外,C++ 程序很简短,但对于我未经训练的眼睛来说却含糊不清。我怀疑精通 C++/opencv 和 Python 的人可以查看源代码和一个优雅的程序来在 python 中进行类似的文件读取?为了方便起见,我将其内容粘贴在下面。

http://campar.in.tum.de/personal/hinterst/index/downloads!09384230443!/loadDepth.txt

IplImage * loadDepth( std::string a_name )
{
    std::ifstream l_file(a_name.c_str(),std::ofstream::in|std::ofstream::binary );

    if( l_file.fail() == true ) 
    {
        printf("cv_load_depth: could not open file for writing!\n");
        return NULL; 
    }
    int l_row;
    int l_col;

    l_file.read((char*)&l_row,sizeof(l_row));
    l_file.read((char*)&l_col,sizeof(l_col));

    IplImage * lp_image = cvCreateImage(cvSize(l_col,l_row),IPL_DEPTH_16U,1);

    for(int l_r=0;l_r<l_row;++l_r)
    {
        for(int l_c=0;l_c<l_col;++l_c)
        {
            l_file.read((char*)&CV_IMAGE_ELEM(lp_image,unsigned short,l_r,l_c),sizeof(unsigned short));
        }
    }
    l_file.close();

    return lp_image;
}

感谢您对此的帮助!

最佳答案

经过一些尝试和错误,下面的代码片段似乎可以工作。希望这对其他提出我的问题的人有用。

import struct
cpp_int_size = 4
cpp_ushort_size = 2
with open('ape/data/depth811.dpt', 'rb') as f:
    rows_b = f.read(cpp_int_size) # I assume that the C++ int in question has 4 bytes ... trial and error
    cols_b = f.read(cpp_int_size)

    R = struct.unpack('<i', rows_b)[0] # small endian
    C = struct.unpack('<i', cols_b)[0]
    depth_image_str = f.read(R * C * cpp_ushort_size)
depth_img = np.fromstring(depth_image_str, dtype=np.uint16).reshape([R, C])

关于python - 解析 LINEMOD 6d 姿态估计数据集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46476689/

相关文章:

python - Matplotlib 和 OpenCV 导致崩溃

python - Holoviews 表不直观地保留索引

c++ - Xerces C++ XML : escape is really hard to do?

c++ - 不同大小的着色器存储缓冲区内容 "transfered"到数组缓冲区

python - Raspberry Pi cv2.VideoCapture 卡在第二次初始化时具有相同的 ID

optimization - 在嵌入式平台中充分利用 GPU

python - 在python中提取特定的netcdf信息并转换为GeoTIFF

python - Nose 测试用例上的装饰器产生

Python 在字典值中追加字典

c++ - 在 C++ 中使用另一个项目中的类