How to do it...

  1. Import the necessary packages:
import sys 
import cv2 
import numpy as np 
  1. Read the input image:
in_file = sys.argv[1] 
image = cv2.imread(in_file, cv2.IMREAD_GRAYSCALE) 
  1. Implement the Sobel edge detection scheme:
horizontal_sobel = cv2.Sobel(image, cv2.CV_64F, 1, 0, ksize=5) 
vertical_sobel = cv2.Sobel(image, cv2.CV_64F, 0, 1, ksize=5) 
laplacian_img = cv2.Laplacian(image, cv2.CV_64F) 
canny_img = cv2.Canny(image, 30, 200) 
  1. Display the input image and its corresponding output:
cv2.imshow('Original', image) 
cv2.imshow('horizontal Sobel', horizontal_sobel) 
cv2.imshow('vertical Sobel', vertical_sobel) 
cv2.imshow('Laplacian image', laplacian_img) 
cv2.imshow('Canny image', canny_img) 
  1. Wait for the instruction from the operator:
cv2.waitKey() 
  1. Display the input image and the corresponding results:
cv2.imshow('Original', image) 
cv2.imshow('horizontal Sobel', horizontal_sobel) 
cv2.imshow('vertical Sobel', vertical_sobel) 
cv2.imshow('Laplacian image', laplacian_img) 
cv2.imshow('Canny image', canny_img) 
  1. Wait for the instruction from the operator:
cv2.waitKey()
  1. The command used to execute the Detecting_edges.py Python program file, along with the input image (baby.jpg), is shown here:
  1. The input image and the horizontal Sobel filter output obtained after executing the Detecting_edges.py file is shown here:
  1. The vertical Sobel filter output and the Laplacian image output obtained after executing the Detecting_edges.py file is shown here:

Following  is the Laplacian image output:

  1. The Canny edge detection output obtained after executing the Detecting_edges.py file is shown here: