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
bbox=outputs['instances'].pred_boxes.tensor.cpu().numpy() | |
print(bbox) |
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
classes=outputs['instances'].pred_classes.cpu().numpy() | |
print(classes) |
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
#frame rate of a video | |
FPS=cap.get(cv2.CAP_PROP_FPS) | |
print(FPS) |
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
#read an image | |
img = cv2.imread("frames/30.png") | |
#pass to the model | |
outputs = predictor(img) |
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
%%time | |
frames = os.listdir('frames/') | |
frames.sort(key=lambda f: int(re.sub('\D', '', f))) | |
frame_array=[] | |
for i in range(len(frames)): | |
#reading each files | |
img = cv2.imread('frames/'+frames[i]) |
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
from tqdm import tqdm | |
thresh=100 | |
_ = [find_closest_people(names[i],thresh) for i in tqdm(range(len(names))) ] |
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
def find_closest_people(name,thresh): | |
img = cv2.imread('frames/'+name) | |
outputs = predictor(img) | |
classes=outputs['instances'].pred_classes.cpu().numpy() | |
bbox=outputs['instances'].pred_boxes.tensor.cpu().numpy() | |
ind = np.where(classes==0)[0] | |
person=bbox[ind] | |
midpoints = [mid_point(img,person,i) for i in range(len(person))] | |
num = len(midpoints) |
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
import os | |
import re | |
names=os.listdir('frames/') | |
names.sort(key=lambda f: int(re.sub('\D', '', f))) |
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
img = change_2_red(img,person,p1,p2) | |
plt.figure(figsize=(20,10)) | |
plt.imshow(img) |
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
def change_2_red(img,person,p1,p2): | |
risky = np.unique(p1+p2) | |
for i in risky: | |
x1,y1,x2,y2 = person[i] | |
_ = cv2.rectangle(img, (x1, y1), (x2, y2), (255,0,0), 2) | |
return img |