C++ OpenCV ORB GPU实现比CPU慢
我试图对视频帧运行ORB OpenCV算法,我注意到CPU版本的执行速度比GPU版本快得多。代码如下:C++ OpenCV ORB GPU实现比CPU慢,c++,opencv,gpu,orb,C++,Opencv,Gpu,Orb,我试图对视频帧运行ORB OpenCV算法,我注意到CPU版本的执行速度比GPU版本快得多。代码如下: #include <iostream> #include "opencv2/core/core.hpp" #include "opencv2/features2d/features2d.hpp" #include "opencv2/highgui/highgui.hpp" #include "opencv2/gpu/gpu.hpp" #include <fstream>
#include <iostream>
#include "opencv2/core/core.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/gpu/gpu.hpp"
#include <fstream>
#include <sstream>
#include <math.h>
#include <omp.h>
#include <algorithm>
#include <vector>
#include <string>
using namespace cv;
using namespace std;
using namespace cv::gpu;
void process_cpu(string vid, int start_frame, int end_frame)
{
VideoCapture myCapture(vid);
Mat frame, gray_frame;
ORB myOrb(400);
Mat descriptors;
vector<KeyPoint> keypoints;
myCapture.set(CV_CAP_PROP_POS_FRAMES, start_frame);
for (int i=0; i<end_frame-start_frame; i++) {
myCapture.read(frame);
cvtColor(frame, gray_frame, CV_RGB2GRAY);
myOrb(gray_frame, Mat(), keypoints, descriptors);
}
myCapture.release();
}
void process_gpu(string vid, int start_frame, int end_frame)
{
VideoCapture myCapture(vid);
Mat frame, gray_frame;
GpuMat gpu_frame;
ORB_GPU myOrb(400);
GpuMat keypoints, descriptors;
myCapture.set(CV_CAP_PROP_POS_FRAMES, start_frame);
for (int i=0; i<end_frame-start_frame; i++) {
myCapture.read(frame);
cvtColor(frame, gray_frame, CV_RGB2GRAY);
gpu_frame.upload(gray_frame);
myOrb.blurForDescriptor = true;
myOrb(gpu_frame, GpuMat(), keypoints, descriptors);
}
myCapture.release();
}
int main (int argc, char* argv[])
{
int n = 4;
VideoCapture myCapture(argv[1]);
double frameNumber = myCapture.get(CV_CAP_PROP_FRAME_COUNT);
myCapture.release();
double TimeStart = 0;
double TotalTime = 0;
TimeStart = (double)getTickCount();
process_gpu(argv[1], 0, frameNumber);
TotalTime = (double)getTickCount() - TimeStart;
TotalTime = TotalTime / getTickFrequency();
cout << "Gpu Time : " << TotalTime << endl;
TimeStart = (double)getTickCount();
process_cpu(argv[1], 0, frameNumber);
TotalTime = (double)getTickCount() - TimeStart;
TotalTime = TotalTime / getTickFrequency();
cout << "Cpu Time : " << TotalTime << endl;
return -1;
}
#包括
#包括“opencv2/core/core.hpp”
#包括“opencv2/features2d/features2d.hpp”
#包括“opencv2/highgui/highgui.hpp”
#包括“opencv2/gpu/gpu.hpp”
#包括
#包括
#包括
#包括
#包括
#包括
#包括
使用名称空间cv;
使用名称空间std;
使用名称空间cv::gpu;
无效进程\u cpu(字符串视频、整数开始\u帧、整数结束\u帧)
{
视频捕获myCapture(vid);
垫框、灰框;
myOrb(400);
Mat描述符;
矢量关键点;
myCapture.set(CV\u CAP\u PROP\u POS\u FRAMES,start\u FRAMES);
对于(int i=0;i取自:
cv::ORB
应用高斯模糊(距离
在计算描述符之前。没有办法控制它
通过公共接口
cv::gpu::ORB\gpu
有一个公共成员boolblurForDescriptor
,它
默认情况下,构造为false
发现最小/平均/最大汉明距离下降到0/7.2/30位,这
看起来更合理