[英]How to get ORB descriptors out of openCV as efficent as possible?
我想将openCV计算的ORB描述符存储到std::bitset<256>
。
由于每帧/图像有几个描述符,我想每帧使用std::vector<std::bitset<256>>
。
由于视频中有多个帧,因此结尾使用结构std::vector<std::vector<std::bitset<256>>>
。
由于openCV将解析器存储到cv::Mat
,我正在质疑自己如何尽可能快速/高效地获取描述符? 所以我四处寻找并找到了一个不使用像SHIFT
或AND
这样的逻辑运算符的答案 。 有没有更快的方法?
也许有一个更好的结构基于std
作为std::vector<std::vector<std::bitset<256>>>
来加速它?
这是一段简短的代码,可以更轻松地理解问题。
#include <iostream>
#include <vector>
#include <bitset>
#include <opencv2/opencv.hpp>
int main(int argc, char ** argv)
{
// opencv
cv::Mat color, gray, descs;
std::vector<cv::KeyPoint> kpts;
cv::Ptr<cv::ORB> detector = cv::ORB::create();
cv::VideoCapture video(argv[1]);
// my desired datastruct
using my_desc_t = std::bitset<256>; // one descriptor
using my_frame_t = std::vector<my_desc_t>; // one frame
using my_video_t = std::vector<my_frame_t>; // one video
my_video_t my_video;
my_video.resize(video.get(CV_CAP_PROP_FRAME_COUNT));
// processing
for (size_t i=0,j=video.get(CV_CAP_PROP_FRAME_COUNT); i!=j; ++i)
{
if (video.read(color))
{
// detect and compute
cv::cvtColor(color,gray,CV_BGR2GRAY);
detector->detectAndCompute(gray,cv::Mat(),kpts,descs);
// fill
// TODO
// 8 (uchar) * 32 = 256 bits each orb descriptor.
// how to use logical operators to copy it
// as fast as possible into my_video?
}
}
}
我用clang++ -std=c++11 experiment.cpp -o experiment -lopencv_core -lopencv_imgproc -lopencv_videoio -lopencv_features2d
编译它clang++ -std=c++11 experiment.cpp -o experiment -lopencv_core -lopencv_imgproc -lopencv_videoio -lopencv_features2d
这是答案
// bitset to Mat:
std::bitset<256> bs(11); // some demo value
Mat m(1,32,CV_8U, reinterpret_cast<uchar*>(&bs)); // 32 bytes
cerr << bs << endl;
cerr << m << endl;
// Mat to bitset
std::bitset<256> bs2;
memcpy(&bs2, m.data, 32);
cerr << bs2 << endl;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.