
pip 명령어를 통한 간단한 설치 지원pip install opencv-python
cv2.imread()cv2.imwrite()cv2.resize()cv2.rotate()cv2.cvtColor()cv2.VideoCapture()cv2.VideoWriter() cv2.ml.KNearest_create()cv2.ml.SVM_create()cv2.ml.ANN_MLP_create()model.train()model.predict()import cv2
image = cv2.imread('input.jpg')
blurred_image = cv2.GaussianBlur(image, (5, 5), 0)
cv2.imwrite('output.jpg', blurred_image)
cap = cv2.VideoCapture('data/input.mov')
fps = cap.get(cv2.CAP_PROP_FPS) # 초당 프레임 수
frame_count = int(cap.get(cv2.CAP_PROP_FRAME_COUNT)) # 총 프레임 수
width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)) # 프레임의 가로 크기
height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)) # 프레임의 세로 크기
fourcc = cv2.VideoWriter_fourcc(*'avc1') # MOV 코덱
out = cv2.VideoWriter('data/output.mov', fourcc, fps, (width, height))
frames = []
while cap.isOpened():
ret, frame = cap.read()
if not ret:
break
frames.append(frame)
# 첫 1초에 해당하는 프레임 추출
first_second_frames = frames[:int(fps)]
# 부메랑 효과(1초 재생 + 1초 역재생 순서로 3회 반복)
boomerang_frames = first_second_frames + first_second_frames[::-1] +\
first_second_frames + first_second_frames[::-1] +\
first_second_frames + first_second_frames[::-1]
for frame in boomerang_frames:
out.write(frame)
cap.release()
out.release()
cv2.destroyAllWindows()

*이 글은 제로베이스 데이터 취업 스쿨의 강의 자료 일부를 발췌하여 작성되었습니다.