簡體   English   中英

OpenCV ORB GPU實施比CPU慢

[英]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

  • 16 GB RAM

其他功能檢測/描述算法(例如SURF)在我的計算機上使用GPU實施時性能更快。

有人在他的機器上比較過ORB的兩種實現嗎?

取自這篇文章

cv::ORB在計算描述符之前應用GaussianBlur(從orb.cpp末尾大約20行)。 沒有辦法通過公共接口來控制它。

cv::gpu::ORB_GPU具有公共成員bool blurForDescriptor ,默認情況下其構造為false 當我將其設置為true時,我發現最小/平均/最大漢明距離降至0 / 7.2 / 30位,這似乎更加合理。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM