Sunday, May 3, 2020

Computer Vision 4- Video Basics with OpenCV

Learn A-Z Computer Vision In 15 Days 



In this lecture, we will cover  Video Basic with OpenCV.

Video Capture

import cv2

# Connects to your computer's default camera
cap = cv2.VideoCapture(0)

while (cap.isOpened()):
    
    # Capture frame-by-frame    
    ret, frame=cap.read()
    if not ret:
        break  

    # Grayscale the Image
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

    # Display the resulting frame
    cv2.imshow('frame',gray)
    
    # This command let's us quit with the "q" button on a keyboard.
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

# When everything is done, release the capture and destroy the windows
cap.release()
cv2.destroyAllWindows()

Video Writer

import cv2

# Connects to your computer's default camera
cap = cv2.VideoCapture(0)

# Writer is used to export(save) the frame  
writer = cv2.VideoWriter('Live_capture.mp4', cv2.VideoWriter_fourcc(*"MJPG"), 30 (int(cap.get(3)),int(cap.get(4)))) 

while (cap.isOpened()):
    
    # Capture frame-by-frame    
    ret, frame=cap.read()
    if not ret:
        break  

    # Write the video
    writer.write(frame)

    # Display the resulting frame
    cv2.imshow('frame',frame)
    
    # This command let's us quit with the "q" button on a keyboard.
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

        
cap.release()
writer.release()
cv2.destroyAllWindows()



In the next blog, we will discuss the Object detection with OpenCV. 
https://sngurukuls247.blogspot.com/2020/05/computer-vision-5-video-basics-with.html

.                                                                                                                                        


Follow the link below to access Free Python Lectures-

Instagram-
https://www.instagram.com/python.india/

Feel free contact me on-
Email - sn.gurukul24.7uk@gmail.com

No comments:

Post a Comment