-
OpenCv로비디오(영상) 이미지로 출력 후 저장하기카테고리 없음 2020. 3. 10. 15:56
Progress
1. 불러올 파일 경로 지정
path_dir = './none/otherss'
cnt = 0
file_list = os.listdir(path_dir)2. 파일 읽기
for i in file_list:
VideoFilePath = path_dir+'/'+ i
vidcap = cv2.VideoCapture(VideoFilePath)
count = 03.이미지 resize
try:
image = cv2.resize(image, dsize=(1920, 1080), interpolation=cv2.INTER_AREA)
except:
cnt += 1
if cnt > 1:
cnt = 0
break4.캡쳐된 이미지를 5/1로 나누어서 저장
try:
if (int(vidcap.get(1)) % 5 == 0):
cv2.imwrite("./second/none_origin/"+i+".%d.jpg" % count, image)
count += 1
else:
continue
except:
breakOutput
총 300개의 영상(약 10초)에서 20000개 이미지 추출
TroubleShoot
1초당 5Frame을 가져오려다 보니 마지막 나눗셈이 딱 떨어지면 예외를 주었음에도 불구하고 오류가남
->count를 이용해서 오류가 나면(마지막 이미지 저장) 그 후 다음이미지로 넘어가서 초기화 시킴