Convert to HSV

    import numpy as np
    import cv2
    import time

    cam = cv2.VideoCapture('ling-f1-good1.mp4')

    while(cam.isOpened()):#Repeat until the end of the video
        t = time.time()
        #Time measurement
        ret, img = cam.read()
        #Cut into image

        if not ret:
            break
        #End if the video is the last


        img = cv2.resize(img, (640, 380))
        #Image resizing

        hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV_FULL)
        #Convert to HSV
        h = hsv[:, :, 0] #H is the hue
        s = hsv[:, :, 1]

        mask = np.zeros(h.shape, dtype=np.uint8)
        #Create an empty array for the mask
        mask[((h < 20) | (h > 200)) & (s > 60)] = 255
        #Create a mask at 200 to 20 degrees * Mask other than red

        #Masking process
        masked_img = cv2.bitwise_and(img, img, mask=mask)

        cv2.imshow("Frame", masked_img)

        print(time.time() - t, ret)

        if cv2.waitKey(1) & 0xFF == ord('q'): break
        #Finish when "q" is pressed

Recommended Posts

Convert to HSV
Convert 202003 to 2020-03 with pandas
Convert kanji to kana
Convert jupyter to py
Convert keras-yolo3 to onnx
Convert dict to array
Convert json to excel
Convert hexadecimal string to binary
[python] Convert date to string
Convert numpy int64 to python int
[Python] Convert list to Pandas [Pandas]
Convert HTML to text file
Convert Scratch project to Python
[Python] Convert Shift_JIS to UTF-8
Convert IP address to decimal
Convert SDF to CSV quickly
Convert genbank file to gff file
Convert python 3.x code to python 2.x
Convert .ipynb to .html (with BatchFile)
Function to convert Excel column to number
Convert PDF to Documents by OCR
Convert markdown to PDF in Python
Convert A4 PDF to A3 every 2 pages
Convert wma to mp3 on Mac
Convert some Japanese names to antonyms
convert ggplot based graph to html
Workflow to convert formula (image) to python
Convert list to DataFrame with python
Convert sentences to vectors with gensim
How to convert 0.5 to 1056964608 in one shot
Python> list> Convert double list to single list
Convert from pdf to txt 2 [pyocr]
How to convert Tensorflow model to Lite
Convert a string to an image
[Python] Convert natural numbers to ordinal numbers
Convert decimal numbers to n-ary numbers [python]
Program to convert Japanese to station name
How to convert from .mgz to .nii.gz
Convert PDF to image with ImageMagick
A tool to convert Juniper config
Python> tuple> Convert double tuple to single tuple
[Python] How to convert db file to csv
Convert memo at once with Python 2to3
How to easily convert format from Markdown
Convert Python> two value sequence to dictionary
[Django] Convert QuerySet to dictionary type list
[Python] How to convert a 2D list to a 1D list
How to convert csv to tsv in CLI
How to convert Python to an exe file
Convert matplotlib graphs to emf file format
[Python] Convert csv file delimiters to tab delimiters
Convert from PDF to CSV with pdfplumber
Convert GFF3 to MSS for DDBJ submission
Convert (compress) formatted JSON string to 1-line JSON
Convert psd file to png in Python
Convert MetaImageIO (* .mha, * .mhd) to tiff stack
Convert character strings to features with RoBERTa
Convert Excel data to JSON with python
[MNIST] Convert data to PNG for keras
Convert Hiragana to Romaji with Python (Beta)
Convert from katakana to vowel kana [python]