out = cv2.VideoWriter(path,fourcc ,frame_rate,(1200,600))
# ...
while cap.isOpend():
ret, frame = cap.read()
if not ret:
break
out_frame = model(frame) #딥러닝 모델을 통해서 나온 프레임 결과 shape = (500,500)
out.write(out_frame)
위와 같이 영상을 불러온 다음에 각 프레임 별로 딥러닝 모델을 돌려서 얻어진 output으로 다시 영상을 제작하는 코드를 짜고 있었는데, 이상하게 만들어진 영상을 틀어보면 "재생할 수 없는 영상" 이라고 나오면서 재생이 안됨.
코드가 실행중에 에러가 나지도 않고 동영상 파일도 잘 나와있는데 이상하게 재생만 안됨.,,
대체 왜 이럴까 이래저래 열심히 뜯어보다 보니
VideoWriter에 입력되어 있는 shape은 (1200,600)
하지만, 내가 저장하려고 하는 out_frame의 shape은(500,500)
그렇다. 이 shape이 달라서 재생할 수 없는 영상이 계속 나온 것이었다.
그러면 에러라도 내주던가,, 왜 묵묵히 헛짓을 하는지 이해 할 수 없었다,,
out = cv2.VideoWriter(path,fourcc ,frame_rate,(1200,600))
# ...
while cap.isOpend():
ret, frame = cap.read()
if not ret:
break
out_frame = model(frame) #딥러닝 모델을 통해서 나온 프레임 결과 shape = (500,500)
out_frame_reshape = cv2.resize(out_frame, dsize=(1200, 600), fx=0, fy=0)
out.write(out_frame_reshape)
위와 같이 shape을 맞춰주니 아주 잘 되었다.,
'즐거운 에러 대잔치' 카테고리의 다른 글
skimage를 import 하면 커널이 자꾸 죽는 현상 (0) | 2023.11.06 |
---|---|
RTX 3090, 3080을 위한 pytorch 버전 (0) | 2023.10.27 |
Failed to load OpenH264 library: openh264, Could not open codec libopenh264 (0) | 2023.10.18 |
RuntimeError: Input type (torch.cuda.FloatTensor) and weight type (torch.FloatTensor) should be the same (0) | 2023.10.17 |
OSError: [Errno 28] No space left on device (2) | 2023.10.17 |