【问题标题】:Parsing the LINEMOD 6d Pose estimation Dataset解析 LINEMOD 6d 姿态估计数据集
【发布时间】:2017-09-28 19:14:42
【问题描述】:

我正在尝试使用广泛引用的 LINEMOD 论文中用于 6D 姿势估计的数据集。 他们的数据集在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;
}

感谢您对此的帮助!

【问题讨论】:

    标签: python c++ opencv graphics computer-vision


    【解决方案1】:

    经过反复试验,下面的 sn-p 似乎可以正常工作。希望这对我的问题的其他人有用。

    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])
    

    【讨论】:

    • 赞成:很高兴您能够回答自己的问题并试图帮助他人。
    猜你喜欢
    • 1970-01-01
    • 2015-09-09
    • 2022-01-12
    • 2011-10-30
    • 1970-01-01
    • 2020-10-31
    • 2018-07-25
    • 2023-03-29
    • 1970-01-01
    相关资源
    最近更新 更多