본문 바로가기

AI/Framework

[pip] import cv2 동영상 세팅/읽기/저장

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

 

 

 

AttributeError: partially initialized module 'cv2' has no attribute 'gapi_wip_gst_GStreamerPipeline' (most likely due to a circu

This happened out of the blue, I was able to import cv2 but now I get 'AttributeError: partially initialized module 'cv2' has no attribute 'gapi_wip_gst_GStreamerPipeline' (most likely due to a cir...

stackoverflow.com

 

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()

 

 

[Study Log] Python 영상파일 프레임별 이미지 추출

Study Concept *) 목적: 음악방송 아이돌별 얼굴 인식을 위한 CNN 얼굴인식 프로젝트 중 학습 Dev Concept *) Python opencv 라이브러리 과정 #reference: deftkang.tistory.com/182 [Python] 파이썬으로 동영상 이미지 추출

devwaffle.tistory.com

 

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()
 

[OpenCV] 파이썬으로 동영상 프레임 초단위 저장/캡처하기 (Save Video Frame per Second by Python)

오늘은 동영상(mp4) 파일을 OpenCV를 사용하여 초단위로 저장하는 방법을 알아보도록 하겠습니다 기본적으로는 프레임 단위로 저장이 가능하나 본 예제에서는 다루고자 하는 동영상이 1초에 몇 프

thinking-developer.tistory.com

mjpg -> avi 파일 생성

 

 

Saving a Video using OpenCV - GeeksforGeeks

A Computer Science portal for geeks. It contains well written, well thought and well explained computer science and programming articles, quizzes and practice/competitive programming/company interview Questions.

www.geeksforgeeks.org

 

'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