Reputation: 35
How to detect (True/False) if the frame contains at least one for example rgb(213, 39, 27) pixel? I want to process frame only when the detection is true.
import cv2
VIDEO_URL = ''
cap = cv2.VideoCapture(VIDEO_URL)
fps = cap.get(cv2.CAP_PROP_FPS)
wait_ms = int(1000/fps)
while True:
ret, frame = cap.read()
img = cv2.cvtColor(frame, cv2.IMREAD_COLOR)[815:970, 360:1920]
#image processing here
if cv2.waitKey(wait_ms) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
Upvotes: 0
Views: 1749
Reputation: 139
You can use hsv images to detect any color.
Eg-Let You want to identify blue color in your image - Include this code inside your while loop.
hsvimg = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
lb=np.array([94,80,2])
ub=np.array([126,255,255])
mask = cv2.inRange(hsvimg, lb, ub)
if 255 in mask:
print("Blue color present")
This code determines the blue color. You can find any other color by changing the HSV range.
Upvotes: 1