MCPcopy Create free account
hub / github.com/antmachineintelligence/mtgbmcode / main

Function main

compute/example/opencv_convolution.cpp:100–265  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

98// with OpenCV, transfer the frames to the GPU,
99// and apply a convolution written in OpenCL
100int 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)

Callers

nothing calls this directly

Calls 11

opencv_imshowFunction · 0.85
opencv_copy_mat_to_imageFunction · 0.85
buildMethod · 0.80
widthMethod · 0.80
heightMethod · 0.80
formatMethod · 0.80
countMethod · 0.45
build_logMethod · 0.45
set_argMethod · 0.45

Tested by

no test coverage detected