Python 3 OpenCV Script to Process MP4 Video Images and Perform Smoothing, Edge Detection & Bitwise Operations
import cv2
import numpy as np
cap = cv2.VideoCapture('sample.mp4')
while (cap.isOpened()):
ret, frame = cap.read()
frame = cv2.resize(frame, (540, 380), fx = 0, fy = 0,
interpolation = cv2.INTER_CUBIC)
cv2.imshow('Frame', frame)
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
Thresh = cv2.adaptiveThreshold(gray, 255, cv2.ADAPTIVE_THRESH_MEAN_C,
cv2.THRESH_BINARY_INV, 11, 2)
cv2.imshow('Thresh', Thresh)
if cv2.waitKey(25) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
import cv2
import numpy as np
cap = cv2.VideoCapture('sample.mp4')
while (cap.isOpened()):
ret, frame = cap.read()
frame = cv2.resize(frame, (540, 380), fx = 0, fy = 0,
interpolation = cv2.INTER_CUBIC)
cv2.imshow('Frame', frame)
gaussianblur = cv2.GaussianBlur(frame, (5, 5), 0)
cv2.imshow('gblur', gaussianblur)
if cv2.waitKey(25) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
import cv2
import numpy as np
cap = cv2.VideoCapture('sample.mp4')
while (cap.isOpened()):
ret, frame = cap.read()
frame = cv2.resize(frame, (540, 380), fx = 0, fy = 0,
interpolation = cv2.INTER_CUBIC)
cv2.imshow('Frame', frame)
edge_detect = cv2.Canny(frame, 100, 200)
cv2.imshow('Edge detect', edge_detect)
if cv2.waitKey(25) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
import cv2
import numpy as np
cap = cv2.VideoCapture('sample.mp4')
while (cap.isOpened()):
ret, frame = cap.read()
frame = cv2.resize(frame, (540, 380), fx = 0, fy = 0,
interpolation = cv2.INTER_CUBIC)
cv2.imshow('Frame', frame)
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
_, mask = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY_INV + cv2.THRESH_OTSU)
BIT = cv2.bitwise_not(frame, frame, mask = mask)
cv2.imshow('BIT', BIT)
if cv2.waitKey(25) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()