This file contains hidden or 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
| #Get the image from the current working directory | |
| img_name = glob.glob('*.jpg')[0] | |
| #Load the image into my working environment | |
| img = cv2.imread(img_name) | |
| #Show the image | |
| plt.imshow(img) |
This file contains hidden or 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(): |
This file contains hidden or 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
| def getJerseyColorsFromGame(jsonPath,MP4Path,whichVideo,nClusters): | |
| mp4_list = getListOfFiles(MP4Path , ".mp4") | |
| n_mp4 = len(mp4_list) | |
| df_list = [] | |
| for vid in range(n_mp4): | |
| jerseyColor_df = getJerseyColorsFromMP4(jsonPath,MP4Path,vid,nClusters) | |
| df_list.append(jerseyColor_df) | |
| allJerseyColors = pd.concat(df_list) | |
| return allJerseyColors |
This file contains hidden or 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
| def getJerseyColorsFromMP4(jsonPath,MP4Path,whichVideo,nClusters): | |
| #Make the list of mp4 and json files from each camera | |
| print('Retrieving MP4 and JSON files...') | |
| mp4List = getListOfFiles(MP4Path , ".mp4") | |
| jsonList = getListOfFiles(jsonPath , ".json") | |
| #Find the json file to use for the current video | |
| jval = matchJSON2MP4(jsonList, jsonPath, mp4List, MP4Path, whichVideo) | |
| #Get json dictionary of all bounding boxes in video |
This file contains hidden or 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
| def crop_image(image,howMuch): | |
| """ | |
| Args: | |
| img : (array) image of player bounding box | |
| howMuch : (int) percent of image to crop (between 0 and 100) | |
| Returns: | |
| cropped_img : (array) cropped image | |
| """ | |
| val = howMuch/100 | |
| cropped_img = image[0:int(image.shape[0]*val),0:int(image.shape[0])] |
This file contains hidden or 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
| def KMeansMaskGreen(img, clusters, lowHue, highHue, lowSat, highSat, loBright, hiBright): | |
| """ | |
| Args: | |
| path2img : (str) path to cropped player bounding box | |
| clusters : (int) how many clusters to use for KMEANS | |
| Returns: | |
| rgb_array : (tuple) Dominant colors in image in RGB format | |
| """ | |
| org_img = img.copy() | |
| #print('Org image shape --> ',img.shape) |
This file contains hidden or 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
| def KMeansImage(img, clusters): | |
| """ | |
| Args: | |
| path2img : (str) path to cropped player bounding box | |
| clusters : (int) how many clusters to use for KMEANS | |
| Returns: | |
| rgb_array : (tuple) Dominant colors in image in RGB format | |
| """ | |
| org_img = img.copy() | |
| #Convert image to HSV |
This file contains hidden or 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
| #Extract bounding box coordinates for a specific bounding box in current frame from json | |
| def makeRectangleFromJSON(bb_dict,whichBB): | |
| """ | |
| Args: | |
| bb_dict: (dict) dictionary from json file | |
| whichBB: (int) what bounding box is being processed | |
| Returns: | |
| x1 ,y1 ,x2 ,y2: (tuple) tuple containing pixel coordinates for the upper-left and lower-right corners of the bounding box | |
| """ | |
| x1 ,y1 ,x2 ,y2 = bb_dict[whichBB][0],bb_dict[whichBB][1],bb_dict[whichBB][2],bb_dict[whichBB][3] |
This file contains hidden or 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
| #Extract bounding boxes for a given frame from json | |
| def get_bb4frame(bb_dict,frame_index): | |
| """ | |
| Args: | |
| bb_dict: (dict) dictionary from json file | |
| frame: (int) what frame is being processed | |
| Returns: | |
| nDetections: (int) Number of bounding boxes in frame | |
| """ | |
This file contains hidden or 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
| #Find first frame that contains detections | |
| def findFrameSpacing(bb_dict): | |
| """ | |
| Args: | |
| bb_dict: (dict) dictionary from json file | |
| Returns: | |
| spacing: (int) Spacing between frames in json | |
| """ | |
| frame0 = bb_dict['frames'][0]['frame_index'] |