I'm fairly new with Python and trying to code a way a PiCamera to pick up on different colors and react based off of that. My current attempt for each color is to take a picture and detect the color involved. Some example code is below.
def red_detect():
# initialize the camera and grab a reference to the raw camera capture
rawCapture = PiRGBArray(camera, size=(640, 480))
# allow the camera to warmup
time.sleep(0.1)
# grab an image from the camera
camera.capture(rawCapture, format="bgr")
image = rawCapture.array
# Convert BGR to HSV
hsv = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
lower_red = np.array([161, 155, 84],np.uint8)
upper_red = np.array([179, 255, 255],np.uint8)
red_mask = cv2.inRange(hsv, lower_red, upper_red)
red = cv2.bitwise_and(image, image, mask=red_mask)
return 255 in cv2.inRange(hsv, lower_red, upper_red)
and then that code will be evaluated with an if statement such as
if green == True:
However, all of my colors are coming back as True. Am I approaching taking a picture wrong?