[PYTHON] Start the webcam to take a still image and save it locally

Thing you want to do

--Launch the webcam attached to your PC --Taking a still image --Save locally

environment

Implementation

#Create an instance of the VideoCapture class
    #Specify 0 when using the built-in webcam
    cap = cv2.VideoCapture(0)

    #If it cannot be read normally
    if cap.isOpened() is False:
        print("IO Error")
    #When loaded normally
    else:
        #read method
        #Return value 1 ret:Was the frame image loaded?/Return value 2 frame:Array of images (ndarray)
        ret, frame = cap.read()
        image_path = "./images/"
        if (ret):
            #imwrite method
            #Argument 1: Image path Argument 2: ndarray object representing the image
            #The extension of the image path is.jpg and.You can use png.
            cv2.imwrite(image_path + "image.png ", frame)
        else:
            print("Read Error")

    cap.release() #Quit the camera device

Recommended Posts

Start the webcam to take a still image and save it locally
[python] Send the image captured from the webcam to the server and save it
How to save the feature point information of an image in a file and use it for matching
POST the image selected on the website with multipart / form-data and save it to Amazon S3! !!
I want to cut out only the face from a person image with Python and save it ~ Face detection and trimming with face_recognition ~
I tried to cut out a still image from the video
How to split and save a DataFrame
I ran GhostScript with python, split the PDF into pages, and converted it to a JPEG image.
The story of making a tool to load an image with Python ⇒ save it as another name
[Python] How to save the installed package and install it in a new environment at once Mac environment
Attempt to launch another .exe and save the console output to a text file
Use Pillow to make the image transparent and overlay only part of it
Crop Numpy.ndarray and save it as an image
Note: Start Anaconda, enter the Python virtual environment, and connect locally to MongoDB.
Save the object to a file with pickle
[Python3] Take a screenshot of a web page on the server and crop it further
100 image processing knocks !! (021-030) I want to take a break ...
Save the graph drawn by pyqtgraph to an image
POST the image with json and receive it with flask
How to take a captured image from a video (OpenCV)
Resize the image to the specified size and blacken the margins
It is difficult to install a green screen, so I cut out only the face and superimposed it on the background image
How to interactively draw a machine learning pipeline with scikit-learn and save it in HTML
A story that makes it easy to estimate the living area using Elasticsearch and Python
How to start the PC at a fixed time every morning and execute the python program
Recursively get the Excel list in a specific folder with python and write it to Excel.
Steps to create a Job that pulls a Docker image and tests it with Github Actions
Return the image data with Flask of Python and draw it to the canvas element of HTML
I made a function to crop the image of python openCV, so please use it.
An easy way to view the time taken in Python and a smarter way to improve it
How to insert a specific process at the start and end of spider with scrapy
Get an image from a web page and resize it
Save the pystan model and results in a pickle file
[python] Change the image file name to a serial number
Temporarily save a Python object and reuse it in another Python
[pyqtgraph] Add region to the graph and link it with the graph region
Convert the image data (png) at hand to a .pbm image
How to take a screenshot of the Chrome screen (prevent it from cutting off in the middle)
I want to create a histogram and overlay the normal distribution curve on it. matplotlib edition
Find the white Christmas rate by prefecture with Python and map it to a map of Japan
[Python] The role of the asterisk in front of the variable. Divide the input value and assign it to a variable
It is surprisingly troublesome to get a list of the last login date and time of Workspaces
The image is a slug
How to start the program
I want to record the execution time and keep a log.
[PEP8] Take over the Python source code and write it neatly
Process Splunk execution results using Python and save to a file
How easy is it to synthesize a drug on the market?
Try to edit a new image using the trained StyleGAN2 model
[Go] Create a CLI command to change the extension of the image
Take an image with Pepper and display it on your tablet
I want to create a pipfile and reflect it in docker
Convert the result of python optparse to dict and utilize it
Note that Python decodes base64 format image and saves it locally
Python --Get bitcoin rate BTC / JPY from bitflyer at regular intervals and save it to a file
[Python / Jupyter] Translate the comment of the program copied to the clipboard and insert it in a new cell
I made a POST script to create an issue on Github and register it in the Project
Set up a yum repository server on CentOS7 system and refer to it locally and from other servers.
Use Cloud Dataflow to dynamically change the destination according to the value of the data and save it in GCS
How to input a character string in Python and output it as it is or in the opposite direction.
Upload data to s3 of aws with a command and update it, and delete the used data (on the way)