This example shows how to read two images or use camera with OpenCV, transfer the frames to the GPU, and apply a convolution written in OpenCL
| 98 | // with OpenCV, transfer the frames to the GPU, |
| 99 | // and apply a convolution written in OpenCL |
| 100 | int main(int argc, char *argv[]) |
| 101 | { |
| 102 | /////////////////////////////////////////////////////////////////////////// |
| 103 | |
| 104 | // setup the command line arguments |
| 105 | po::options_description desc; |
| 106 | desc.add_options() |
| 107 | ("help", "show available options") |
| 108 | ("camera", po::value<int>()->default_value(-1), |
| 109 | "if not default camera, specify a camera id") |
| 110 | ("image", po::value<std::string>(), "path to image file"); |
| 111 | |
| 112 | // Parse the command lines |
| 113 | po::variables_map vm; |
| 114 | po::store(po::parse_command_line(argc, argv, desc), vm); |
| 115 | po::notify(vm); |
| 116 | |
| 117 | //check the command line arguments |
| 118 | if(vm.count("help")) |
| 119 | { |
| 120 | std::cout << desc << std::endl; |
| 121 | return 0; |
| 122 | } |
| 123 | |
| 124 | /////////////////////////////////////////////////////////////////////////// |
| 125 | |
| 126 | //OpenCV variables |
| 127 | cv::Mat cv_mat; |
| 128 | cv::VideoCapture cap; //OpenCV camera handle. |
| 129 | |
| 130 | //Filter Variables |
| 131 | float filter[9] = { |
| 132 | -1.0, 0.0, 1.0, |
| 133 | -2.0, 0.0, 2.0, |
| 134 | -1.0, 0.0, 1.0, |
| 135 | }; |
| 136 | |
| 137 | // The convolution filter is 3x3 |
| 138 | int filterWidth = 3; |
| 139 | |
| 140 | //OpenCL variables |
| 141 | // Get default device and setup context |
| 142 | compute::device gpu = compute::system::default_device(); |
| 143 | compute::context context(gpu); |
| 144 | compute::command_queue queue(context, gpu); |
| 145 | compute::buffer dev_filter(context, sizeof(filter), |
| 146 | compute::memory_object::read_only | |
| 147 | compute::memory_object::copy_host_ptr, |
| 148 | filter); |
| 149 | |
| 150 | compute::program filter_program = |
| 151 | compute::program::create_with_source(source, context); |
| 152 | |
| 153 | try |
| 154 | { |
| 155 | filter_program.build(); |
| 156 | } |
| 157 | catch(compute::opencl_error e) |
nothing calls this directly
no test coverage detected