mirror of https://github.com/opencv/opencv.git
Open Source Computer Vision Library
https://opencv.org/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
86 lines
2.0 KiB
86 lines
2.0 KiB
#include <iostream> |
|
|
|
#include "opencv2/opencv_modules.hpp" |
|
|
|
#if defined(HAVE_OPENCV_GPUCODEC) |
|
|
|
#include <string> |
|
#include <vector> |
|
#include <algorithm> |
|
#include <numeric> |
|
|
|
#include <opencv2/core.hpp> |
|
#include <opencv2/core/opengl.hpp> |
|
#include <opencv2/gpucodec.hpp> |
|
#include <opencv2/highgui.hpp> |
|
#include <opencv2/contrib.hpp> |
|
|
|
int main(int argc, const char* argv[]) |
|
{ |
|
if (argc != 2) |
|
return -1; |
|
|
|
const std::string fname(argv[1]); |
|
|
|
cv::namedWindow("CPU", cv::WINDOW_NORMAL); |
|
cv::namedWindow("GPU", cv::WINDOW_OPENGL); |
|
cv::gpu::setGlDevice(); |
|
|
|
cv::Mat frame; |
|
cv::VideoCapture reader(fname); |
|
|
|
cv::gpu::GpuMat d_frame; |
|
cv::gpu::VideoReader_GPU d_reader(fname); |
|
d_reader.dumpFormat(std::cout); |
|
|
|
cv::TickMeter tm; |
|
std::vector<double> cpu_times; |
|
std::vector<double> gpu_times; |
|
|
|
for (;;) |
|
{ |
|
tm.reset(); tm.start(); |
|
if (!reader.read(frame)) |
|
break; |
|
tm.stop(); |
|
cpu_times.push_back(tm.getTimeMilli()); |
|
|
|
tm.reset(); tm.start(); |
|
if (!d_reader.read(d_frame)) |
|
break; |
|
tm.stop(); |
|
gpu_times.push_back(tm.getTimeMilli()); |
|
|
|
cv::imshow("CPU", frame); |
|
cv::imshow("GPU", d_frame); |
|
|
|
if (cv::waitKey(3) > 0) |
|
break; |
|
} |
|
|
|
if (!cpu_times.empty() && !gpu_times.empty()) |
|
{ |
|
std::cout << std::endl << "Results:" << std::endl; |
|
|
|
std::sort(cpu_times.begin(), cpu_times.end()); |
|
std::sort(gpu_times.begin(), gpu_times.end()); |
|
|
|
double cpu_avg = std::accumulate(cpu_times.begin(), cpu_times.end(), 0.0) / cpu_times.size(); |
|
double gpu_avg = std::accumulate(gpu_times.begin(), gpu_times.end(), 0.0) / gpu_times.size(); |
|
|
|
std::cout << "CPU : Avg : " << cpu_avg << " ms FPS : " << 1000.0 / cpu_avg << std::endl; |
|
std::cout << "GPU : Avg : " << gpu_avg << " ms FPS : " << 1000.0 / gpu_avg << std::endl; |
|
} |
|
|
|
return 0; |
|
} |
|
|
|
#else |
|
|
|
int main() |
|
{ |
|
std::cout << "OpenCV was built without GPU Video decoding support\n" << std::endl; |
|
return 0; |
|
} |
|
|
|
#endif
|
|
|