python opencv inRange
python opencv inRange
import cv2
import numpy as np
# Load the image
img = cv2.imread('20220320151016_144_c.jpg')
hsv = cv2.cvtColor(img,cv2.COLOR_BGR2HSV)
# Define the lower and upper bounds of the blue color range
lower_blue = np.array([0, 0, 175])
upper_blue = np.array([15, 34, 255])
# Create a binary mask of the pixels within the blue color range
mask = cv2.inRange(hsv, lower_blue, upper_blue)
# Apply the mask to the original image to extract the blue pixels
blue_pixels = cv2.bitwise_and(img, img, mask=mask)
# Display the result
cv2.imshow('Blue Pixels', blue_pixels)
cv2.waitKey(0)
cv2.destroyAllWindows()
##################
QQ 3087438119

浙公网安备 33010602011771号