最近在学习opencl在opencv上的编程,资料很少。我做的在opencl的HOG优化程序。
环境变量中加入一个新的字段OPENCV_OPENCL_DEVICE
:<Platform>:<CPU|GPU|ACCELERATOR|nothing=GPU/CPU>:<deviceName>
AMD:GPU:Tahiti
注意环境变量修改后,需要重启VS,才能生效。
其中要用到 CommandLineParser cmd(argc, argv, keys); 还要根据commandlineparser类,往main函数中传递参数,这确实是一个感觉陌生的类。而且通过get()函数得到参数的含义。
const char* keys =
"{ h | help | false | print help message }"
"{ i | input | | specify input image}"
"{ c | camera | -1 | enable camera capturing }"
"{ v | video | | use video as input }"
"{ g | gray | false | convert image to gray one or not}"
"{ s | scale | 1.0 | resize the image before detect}"
"{ l |larger_win| false | use 64x128 window}"
"{ o | output | | specify output path when input is images}";
make_gray = cmd.get<bool>("g");
resize_scale = cmd.get<double>("s");
win_width = cmd.get<bool>("l") == true ? 64 : 48;
vdo_source = cmd.get<string>("v");
img_source = cmd.get<string>("i");
output = cmd.get<string>("o");
camera_id = cmd.get<int>("c");
很奇怪的是我用VS在debug下总是出现abort()的访问越界错误,不知为什么?导致只能在release模式下进行操作。
在调试下我的输入命令参数为“-v p.avi -o ../ -l true”, 终于可以了,意思是:使用video测试,名字为p.avi,输出的位置为上一级目录,使用64*128的大窗口。
不过,好像效果很差,我的GPU很差,结果CPU的速度比GPU的速度快一步。