Edge Detection with OpenCV

Create a sketch-like effect by detecting edges in the image. Detect edges using the Canny edge detector i.e. the Canny() function. Let us see the example of detecting edges with OpenCV:

The following is the output:

Edge Detection with OpenCV
Explanation:

This Python script uses the OpenCV library to load an image, detect its edges using the Canny edge detection algorithm, and display the result:

  • It begins by importing OpenCV and loading the specified image into the variable image using the cv2.imread() function.
  • The Canny edge detector is then applied to the image using cv2.Canny(), which identifies edges by detecting areas of rapid intensity change. This function takes three arguments: the input image, the lower threshold (100), and the upper threshold (200).
  • The resulting edge-detected image is stored in the variable edges.
  • The script then displays the processed image in a window titled “Edge Detection Filter” using cv2.imshow().
  • To keep the display window open, it waits indefinitely for a key press with cv2.waitKey(0) and closes all OpenCV windows using cv2.destroyAllWindows().
  • This allows users to visualize the edges of the image clearly and interactively.

If you liked the tutorial, spread the word and share the link and our website Studyopedia with others.


For Videos, Join Our YouTube Channel: Join Now


Read More:

Blur an image with OpenCV
Add a Color Tint with OpenCV
Studyopedia Editorial Staff
contact@studyopedia.com

We work to create programming tutorials for all.

No Comments

Post A Comment

Discover more from Studyopedia

Subscribe now to keep reading and get access to the full archive.

Continue reading