Skip to content

Instantly share code, notes, and snippets.

@atinfinity
Last active July 17, 2017 17:25
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save atinfinity/fd82f794ebf736a2e2e3 to your computer and use it in GitHub Desktop.
Save atinfinity/fd82f794ebf736a2e2e3 to your computer and use it in GitHub Desktop.
UMatサンプルプログラム
#include <opencv2/core.hpp>
#include <opencv2/core/ocl.hpp>
#include <opencv2/core/cuda.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/contrib.hpp>
#include <iostream>
#define USE_OPENCL
int main(int argc, const char* argv[])
{
if(argc != 2)
{
std::cerr << "Usage : UMatVideoSample <input video file>" << std::endl;
return -1;
}
cv::VideoCapture reader(argv[1]);
if(!reader.isOpened())
{
std::cerr << "Can't open input video file" << std::endl;
return -1;
}
cv::UMat frame;
cv::UMat gray;
cv::UMat blur;
cv::UMat edge;
cv::TickMeter tm;
#ifdef USE_OPENCL
cv::ocl::setUseOpenCL(true);
#else
cv::ocl::setUseOpenCL(false);
#endif
for(int i = 1;; ++i)
{
reader >> frame;
if(frame.empty())
{
std::cout << "Stop" << std::endl;
break;
}
tm.reset();
tm.start();
cv::cvtColor(frame, gray, cv::COLOR_BGR2GRAY);
cv::GaussianBlur(gray, blur, cv::Size(1,1), 1.5, 1.5);
cv::Canny(blur, edge, 0, 30, 3);
tm.stop();
std::cout << "[" << i << "] " << tm.getTimeMilli() << "(ms)" << std::endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment