This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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'): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Release the objects | |
| vid_capture.release() | |
| cv2.destroyAllWindows() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Create a video capture object, in this case we are reading the video from a file | |
| vid_capture = cv2.VideoCapture('Resources/Cars.mp4') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
NewerOlder