关于opencv video_reader.cpp的使用说明
2014-05-09 14:52
483 查看
How to solve OpenCV Error "function not implemented (called functionality is disabled for current build or platform) when using VideoWriter_GPU?
如果要使用这个sample 需要用CMAKE开启 with OPENGL 以及 with NVCUVIDCMAKE的过程可以参考/article/8326101.html这篇博文
#include <iostream> #include <string> #include <vector> #include <algorithm> #include <numeric> #include <opencv2/core/core.hpp> #include <opencv2/core/opengl_interop.hpp> #include <opencv2/gpu/gpu.hpp> #include <opencv2/highgui/highgui.hpp> #include <opencv2/contrib/contrib.hpp> using namespace cv; using namespace gpu; #include<iostream> using namespace std; int _tmain(int argc, _TCHAR* argv[]) { std::string fname="1.avi"; string mm= cv::getBuildInformation(); cout<<mm<<endl; cv::namedWindow("CPU", cv::WINDOW_NORMAL); cv::namedWindow("GPU", cv::WINDOW_OPENGL); 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; } cvDestroyAllWindows(); system("pause"); return 0; }
相关文章推荐
- OpenCV gpu模块样例注释:video_reader.cpp
- 关于Android XMPP使用简单说明
- Python中关于导入(import)语句的使用说明
- 关于国外主机服务的.htaccess使用说明
- 关于使用fetchAll()的一点说明
- 关于OpenLayers.ProxyHost参数的使用说明
- 关于Apache (httpd)服务器防DDOS模块mod_evasive的使用说明
- C语言中关于带密钥的md5算法库md5lib.h的使用说明
- 关于使用 FLAG_HOMEKEY_DISPATCHED 标志在应用层截获 HOME 按键的说明
- 关于JSON.parse()方法的使用说明
- 关于DITTO的使用说明
- 关于OPenCv的安装与配置问题说明
- Apidemo 中关于如何使用ScrollView说明
- 关于oracle函数listagg的使用说明
- 关于easyeclipse for php的使用说明介绍
- 关于SafeArray的使用说明
- 关于Android使用新浪API的一些说明
- 关于最近很火的“快用苹果助手”和“pp助手”使用正版软件闪退问题的说明
- 七牛---关于刷新接口的具体使用说明
- 关于opencv 图像掩膜操作srcImage.copyto(dstImage, mask)说明