【opencv六】利用opencv做边缘提取,并展示像素级操作

利用opencv做一些计算机视觉的操作。实现的功能就是将彩色图片变成灰白的,并对灰度图片作边缘化提取操作。下图展示的是灰度图和边缘图。

#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"

using namespace cv;

int main()
{
	Mat img_rgb, img_gry, img_cny;

	namedWindow("Example Gray",WINDOW_AUTOSIZE);
	namedWindow("Example Canny",WINDOW_AUTOSIZE);

	img_rgb = imread("H:\\vs2017\\opencv_learning\\ConsoleApplication1\\img.jpg");
	
	cvtColor(img_rgb,img_gry,COLOR_BGR2GRAY);
	imshow("Example Gray",img_gry);

	Canny(img_gry,img_cny,10,100,3,true);
	imshow("Example Canny",img_cny);



	waitKey(0);

	return 0;

}


对图片的某一个像素进行读取,并修改该像素值。下边代码展示的是对衣服全灰的图,在某一个像素位置使其变成一个小白点。

#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
using namespace cv;

int main()
{
	Mat img_rgb, img_gry, img_cny;

	namedWindow("Example Gray",WINDOW_AUTOSIZE);
	namedWindow("Example Canny",WINDOW_AUTOSIZE);

	img_rgb = imread("H:\\vs2017\\opencv_learning\\ConsoleApplication1\\img.png");
	
	cvtColor(img_rgb,img_gry,COLOR_BGR2GRAY);
	int x = 16, y = 32;
	Vec3b intensity = img_rgb.at< 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;

	img_gry.at<uchar>(x, y) = 255; // Set the gray pixel

	imshow("Example Gray",img_gry);

	Canny(img_gry,img_cny,10,100,3,true);
	imshow("Example Canny",img_cny);

	waitKey(0);

	getchar();
	return 0;

}

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

yuanCruise

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值