Edge detection is a process of identifying and locating sharp changes in intensity in an image, which can correspond to object boundaries. OpenCV provides various ways to detect edges easily. One of the most popular edge detection algorithm in OpenCV is Canny Edge Detection. In this tutorial, we will learn about how to detect edges in images using OpenCV with some practical work.
Canny edge detection is a popular edge detection algorithm in computer vision, which is used to identify edges in an image. This algorithm is widely used in computer vision applications such as image segmentation, object detection, and many more operations. We can use cv2.canny() function to use this algorithm. This function will take parameters like image source, minimum intensity gradient value, maximum intensity gradient value, aperture size(optional), L2 gradient(default).
Example 1:
Input
Code:
import cv2
img = cv2.imread('demo.png')
image = cv2.Canny(img,100,200)
cv2.imshow('Result', image)
cv2.waitKey(0)
cv2.destroyAllWindows()
Here, first, we imported cv2 and used cv2.imread to read the image. Then, we used cv2.canny with 100 minimum and 200 as the maximum gradient value. At last, we used cv2.imshow to display the final result.
Result:
Example 2:
Input
Code:
import cv2
img = cv2.imread('srk.jpg')
image = cv2.Canny(img,150,200)
cv2.imshow('Result', image)
cv2.waitKey(0)
cv2.destroyAllWindows()
Here, first, we imported cv2 and used cv2.imread to read the image. Then, we used cv2.canny with 150 minimum and 200 as the maximum gradient value. At last, we used cv2.imshow to display the final result.
Result:
Trainings :
Data Science Training in Indore | Python Training in Indore | Data Analytics Training in Indore | Blockchain Training in Indore | React JS Training in Indore | Web Development Training in Indore | Full Stack Development Training in Indore |Free Courses and Resource :
Dart | OpenCV Tutorials | Projects | Interview Questions | Python Data Structures and Algorithms | Aptitude Tests | Verbal Aptitude | Matplotlib Tutorials | Examples | Interview Questions | HackerRank Python | Pandas Tutorials | Projects | Interview Questions | Rust Tutorials | Projects | Interview Questions | ExpressJS Tutorials | Projects | Interview Questions | Django | MongoDB Tutorials | Examples | Interview Questions | HackerRank C Program Solutions | Python Tutorials by CodersDaily | React.js Tutorials | Golang Tutorials | Projects | Interview Questions | MS Sql Server Tutorials | Examples | Interview Questions | Verbal Ability Tutorial | Numpy Tutorials | Projects | Interview Questions | Power BI Tutorials | Projects | Interview Questions | Example Dashboards | Tensor Flow | HackerRank C++ Solutions | Django REST Framework Tutorial | CodeChef Python Solutions | Leetcode Python Solutions | Reasoning Ability Tutorial | Quantitative Ability Tutorial | C++ Tutorials | HackerRank Java Solutions | TCS NQT Mock Test Series | Verbal Aptitude 2 | HackerRank DSA Solutions | HackerRank SQL Solutions | Javascript | Node.js Tutorials |Interview Questions :
Pandas Tutorials | Projects | Interview Questions | ExpressJS Tutorials | Projects | Interview Questions | Django | Python Tutorials by CodersDaily | Golang Tutorials | Projects | Interview Questions | Numpy Tutorials | Projects | Interview Questions | Django REST Framework Tutorial |Top Colleges in India :
Indian Institute of Technology Bombay | Jaypee University of Engineering and Technology - Guna |