[英]OpenCV ORB GPU implementation slower than CPU
我正在尝试对视频帧运行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 <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;
}
在具有3000帧和720x480分辨率的视频上运行此视频后,GPU时间为54秒,CPU时间为24秒。 我在其他视频(非高清)上也得到了类似的结果。 PC规格:
i7-4770K CPU 3.50 GHz
NVIDIA GeForce GTX 650
其他功能检测/描述算法(例如SURF)在我的计算机上使用GPU实施时性能更快。
有人在他的机器上比较过ORB的两种实现吗?
取自这篇文章 :
cv::ORB
在计算描述符之前应用GaussianBlur(从orb.cpp末尾大约20行)。 没有办法通过公共接口来控制它。
cv::gpu::ORB_GPU
具有公共成员boolblurForDescriptor
,默认情况下其构造为false
。 当我将其设置为true时,我发现最小/平均/最大汉明距离降至0 / 7.2 / 30位,这似乎更加合理。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.