Opencv-python (11)--Image edge detection

Source: Internet
Author: User
Tags function prototype

I. Introduction to Functions 1, Laplacian operator function prototypes: Laplacian (SRC, ddepth, Dst=none, Ksize=none, Scale=none, Delta=none, Bordertype=none) SRC: Image matrix ddepth: Depth type 2, Sobel operator function prototype: Sobel (SRC, ddepth, dx, dy, Dst=none, Ksize=none, Scale=none, Delta=none, bordertype= None) src: Image matrix ddepth: Depth type dx:x direction dy:y Direction 3, Canny operator function prototype: Canny (image, Threshold1, Threshold2, Edges=none, aperturesize= None, L2gradient=none) Image: Image matrix Threshold1: Threshold value 1threshold1: Threshold 22, instance Walkthrough 1, Laplace Edge detection code as follows:
#encoding: Utf-8##laplacian边缘检测#Import NumPy as Npimport cv2image = Cv2. Imread("H:\\img\\lena.jpg") image = Cv2. Cvtcolor(Image,cv2. COLOR_bgr2gray)#将图像转化为灰度图像Cv2. Imshow("Original", image) Cv2. Waitkey()#拉普拉斯边缘检测Lap = Cv2. Laplacian(Image,cv2. CV_64f)#拉普拉斯边缘检测Lap = NP. UINT8 (NP. Absolute(lap))# #对lap去绝对值Cv2. Imshow("Laplacian", lap) Cv2. Waitkey()
The results are as follows: Original image:

Laplacian Edge Detection results:

2. Soble Edge Detection code is as follows:
#encoding: Utf-8##Sobel边缘检测#Import NumPy as Npimport cv2image = Cv2. Imread("H:\\img\\lena.jpg") image = Cv2. Cvtcolor(Image,cv2. COLOR_bgr2gray)#将图像转化为灰度图像Cv2. Imshow("Original", image) Cv2. Waitkey()#Sobel边缘检测Sobelx = Cv2. Sobel(Image,cv2. CV_64f,1,0)#x方向的梯度sobely = Cv2. Sobel(Image,cv2. CV_64f,0,1)#y方向的梯度SOBELX = NP. UINT8 (NP. Absolute(SOBELX))#x方向梯度的绝对值sobely = NP. UINT8 (NP. Absolute(sobely))#y方向梯度的绝对值sobelcombined = Cv2. Bitwise_or (sobelx,sobely)#Cv2. Imshow("Sobel X", Sobelx) Cv2. Waitkey() Cv2. Imshow("Sobel Y", sobely) Cv2. Waitkey() Cv2. Imshow("Sobel Combined", sobelcombined) Cv2. Waitkey()
The results are as follows: Original image:

X-Direction Edge detection results:

Y-Direction edge detection results:

XY direction combined with edge detection results:

3. Canny edge detection code is as follows:
#encoding: Utf-8##Canny边缘检测#Import NumPy as Npimport cv2image = Cv2. Imread("H:\\img\\lena.jpg")#读入图像Image = Cv2. Cvtcolor(Image,cv2. COLOR_bgr2gray)#将图像转化为灰度图像Cv2. Imshow("Image", image)#显示图像Cv2. Waitkey()#Canny边缘检测Canny = Cv2. Canny(Image, -, Max) Cv2. Imshow("Canny", canny) Cv2. Waitkey()
The results are as follows: Original image:

Canny Edge detection results:

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Opencv-python (11)--Image edge detection

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.