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 cv2 | |
import numpy as np | |
import imutils | |
video='28.mp4' | |
# Create a VideoCapture object and read from input file | |
# If the input is the camera, pass 0 instead of the video file name | |
cap = cv2.VideoCapture(video) | |
cnt=0 |
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 keras import backend as K | |
K.clear_session() | |
latent_dim = 500 | |
# Encoder | |
encoder_inputs = Input(shape=(max_len_text,)) | |
enc_emb = Embedding(x_voc_size, latent_dim,trainable=True)(encoder_inputs) | |
#LSTM 1 | |
encoder_lstm1 = LSTM(latent_dim,return_sequences=True,return_state=True) |
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
ball_df.dropna(inplace=True) | |
print(ball_df) |
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
!rm -r ball/* | |
ball_df = pd.DataFrame(columns=['frame','x','y','w','h']) | |
for idx in range(len(frames)): | |
img= cv2.imread('frames/' + frames[idx]) | |
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) | |
gray = cv2.GaussianBlur(gray,(25, 25),0) | |
_ , mask = cv2.threshold(gray, 200, 255, cv2.THRESH_BINARY) | |
image, contours, _ = cv2.findContours(mask, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE) |
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 sklearn.metrics import classification_report | |
y_pred = rfc.predict(x_val) | |
print(classification_report(y_val,y_pred)) |
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 sklearn.ensemble import RandomForestClassifier | |
rfc = RandomForestClassifier(max_depth=3) | |
rfc.fit(x_tr,y_tr) |
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 sklearn.model_selection import train_test_split | |
x_tr,x_val,y_tr,y_val = train_test_split(features,labels, test_size=0.2, stratify=labels,random_state=0) |
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 cv2 | |
import numpy as np | |
import pandas as pd | |
folders=os.listdir('data/') | |
images=[] | |
labels= [] | |
for folder in folders: | |
files=os.listdir('data/'+folder) |
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
!rm -r patch/* | |
num=20 | |
cnt=0 | |
for i in range(len(contours)): | |
x,y,w,h = cv2.boundingRect(contours[i]) | |
numer=min([w,h]) | |
denom=max([w,h]) | |
ratio=numer/denom |
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_copy = np.copy(gray) | |
cv2.drawContours(img_copy, contours, -1, (0,255,0), 3) | |
plt.imshow(img_copy, cmap='gray') |
NewerOlder