This example shows how to read two images or use camera with OpenCV, transfer the frames to the GPU, and apply a naive optical flow algorithm written in OpenCL
| 114 | // and apply a naive optical flow algorithm |
| 115 | // written in OpenCL |
| 116 | int main(int argc, char *argv[]) |
| 117 | { |
| 118 | // setup the command line arguments |
| 119 | po::options_description desc; |
| 120 | desc.add_options() |
| 121 | ("help", "show available options") |
| 122 | ("camera", po::value<int>()->default_value(-1), |
| 123 | "if not default camera, specify a camera id") |
| 124 | ("image1", po::value<std::string>(), "path to image file 1") |
| 125 | ("image2", po::value<std::string>(), "path to image file 2"); |
| 126 | |
| 127 | // Parse the command lines |
| 128 | po::variables_map vm; |
| 129 | po::store(po::parse_command_line(argc, argv, desc), vm); |
| 130 | po::notify(vm); |
| 131 | |
| 132 | //check the command line arguments |
| 133 | if(vm.count("help")) |
| 134 | { |
| 135 | std::cout << desc << std::endl; |
| 136 | return 0; |
| 137 | } |
| 138 | |
| 139 | //OpenCV variables |
| 140 | cv::Mat previous_cv_image; |
| 141 | cv::Mat current_cv_image; |
| 142 | cv::VideoCapture cap; //OpenCV camera handle |
| 143 | |
| 144 | //check for image paths |
| 145 | if(vm.count("image1") && vm.count("image2")) |
| 146 | { |
| 147 | // Read image 1 with OpenCV |
| 148 | previous_cv_image = cv::imread(vm["image1"].as<std::string>(), |
| 149 | CV_LOAD_IMAGE_COLOR); |
| 150 | if(!previous_cv_image.data){ |
| 151 | std::cerr << "Failed to load image" << std::endl; |
| 152 | return -1; |
| 153 | } |
| 154 | |
| 155 | // Read image 2 with opencv |
| 156 | current_cv_image = cv::imread(vm["image2"].as<std::string>(), |
| 157 | CV_LOAD_IMAGE_COLOR); |
| 158 | if(!current_cv_image.data){ |
| 159 | std::cerr << "Failed to load image" << std::endl; |
| 160 | return -1; |
| 161 | } |
| 162 | } |
| 163 | else //by default use camera |
| 164 | { |
| 165 | //open camera |
| 166 | cap.open(vm["camera"].as<int>()); |
| 167 | // read first frame |
| 168 | cap >> previous_cv_image; |
| 169 | if(!previous_cv_image.data){ |
| 170 | std::cerr << "failed to capture frame" << std::endl; |
| 171 | return -1; |
| 172 | } |
| 173 |
nothing calls this directly
no test coverage detected