Fix video
This commit is contained in:
parent
b3e1d26a5e
commit
75157abaf2
38
main.py
38
main.py
@ -30,7 +30,7 @@ if __name__ == "__main__":
|
||||
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=1.5)
|
||||
st.write(f"Załadowano {num} klatek")
|
||||
classifications = []
|
||||
for img in result:
|
||||
@ -54,34 +54,40 @@ if __name__ == "__main__":
|
||||
text = ''
|
||||
font = cv.FONT_HERSHEY_SIMPLEX
|
||||
width, height, layers = result[0].shape
|
||||
fourcc = cv.VideoWriter_fourcc(*'mp4v')
|
||||
new_video_cap = cv.VideoCapture(tfile.name)
|
||||
|
||||
new_video = cv.VideoWriter("output_video.mp4", fourcc, 30.0, (width, height), 3)
|
||||
out = cv.VideoWriter("output_video.mp4",cv.VideoWriter_fourcc(*'mp4v'), 30, (300, 300))
|
||||
print(f"VIDEO CAP {result[0].shape}")
|
||||
|
||||
while True:
|
||||
ret, frame = new_video_cap.read()
|
||||
if ret == False:
|
||||
break
|
||||
image =cv.resize(frame, [300, 300])
|
||||
|
||||
image = cv.cvtColor(image, cv.COLOR_RGB2BGR)
|
||||
cv.putText(image,
|
||||
last_letter,
|
||||
(50, 50),
|
||||
font, 2,
|
||||
(255, 255, 255),
|
||||
6,
|
||||
cv.LINE_4)
|
||||
cv.imwrite(f'frames/post/{i}.jpg', image)
|
||||
|
||||
if i in frames:
|
||||
print(i)
|
||||
frame_index = frames.index(i)
|
||||
letter = classifications[frame_index]
|
||||
last_letter = letter
|
||||
cv.putText(frame,
|
||||
last_letter,
|
||||
(50, 50),
|
||||
font, 1,
|
||||
(0, 255, 255),
|
||||
2,
|
||||
cv.LINE_4)
|
||||
img_pil = Image.fromarray(img)
|
||||
frame = np.array(img_pil)
|
||||
img = cv.cvtColor(frame, cv.COLOR_BGR2RGB)
|
||||
new_video.write(img)
|
||||
|
||||
img = cv.imread(f"frames/post/{i}.jpg")
|
||||
out.write(img)
|
||||
|
||||
i += 1
|
||||
video_cap.release()
|
||||
new_video_cap.release()
|
||||
new_video.release()
|
||||
|
||||
out.release()
|
||||
video_file = open('output_video.mp4', 'rb')
|
||||
|
||||
st.video(video_file, format="video/mp4")
|
||||
|
Loading…
Reference in New Issue
Block a user