SoFunction
Updated on 2024-11-12

python-opencv color extraction segmentation method

1. For simple object detection, tracking

2. Simple front background segmentation

#encoding:utf-8
#Yellow detection
import numpy as np
import argparse
import cv2
image = ('')
color = [
 ([0, 70, 70], [100, 255, 255])#Yellow range~This is my own experimental range, can be adjusted according to the actual situation~Note: The values are arranged according to [b,g,r].
]
# If several color intervals are defined in color, they can all be split out
for (lower, upper) in color:
 # Create NumPy arrays
 lower = (lower, dtype = "uint8")#Color lower limit
 upper = (upper, dtype = "uint8")#Color cap
 
 # Find the corresponding color based on the threshold
 mask = (image, lower, upper)
 output = cv2.bitwise_and(image, image, mask = mask)
 
 # Show pictures
 ("images", ([image, output]))
 (0)

python-opencv颜色提取分割

This python-opencv color extraction segmentation method above is all I have shared with you.