Skip to content
Snippets Groups Projects
Commit 991d0c8d authored by zalonzo2's avatar zalonzo2
Browse files

Fixed color thresholding for the most part. Probably gonna have to incorporate...

Fixed color thresholding for the most part. Probably gonna have to incorporate brightness and saturation though, not just hue
parent c94de6b6
No related branches found
No related tags found
No related merge requests found
......@@ -225,19 +225,18 @@ def find_board(img):
def find_pieces(warped_img, sorted_warped_points):
hsv_img = cv2.cvtColor(warped_img, cv2.COLOR_BGR2HSV)
hsv_mask_sat = cv2.inRange(hsv_img[:,:,1], 70, 255) # saturation mask
# threshold to find strongest colors in image
hsv_mask_sat = cv2.inRange(hsv_img[:,:,1], 60, 255) # saturation mask
hsv_mask_bright = cv2.inRange(hsv_img[:,:,2], 100, 255) # brightness mask
hsv_mask = cv2.bitwise_and(hsv_mask_sat, hsv_mask_bright)
# Apply the mask to the entire HSV image
full_white = np.full_like(hsv_img, 255, dtype=np.uint8)
hsv_after = cv2.bitwise_and(hsv_img, full_white, mask=hsv_mask)
hsv_after = cv2.bitwise_and(hsv_img, hsv_img, mask=hsv_mask)
bgr_after = cv2.cvtColor(hsv_after, cv2.COLOR_HSV2BGR)
# create color histogram for each square and find candidate color, if any
hue_thresh_dict = {'red': (170,190), 'orange':(11,30), 'yellow': (31,40), 'green': (50,70), 'blue': (110,130), 'teal': (90,109),
'pink': (140,160)}
hue_thresh_dict = {'red': (170,190), 'orange':(8,20), 'yellow': (20,40), 'green': (50,70), 'blue': (105,120), 'purple': (120,140),
'teal': (90,105), 'pink': (140,170)}
count = 0
color_grid = []
......@@ -273,24 +272,24 @@ def find_pieces(warped_img, sorted_warped_points):
piece_found = False
if avg_hue != 0:
for color, (lower, upper) in hue_thresh_dict.items():
if lower <= avg_hue <= upper:
color_grid[i].append((color, avg_hue))
if lower <= avg_hue < upper:
color_grid[i].append((color, avg_hue, num_pixels))
piece_found = True
break # should only do this once
if piece_found == False:
color_grid[i].append((None,avg_hue))
color_grid[i].append((None, avg_hue, num_pixels))
count += 1
# print color_grid
# print color_grid. only print when the color is found a lot in the square (> 100 times)
for row in color_grid:
print("||", end="")
for tup in row:
if tup[1] == 0:
print("\t\t|", end="")
for color, avg_hue, num_pixels in row:
if num_pixels > 100:
print(color,int(avg_hue), "\t|", end="")
else:
print(tup[0],int(tup[1]), "\t|", end="")
print("\t\t|", end="")
print("|")
if show_cv:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment