Last active
October 21, 2022 03:36
-
-
Save victormurcia/0e24abc707db27e3ce11a392d87d2b51 to your computer and use it in GitHub Desktop.
gui for viz of clustering results
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Make image bigger | |
def makeBigger(img): | |
dim = (300, 200) #(width, height) | |
# resize image | |
resized = cv2.resize(img, dim, interpolation = cv2.INTER_AREA) | |
return resized | |
# empty function called when trackbar moves | |
def emptyFunction(): | |
pass | |
#Panel to cycle through player bounding boxes and 2 dominant colors in each BB | |
def main(df): | |
# blackwindow having 3 color chanels | |
windowName ="Open CV Color Palette" | |
# window name | |
cv2.namedWindow(windowName) | |
# Define trackbar | |
rows = df.shape[0]-1 | |
cv2.createTrackbar('BB ID', windowName, 0, rows, emptyFunction) | |
#previousTrackbarValue = -1 # Set this to -1 so the threshold will be applied and the image displayed the first time through the loop | |
# Used to open the window until press ESC key | |
while(True): | |
if cv2.waitKey(1) == 27: | |
break | |
# Which row to look at in dataframe? | |
bbID = cv2.getTrackbarPos('BB ID', windowName) | |
print(bbID) | |
fName = df.iloc[bbID]['File Name'] | |
print(fName) | |
bb = cv2.imread(fName) | |
bb = makeBigger(bb) | |
bbsize = bb.shape | |
image1 = np.zeros((bbsize[0], bbsize[1], 3), np.uint8) | |
image2 = np.zeros((bbsize[0], bbsize[1], 3), np.uint8) | |
image3 = np.zeros((bbsize[0], bbsize[1], 3), np.uint8) | |
# values of blue, green, red extracted from the dataframe | |
hex_string1 = df.iloc[bbID]['Jersey Color 1'] | |
hex_string2 = df.iloc[bbID]['Jersey Color 2'] | |
hex_string3 = df.iloc[bbID]['Jersey Color 3'] | |
rgb1 = hex_to_rgb(hex_string1) | |
blue1 = rgb1[2] | |
green1 = rgb1[1] | |
red1 = rgb1[0] | |
rgb2 = hex_to_rgb(hex_string2) | |
blue2 = rgb2[2] | |
green2 = rgb2[1] | |
red2 = rgb2[0] | |
rgb3 = hex_to_rgb(hex_string3) | |
blue3 = rgb3[2] | |
green3 = rgb3[1] | |
red3 = rgb3[0] | |
# font | |
font = cv2.FONT_HERSHEY_SIMPLEX | |
# org | |
org = (75, 50) | |
# fontScale | |
fontScale = 1 | |
# Blue color in BGR | |
color = (255, 0, 0) | |
# Line thickness of 2 px | |
thickness = 2 | |
image1[:] = [blue1, green1, red1] | |
image2[:] = [blue2, green2, red2] | |
image3[:] = [blue3, green3, red3] | |
# Using cv2.putText() method | |
image1 = cv2.putText(image1, hex_string1, org, font, fontScale, color, thickness, cv2.LINE_AA) | |
image2 = cv2.putText(image2, hex_string2, org, font, fontScale, color, thickness, cv2.LINE_AA) | |
image3 = cv2.putText(image3, hex_string3, org, font, fontScale, color, thickness, cv2.LINE_AA) | |
# concatenate image Vertically | |
verti = np.concatenate((bb, image1, image2, image3), axis=0) | |
cv2.imshow(windowName, verti) | |
cv2.destroyAllWindows() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment