Files
ai-titration/test2.py
flt6 c1f33df66d 1
Former-commit-id: 1b34dc488f5306fcb5d20746c217255bb9ead3c5
2025-06-06 23:02:15 +08:00

11 lines
371 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import cv2
import numpy as np
cap = cv2.VideoCapture(2) # 使用摄像头0通常更稳定
im = cap.read()[1]
hsv = cv2.cvtColor(im, cv2.COLOR_BGR2HSV)
h, s, v = cv2.split(hsv)
pink_mask = (((h >= 300/360) | (h <= 20/360)) & (s >= 0.15) & (v >= 0.2))
cv2.imshow("Pink Mask", im * pink_mask[:,:,np.newaxis]) # 显示掩码
cv2.waitKey(0) # 等待按键
cap.release()