Merge branch 'master' of git.wmi.amu.edu.pl:s444463/projekt_widzenie

This commit is contained in:
Mikołaj Pokrywka 2023-01-31 17:51:12 +01:00
commit b3e1d26a5e
2 changed files with 13 additions and 3 deletions

12
main.py
View File

@ -28,6 +28,8 @@ 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)
font = cv.FONT_HERSHEY_SIMPLEX
result, num, frames = segment_video(video_cap, fps=3) result, num, frames = segment_video(video_cap, fps=3)
st.write(f"Załadowano {num} klatek") st.write(f"Załadowano {num} klatek")
classifications = [] classifications = []
@ -38,8 +40,15 @@ if __name__ == "__main__":
img_np = np.asarray(img2) img_np = np.asarray(img2)
classification = classify(img_np[:,:,::-1], model) classification = classify(img_np[:,:,::-1], model)
classifications.append(classification) classifications.append(classification)
cv.putText(img_skeleton,
classification,
(20, 50),
font, 2,
(255, 255, 255),
6,
cv.LINE_4)
st.image(img_skeleton[:,:,::-1]) st.image(img_skeleton[:,:,::-1])
st.write(classification)
i = 0 i = 0
last_letter = '' last_letter = ''
text = '' text = ''
@ -59,7 +68,6 @@ if __name__ == "__main__":
frame_index = frames.index(i) frame_index = frames.index(i)
letter = classifications[frame_index] letter = classifications[frame_index]
last_letter = letter last_letter = letter
st.write(last_letter)
cv.putText(frame, cv.putText(frame,
last_letter, last_letter,
(50, 50), (50, 50),

View File

@ -17,6 +17,7 @@ def segment_video(video, fps=5):
n = int(real_fps / fps) n = int(real_fps / fps)
result = [] result = []
frames_nums = []
i=0 i=0
num = 0 num = 0
while True: while True:
@ -25,10 +26,11 @@ def segment_video(video, fps=5):
break break
if i % n == 0: if i % n == 0:
result.append(frame) result.append(frame)
frames_nums.append(i)
num += 1 num += 1
i += 1 i += 1
return result, num return result, num, frames_nums
def save_frames(frames, dir): 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)