1 Star 0 Fork 0

lewlovehow / Learning-OpenCV-3_examples

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
example_02-09.cpp 1.80 KB
一键复制 编辑 原始数据 按行查看 历史
// Example 2-9. Getting and setting pixels in Example 2-8
#include <opencv2/opencv.hpp>
void help(char** argv ) {
std::cout << "\n"
<< "\nExample 2-9. Getting and setting pixels in Example 2-8"
<< "\nCall:\n"
<< argv[0] <<" <path/image>\n"
<< "For example:\n"
<< argv[0] << " ../fruits.jpg\n"
<< std::endl;
}
int main( int argc, char** argv ) {
if (argc != 2) {
help(argv);
return 0;
}
cv::Mat img_rgb, img_gry, img_cny, img_pyr, img_pyr2;
cv::namedWindow( "Example Gray", cv::WINDOW_AUTOSIZE );
cv::namedWindow( "Example Canny", cv::WINDOW_AUTOSIZE );
img_rgb = cv::imread( argv[1] );
cv::cvtColor( img_rgb, img_gry, cv::COLOR_BGR2GRAY);
cv::pyrDown( img_gry, img_pyr );
cv::pyrDown( img_pyr, img_pyr2 );
cv::Canny( img_pyr2, img_cny, 10, 100, 3, true );
// ----------------------------------------------------
// Start new code for example 2-9
//
int x = 16, y = 32;
cv::Vec3b intensity = img_rgb.at< cv::Vec3b >(y, x);
// ( Note: We could write img_rgb.at< cv::Vec3b >(x,y)[0] )
//
uchar blue = intensity[0];
uchar green = intensity[1];
uchar red = intensity[2];
std::cout << "At (x,y) = (" << x << ", " << y <<
"): (blue, green, red) = (" <<
(unsigned int) blue <<
", " << (unsigned int)green << ", " <<
(unsigned int) red << ")" << std::endl;
std::cout << "Gray pixel there is: " <<
(unsigned int) img_gry.at<uchar>(y, x) << std::endl;
x /= 4; y /= 4;
std::cout << "Pyramid2 pixel there is: " <<
(unsigned int)img_pyr2.at<uchar>(y, x) << std::endl;
img_cny.at<uchar>(x, y) = 128; // Set the Canny pixel there to 128
//
// End new code for example 2-9
// ----------------------------------------------------
cv::imshow( "Example Gray", img_gry );
cv::imshow( "Example Canny", img_cny );
cv::waitKey(0);
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/lewlovehow/Learning-OpenCV-3_examples.git
git@gitee.com:lewlovehow/Learning-OpenCV-3_examples.git
lewlovehow
Learning-OpenCV-3_examples
Learning-OpenCV-3_examples
master

搜索帮助

344bd9b3 5694891 D2dac590 5694891