COLOR_BGR2GRAY
So here we are going to use the same test image and then we are going to look at the basic function that we can use which are present in the image processing, so after reading our image, we are going to first convert it into grayscale. So to convert it we can write cvtColor and then here you can see that we have all the arguments that are required. So we can write first argument here the input image, and second argument here then we have to write the output image or the destination image. So we will write imageGray, and then third argument here we will write the conversion. So we need to convert from COLOR_BGR2GRAY. Now this is giving error because it does not recognize imageGray, so what we cat do is we can define here Mat, and we can write here imageGray (define Mat imageGray ). So now it should be fine. So if we write it again COLOR_BGR2GRAY. Imshow imageGray ,run it. So here we have the original image and here we have the image gray.
ADD BLUR
Next we will add a little bit of blur, so we have different types of blurs that we can add but one of the most common ones is gaussian blur. So we are going to use that so let’s write here GaussianBlur and then we are going to define our image then our destination image now if you remember in python, We don’t actually write the destination. Inside the function but most of the time we write it outside. Input corresponding arguments. Run it.
Edge detection
We will learn how to perform edge detection and one of the most commonly used edge detector is canny edge detector. So let’s write down the canny ()
Dilate and erode an image
We well learn dilate and erode image. So a lot of the times when you detect the edges, they are not completely filled or you can say they are not joined or they are very thin to actually detect properly. So what you can do is you can dilate it, which means it will increase their thickness and you can erode it which means it will decrease their thickness. So let’s see how we can do that so here we will write dilate(). So we are going to give in our image (imagecanny), And then we are going to give out our image output. So we will write image dilation.
?这次练习主要关于opencv的基本函数,彩色图像转变为灰度图像,添加模糊主要使用的是高斯模糊,边缘提取,边缘扩张和边缘侵蚀。
图像效果:
?
?
|