convert bitset descriptor -> cv::Mat

14738 ワード

リファレンスhttps://blog.csdn.net/magicyang87/article/details/7246771

1.bitset回転opencv cv::Mat


注意(1)Matの列は32列,タイプはuchar(2)BRIEF::bitsetの長さは256(3)8個ごとにucharを構成するこのテストok
vector<BRIEF::bitset> temp_brief_descriptors;
extractor(image, keypoints, temp_brief_descriptors);
brief_descriptors_mat=Mat::zeros(brief_descriptors.size(),32,CV_8UC1);
int row=0;
 for(iter = temp_brief_descriptors.begin(); iter!=temp_brief_descriptors.end();iter++)
 {
     BRIEF::bitset bits=*iter;
     for (int i = 0; i < 32; i += 8)
     {
         char ch;
         for (int j = 0; j < 8; ++j)
         {
             if (bits.test(i + j))	//  i + j 1
                 ch |= (1 << j);
             else
                 ch &= ~(1 << j);
         }
         brief_descriptors_mat.at<uchar>(row, i)=(uchar)ch;

     }
     row++;
 }
void convert_bitset_to_Mat(vector<BRIEF::bitset> temp_brief_descriptors,cv::Mat& out_brief_descriptors_mat)
{
    //2.convert bitset to Mat
    out_brief_descriptors_mat=cv::Mat::zeros(temp_brief_descriptors.size(),32,CV_8UC1);
    int row=0;
    for(vector<BRIEF::bitset> :: iterator iter = temp_brief_descriptors.begin(); iter!=temp_brief_descriptors.end();iter++)
    {
        BRIEF::bitset bits=*iter;

        for (int i = 0; i < 32; i++)
        {
            char ch=' ';
            int n_offset=i*8;
            for (int j = 0; j < 8; j++)
            {
                if (bits.test(n_offset + j))	//  i + j 1
                    ch |= (1 << j);
                else
                    ch &= ~(1 << j);
            }
            out_brief_descriptors_mat.at<uchar>(row, i)=(uchar)ch;
        }
        row++;
    }

}



2.opencv cv::Mat回転bitset


このコードテストに問題があります.原因が見つからない!
//1.convert Mat to bitset
    for(int i=0;i<brief_descriptors_mat.rows;i++)
    {
        BRIEF::bitset bits;
        bits.resize(256);
        bits.reset();
        for (int j = 0; j < 32; j ++)
        {
            char ch=(char) brief_descriptors_mat.at<uchar>(i, j);
            int n_offset = j * 8;
            for (int k = 0; k < 8; ++k)
            {
                bits.set(n_offset + k, ch & (1 << k));
            }
        }
        brief_descriptors.push_back(bits);
    }