// ================= // || Worksheet 3 // || In this example, we are going to apply convolution filters to an image.. // ================= // for comparison, see: // http://docs.opencv.org/doc/tutorials/core/mat-mask-operations/mat-mask-operations.html#maskoperationsfilter // more at // https://github.com/Itseez/opencv/blob/master/samples/cpp/tutorial_code/core/mat_mask_operations/mat_mask_operations.cpp #include "program.h" using namespace std; using namespace cv; int worksheetthree( Mat& colorImage ) { char my_window_name[] = "My Image"; cv::namedWindow( my_window_name, WINDOW_AUTOSIZE ); // display our output image. cv::imshow( my_window_name, colorImage); cv::waitKey(); cv::Mat outputImage; outputImage.create(colorImage.size(), colorImage.type()); // now, we are going to create a convolution kernel. // this should do a small blurring. // the syntax here is a little confusing. // we are going to need to create a 3x3 matrix. //and store the following values // 0 1 0 // 1 2 1 // 0 1 0 cv::Mat kernel = (cv::Mat_(3,3) << 0, 1, 0, 1, 2, 1, 0, 1, 0); // now that we have our kernel, we want to apply it to our input image. // the arguments are // filter2D(input, output, depth, kernel) cv::filter2D(colorImage, outputImage, colorImage.depth(), 0.1666f*kernel); // display our output image. cv::imshow( my_window_name, outputImage); cv::waitKey(); return 0; }