Skip to content

Instantly share code, notes, and snippets.

@csukuangfj
Last active September 14, 2023 05:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save csukuangfj/49d6e8fb4bf4b694f2235b8fcfd1ca8b to your computer and use it in GitHub Desktop.
Save csukuangfj/49d6e8fb4bf4b694f2235b8fcfd1ca8b to your computer and use it in GitHub Desktop.
First example of using OpenCL in OpenCV 3.x
// This example shows how to create
// a context from a specified device type
// using OpenCL wrappers provided by OpenCV 3.x
//
// The default platform is the zero-th platform
// returned by clGetPlatformIDs.
//
// To compile it on Mac OS X, add `-framework opencl`
// to CXX_FLAGS
#include <iostream>
#include <opencv2/core/ocl.hpp>
int main()
{
cv::ocl::Context ctx;
ctx.create(cv::ocl::Device::TYPE_CPU);
std::cout << ctx.ndevices() << std::endl;
std::cout << (ctx.create() ? "true":"false") << std::endl;
return 0;
}
// output:
//1
//false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment