This commit is contained in:
Andrzej Preibisz 2023-01-30 16:28:34 +01:00
parent 80ac412a5a
commit cb02cd0eaa
2 changed files with 11 additions and 5 deletions

12
main.py
View File

@ -5,9 +5,13 @@ import cv2 as cv
import tempfile import tempfile
import numpy as np import numpy as np
import tensorflow as tf import tensorflow as tf
from crop_hand_skeleton import crop_hand
from cvzone.HandTrackingModule import HandDetector
if __name__ == "__main__": if __name__ == "__main__":
detector = HandDetector(maxHands=1, mode=True, detectionCon=0.7, minTrackCon=0.8)
model = tf.keras.models.load_model('model_pred/VGG16_sign_char_detection_model') model = tf.keras.models.load_model('model_pred/VGG16_sign_char_detection_model')
st.set_page_config( st.set_page_config(
page_title="Projekt widzenie" page_title="Projekt widzenie"
) )
@ -22,13 +26,15 @@ if __name__ == "__main__":
tfile = tempfile.NamedTemporaryFile(delete=False) tfile = tempfile.NamedTemporaryFile(delete=False)
tfile.write(upload_movie.read()) tfile.write(upload_movie.read())
video_cap = cv.VideoCapture(tfile.name) video_cap = cv.VideoCapture(tfile.name)
result, num = segment_video(video_cap, fps=1.5) result, num = segment_video(video_cap, fps=10)
st.write(f"Załadowano {num} klatek") st.write(f"Załadowano {num} klatek")
for img in result: for img in result:
img2= cv.resize(img,dsize=(224,224)) img_skeleton = crop_hand(img, detector)
img2= cv.resize(img_skeleton,dsize=(224,224))
#breakpoint()
img_np = np.asarray(img2) img_np = np.asarray(img2)
classification = classify(img_np[:,:,::-1], model) classification = classify(img_np[:,:,::-1], model)
st.image(img[:,:,::-1]) st.image(img_skeleton[:,:,::-1])
st.write(classification) st.write(classification)

View File

@ -1,7 +1,7 @@
import cv2 import cv2
import tensorflow as tf import tensorflow as tf
import numpy as np import numpy as np
from crop_hands_skeleton import crop_hands from crop_hand_skeleton import crop_hand
from cvzone.HandTrackingModule import HandDetector from cvzone.HandTrackingModule import HandDetector
class_names = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'del', 'nothing', 'space'] class_names = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'del', 'nothing', 'space']
@ -34,7 +34,7 @@ def save_frames(frames, dir):
detector = HandDetector(maxHands=1, mode=True, detectionCon=0.7, minTrackCon=0.8) detector = HandDetector(maxHands=1, mode=True, detectionCon=0.7, minTrackCon=0.8)
for i, frame in enumerate(frames): for i, frame in enumerate(frames):
print(i) print(i)
cv2.imwrite(f"{dir}/frame{i}.jpg", crop_hands(frame, detector)) cv2.imwrite(f"{dir}/frame{i}.jpg", crop_hand(frame, detector))
def classify(img, model): def classify(img, model):