opencv中ocl的使用
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
// ocl_stereo_match.cpp : 定义控制台应用程序的入口点。//
#include "stdafx.h"
#include
#include
#include
#include
#include
#include "opencv2/ocl/ocl.hpp"
#include "opencv2/highgui/highgui.hpp"
#pragma comment(lib,"opencv_core2410d.lib")
#pragma comment(lib,"opencv_highgui2410d.lib")
#pragma comment(lib,"opencv_ocl2410d.lib")
#pragma comment(lib,"opencv_imgproc2410d.lib")
using namespace cv;
using namespace std;
using namespace ocl;
struct App
{
App(CommandLineParser&cmd);
void run();
voidhandleKey(char key);
voidprintParams() const;
voidworkBegin()
{
work_begin = getTickCount();
}
voidworkEnd()
{
int64 d = getTickCount() - work_begin;
double f = getTickFrequency();
work_fps = f / d;
}
stringmethod_str() const
{
switch (method)
{
case BM:
return "BM";
case BP:
return "BP";
case CSBP:
return "CSBP";
}
return "";
}
string text() const
{
stringstreamss;
ss<< "(" < < returnss.str(); } private: bool running, write_once; Mat left_src, right_src; Mat left, right; oclMatd_left, d_right; StereoBM_OCLbm; StereoBeliefPropagationbp; StereoConstantSpaceBPcsbp; int64 work_begin; doublework_fps; stringl_img, r_img; stringout_img; enum {BM, BP, CSBP} method; intndisp; // Max disparity + 1 enum {GPU, CPU} type; }; int main(intargc, char** argv) { const char* keys = "{ h | help | false | print help message }" "{ l | left | | specify left image }" "{ r | right | | specify right image }" "{ m | method | BM | specify match method(BM/BP/CSBP) }" "{ n | ndisp | 64 | specify number of disparity levels }" "{ o | output | stereo_match_output.jpg | specify output path when input is images}"; CommandLineParsercmd(argc, argv, keys); if (cmd.get { cout<< "Available options:" < cmd.printParams(); return 0; } try { App app(cmd); cout<< "Device name:" << cv::ocl::Context::getContext()->getDeviceInfo().deviceName< app.run(); getchar(); } catch (const exception& e) { cout<< "error: " < } return EXIT_SUCCESS; } App::App(CommandLineParser&cmd) : running(false),method(BM) { cout<< "stereo_match_ocl sample\n"; cout<< "\nControls:\n" << "\tesc - exit\n" << "\to - save output image once\n" << "\tp - print current parameters\n" << "\tg - convert source images into gray\n" << "\tm - change stereo match method\n" << "\ts - change Sobel prefiltering flag (for BM only)\n" << "\t1/q - increase/decrease maximum disparity\n" << "\t2/w - increase/decrease window size (for BM only)\n" << "\t3/e - increase/decrease iteration count (for BP and CSBP only)\n"