1. 세팅
I also had the same problem with opencv-python-4.6.0.66
I solved this error by just downgrading opencv. you can follow this command.
pip install opencv-python==4.5.5.64
2. 읽기
import cv2, os
v_cap = cv2.VideoCapture(os.path.join(os.path.curdir, 'test.mp4'))
cnt = 0
while v_cap.isOpened():
ret, image = v_cap.read()
image = cv2.resize(image, (1920, 1080))
if int(v_cap.get(1)) % 10 == 0:
cv2.imwrite(os.path.join(os.path.curdir, 'capture', '%d.png' % v_cap.get(1)), image)
print("Frame Captured: %d" % v_cap.get(1))
cnt += 1
v_cap.release()
3. 저장
pathIn= './ims/2/'
pathOut = './ims/2/gan.mp4'
fps = 30
import cv2
frame_array = []
for idx , path in enumerate(paths) :
if (idx % 2 == 0) | (idx % 5 == 0) :
continue
img = cv2.imread(path)
height, width, layers = img.shape
size = (width,height)
frame_array.append(img)
out = cv2.VideoWriter(pathOut,cv2.VideoWriter_fourcc(*'DIVX'), fps, size)
for i in range(len(frame_array)):
# writing to a image array
out.write(frame_array[i])
out.release()
mjpg -> avi 파일 생성
'AI > Framework' 카테고리의 다른 글
[MMDetection] Config File Structure (0) | 2021.12.28 |
---|---|
[Detectron2] 설치 (0) | 2021.11.23 |
[Detectron2] Densepose COCO 데이터셋 (0) | 2021.11.23 |
[Keras] RNN 구현하기 (0) | 2021.07.07 |
[scikit] LabelEncoder (0) | 2021.02.13 |