I have been tasked with writing a program to detect and differentiate three "targets" from altitude for my rocketry club. These targets are 3 large tarps for which I have the RGB values.
When I started this project, I overlaid a GoogleEarth image with 3 rectangles using the exact RGB values of the tarps, and my code worked flawlessly. However, when I actually received the tarps and began taking pictures of them on the ground, my code does not recognize the tarps with the RGB color boundaries I prescribed.
I have tried to convert the images to HSV color space, but I just cannot get it to work. I've also thought about using contours - trying to get the program to recognize the 4 straight lines that bound each target. The problem is that these images will be taken outdoors, so I have no control over the ambient lighting conditions.
Does anyone have any ideas as to what colorspace or computer vision method would allow me to identify and differentiate between these targets regardless of outdoor lighting?
Original Image After Processing
Actual Tarps to be Identified

Here is the code:
import cv2
import numpy as np
image = cv2.imread('2000 ft.png', 1)
#hsv_img = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
#cv2.waitKey(0)
cv2.destroyAllWindows()
# define target strings
targ = ['Target 1 - Blue', 'Target 2 - Yellow', 'Target 3 - Red']
i = 0
# BGR boundaries of colors
boundaries = [
# 0, 32, 91
([40, 10, 0], [160, 60, 20]),
# 255, 209, 0
([0, 180, 220], [20, 230, 255]),
# 166, 9, 61
([40, 0, 150], [80, 30, 185]),
]
# colors for rectangle outlines
colors = [
([91, 32, 0]), ([0, 209, 255]), ([61, 9, 166])
]
# # loop over the boundaries
for (lower, upper) in boundaries:
# create NumPy arrays from the boundaries
lower = np.array(lower, dtype = "uint16")
upper = np.array(upper, dtype = "uint16")
# find the colors within the specified boundaries and apply
# the mask
mask = cv2.inRange(image, lower, upper)
output = cv2.bitwise_and(image, image, mask = mask)
# frame threshold
frame_threshed = cv2.inRange(image, lower, upper)
imgray = frame_threshed
# iteratively view masks
cv2.imshow('imgray',imgray)
cv2.waitKey(0)
cv2.destroyAllWindows()
ret,thresh = cv2.threshold(frame_threshed,127,255,0)
contours, hierarchy = cv2.findContours(thresh,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
# Find the index of the largest contour
areas = [cv2.contourArea(c) for c in contours]
max_index = np.argmax(areas)
cont=contours[max_index]
# putting text and outline rectangles on image
x,y,w,h = cv2.boundingRect(cont)
cv2.rectangle(image,(x,y),(x+w,y+h),colors[i],2)
cv2.putText(image, targ[i], (x-50, y-10), cv2.FONT_HERSHEY_PLAIN, 0.85, (0, 255, 0))
# cv2.rectangle(image,(x,y),(x+w,y+h),(0,255,0),4)
cv2.imshow("Show",image)
cv2.waitKey()
cv2.destroyAllWindows()
i += 1
cv2.destroyAllWindows()
I am writing this code in Python, which I have a good amount of experience in, using the OpenCV library which I do not have much experience in. Any help would be greatly appreciated!
