opencv中ocl的使用

更新时间:2023-11-27 12:13:01 阅读量: 教育文库 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

// ocl_stereo_match.cpp : 定义控制台应用程序的入口点。 //

#include \

#include #include #include #include #include

#include \

#include \

#pragma comment(lib,\#pragma comment(lib,\#pragma comment(lib,\

#pragma comment(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 \ case BP: return \ case CSBP: return \ } return \ } string text() const { stringstreamss; ss<< \ <

int main(intargc, char** argv) { const char* keys = \ | false | print help message }\ \ | | specify left image }\ \ | | specify right image }\ \m | method | BM | specify match

method(BM/BP/CSBP) }\ \ | 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<< \ cmd.printParams(); return 0; } try { App app(cmd); cout<< \name:\cv::ocl::Context::getContext()->getDeviceInfo().deviceName<

App::App(CommandLineParser&cmd) : running(false),method(BM) { cout<< \ cout<< \ << \ << \ << \ << \ << \ << \ << \ << \ << \

<< << \ l_img = cmd.get(\ r_img = cmd.get(\ stringmstr = cmd.get(\ if(mstr == \ else if(mstr == \ else if(mstr == \ elsecout<< \ ndisp = cmd.get(\ out_img = cmd.get(\ write_once = false; }

void App::run() { // Load images cout<

while (running) { // Prepare disparity map of specified type Mat disp; oclMatd_disp; workBegin(); switch (method) { case BM: if (d_left.channels() > 1 || d_right.channels() > 1) { cout<< \ cvtColor(left_src, left, CV_BGR2GRAY); cvtColor(right_src, right, CV_BGR2GRAY); cout<< \ d_left.upload(left); d_right.upload(right); imshow(\ imshow(\ } bm(d_left, d_right, d_disp); break; case BP: bp(d_left, d_right, d_disp); break; case CSBP: csbp(d_left, d_right, d_disp); break; }

// Show results

d_disp.download(disp); workEnd();

if (method != BM) { disp.convertTo(disp, 0); }

putText(disp, text(), Point(5, 25), FONT_HERSHEY_SIMPLEX, 1.0, Scalar::all(255)); imshow(\if(write_once) { imwrite(out_img, disp); write_once = false;

本文来源:https://www.bwwdw.com/article/70et.html

Top