|
| 1 | +#include <opencv2/opencv.hpp> |
| 2 | + |
| 3 | +int main( int argc, char** argv ) { |
| 4 | + |
| 5 | + cv::Mat img_rgb, img_gry, img_cny, img_pyr, img_pyr2; |
| 6 | + |
| 7 | + cv::namedWindow( "Example Gray", cv::WINDOW_AUTOSIZE ); |
| 8 | + cv::namedWindow( "Example Canny", cv::WINDOW_AUTOSIZE ); |
| 9 | + |
| 10 | + img_rgb = cv::imread( argv[1] ); |
| 11 | + |
| 12 | + cv::cvtColor( img_rgb, img_gry, cv::COLOR_BGR2GRAY); |
| 13 | + |
| 14 | + cv::pyrDown( img_gry, img_pyr ); |
| 15 | + cv::pyrDown( img_pyr, img_pyr2 ); |
| 16 | + |
| 17 | + cv::Canny( img_pyr2, img_cny, 10, 100, 3, true ); |
| 18 | + |
| 19 | + // ---------------------------------------------------- |
| 20 | + // Start new code for example 2-9 |
| 21 | + // |
| 22 | + |
| 23 | + int x = 16, y = 32; |
| 24 | + cv::Vec3b intensity = img_rgb.at< cv::Vec3b >(y, x); |
| 25 | + |
| 26 | + // ( Note: We could write img_rgb.at< cv::Vec3b >(x,y)[0] ) |
| 27 | + // |
| 28 | + uchar blue = intensity[0]; |
| 29 | + uchar green = intensity[1]; |
| 30 | + uchar red = intensity[2]; |
| 31 | + |
| 32 | + std::cout << "At (x,y) = (" << x << ", " << y << |
| 33 | + "): (blue, green, red) = (" << |
| 34 | + (unsigned int) blue << |
| 35 | + ", " << (unsigned int)green << ", " << |
| 36 | + (unsigned int) red << ")" << std::endl; |
| 37 | + |
| 38 | + std::cout << "Gray pixel there is: " << |
| 39 | + (unsigned int) img_gry.at<uchar>(y, x) << std::endl; |
| 40 | + |
| 41 | + x /= 4; y /= 4; |
| 42 | + |
| 43 | + std::cout << "Pyramid2 pixel there is: " << |
| 44 | + (unsigned int)img_pyr2.at<uchar>(y, x) << std::endl; |
| 45 | + |
| 46 | + img_cny.at<uchar>(x, y) = 128; // Set the Canny pixel there to 128 |
| 47 | + |
| 48 | + // |
| 49 | + // End new code for example 2-9 |
| 50 | + // ---------------------------------------------------- |
| 51 | + |
| 52 | + cv::imshow( "Example Gray", img_gry ); |
| 53 | + cv::imshow( "Example Canny", img_cny ); |
| 54 | + |
| 55 | + cv::waitKey(0); |
| 56 | + |
| 57 | +} |
0 commit comments