Skip to content

Instantly share code, notes, and snippets.

View Achyut-Krishna's full-sized avatar
💭
I may be slow to respond.

Achyut Krishna Sai Adiraju Achyut-Krishna

💭
I may be slow to respond.
View GitHub Profile
import cv2 as cv
# img = cv.imread('../Resources/Photos/cat.jpg')
# cv.imshow('Cat', img)
def rescaleFrame(frame, scale=0.75):
# Images, Videos and Live Video
width = int(frame.shape[1] * scale)
height = int(frame.shape[0] * scale)
dimensions = (width,height)
return cv.resize(frame, dimensions, interpolation=cv.INTER_AREA)
def changeRes(width,height):
capture = cv.VideoCapture('../Resources/Videos/dog.mp4')
while True:
isTrue, frame = capture.read()
# if cv.waitKey(20) & 0xFF==ord('d'):
# This is the preferred way - if `isTrue` is false (the frame could
# not be read, or we're at the end of the video), we immediately
# break from the loop.
if isTrue:
cv.imshow('Video', frame)
if cv.waitKey(20) & 0xFF==ord('d'):
while(vid_capture.isOpened()):
# vCapture.read() methods returns a tuple, first element is a bool
# and the second is frame
ret, frame = vid_capture.read()
if ret == True:
cv2.imshow('Frame',frame)
k = cv2.waitKey(20)
# 113 is ASCII code for q key
if k == 113:
# Release the objects
vid_capture.release()
cv2.destroyAllWindows()
if (vid_capture.isOpened() == False):
print("Error opening the video file")
else:
# Get frame rate information
fps = int(vid_capture.get(5))
print("Frame Rate : ",fps,"frames per second")
# Get frame count
frame_count = vid_capture.get(7)
# Create a video capture object, in this case we are reading the video from a file
vid_capture = cv2.VideoCapture('Resources/Cars.mp4')
import cv2
# Create a video capture object, in this case we are reading the video from a file
vid_capture = cv2.VideoCapture('Resources/Cars.mp4')
if (vid_capture.isOpened() == False):
print("Error opening the video file")
# Read fps and frame count
else:
# Get frame rate information
#library is imported
import cv2 as cv
# Read in an image
img = cv.imread('../Resources/Photos/park.jpg')
cv.imshow('Park', img)
# Cropping
cropped = img[50:200, 200:400]
cv.imshow('Cropped', cropped)
#library is imported
import cv2 as cv
# Read in an image
img = cv.imread('../Resources/Photos/park.jpg')
cv.imshow('Park', img)
# Resize
resized = cv.resize(img, (500,500), interpolation=cv.INTER_CUBIC)
cv.imshow('Resized', resized)
import cv2
import numpy as np
img = cv2.imread(r'C:\Users\Achyut Krishna\baloon.jpg', 1)
kernel = np.ones((5,5), np.uint8)
img_erosion = cv2.erode(img, kernel, iterations=1)
img_dilation = cv2.dilate(img, kernel, iterations=1)
cv2.imshow('Input', img)
cv2.imshow('Erosion', img_erosion)
cv2.waitKey(0)