Oh Snap!

Please turnoff your ad blocking mode for viewing your site content

Hit enter after type your search item

Python OpenCV Tutorial To Capture Images From Webcam Full Project

/
/
/
410 Views

Welcome folks today in this blog post I will be talking about how to capture images from webcam using opencv library in python full project. So let’s get started. You can see the step by step video for building this application.

READ  Python Tutorial Compressing and Extracting Files Using ZipFile Library Full Project

 

 

Requirements

 

pip install opencv

 

 

Full Source Code

 

 

import cv2

cam = cv2.VideoCapture(0)

cv2.namedWindow("test")

img_counter = 0

while True:
    ret, frame = cam.read()
    if not ret:
        print("failed to grab frame")
        break
    cv2.imshow("test", frame)

    k = cv2.waitKey(1)
    if k%256 == 27:
        # ESC pressed
        print("Escape hit, closing...")
        break
    elif k%256 == 32:
        # SPACE pressed
        img_name = "opencv_frame_{}.png".format(img_counter)
        cv2.imwrite(img_name, frame)
        print("{} written!".format(img_name))
        img_counter += 1

cam.release()

cv2.destroyAllWindows()

 

READ  Python Tutorial To Convert Images to PDF Document Using Pillow Library

 

When you press the space key in the application the screenshot will be taken automatically and image will be saved in your local directory and also when you want to exit the application you can press the esc key.

READ  PyInstaller Tutorial to Convert Python Scripts (.py) to .EXE Files Full Tutorial

 

 

Leave a Comment

Your email address will not be published. Required fields are marked *

This div height required for enabling the sticky sidebar
Ad Clicks : Ad Views : Ad Clicks : Ad Views : Ad Clicks : Ad Views : Ad Clicks : Ad Views : Ad Clicks : Ad Views : Ad Clicks : Ad Views : Ad Clicks : Ad Views : Ad Clicks : Ad Views : Ad Clicks : Ad Views : Ad Clicks : Ad Views : Ad Clicks : Ad Views : Ad Clicks : Ad Views :