Learn practical skills, build real-world projects, and advance your career
Updated 3 years ago
Edge Detection using OpenCV in Python-Programming
- This was an Amazing Project made with Python OpenCV b Capturing Live video.
- This Projec Requires Acive Internet and can be Open in oogle-Colab, Bnider or Jupyter Notebboks as well.
- Make sure of Installing required Python Libraries to perfoem this Project.
Best Regards:
- S.Venkata Sreeram | venkatasreeram14@gmail.com
Let's Import Necessary Files to Perform Operations
- pip install python cv2
- pip install numpy
Note: Makes Sure of Install these in your command prompt before Importing these in Notebook
import cv2
import numpy as np # # np is an alias pointing to numpy library
# capture frames from a camera
cap = cv2.VideoCapture(0)
# loop runs if capturing has been initialized
while(1):
# reads frames from a camera
ret, frame = cap.read()
# converting BGR to HSV
hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
# define range of red color in HSV
lower_red = np.array([30,150,50])
upper_red = np.array([255,255,180])
# create a red HSV colour boundary and
# threshold HSV image
mask = cv2.inRange(hsv, lower_red, upper_red)
# Bitwise-AND mask and original image
res = cv2.bitwise_and(frame,frame, mask= mask)
# Display an original image
cv2.imshow('Original',frame)
# finds edges in the input image image and
# marks them in the output map edges
edges = cv2.Canny(frame,100,200)
# Display edges in a frame
cv2.imshow('Edges',edges)
# Wait for Esc key to stop
k = cv2.waitKey(5) & 0xFF
if k == 27:
break
# Close the window
cap.release()
# De-allocate any associated memory usage
cv2.destroyAllWindows()