강의 출처 : https://www.youtube.com/watch?v=XK3eU9egll8&t=19409s
import cv2
img = cv2.imread('img.jpg')
dst = cv2.resize(img, (400,400)) #width height 사이즈로 고정
cv2.imshow('img',img)
cv2.imshow('dst',dst)
cv2.waitKey(0)
cv2.destroyAllWindows()
import cv2
img = cv2.imread('img.jpg')
dst = cv2.resize(img, None, fx=0.5,fy=0.5) #x y를 0.5배씩 줄임
cv2.imshow('img',img)
cv2.imshow('dst',dst)
cv2.waitKey(0)
cv2.destroyAllWindows()
보간법
- 이미지를 늘리거나 줄일 때 자연스럽게 하기 위해 사용
- cv2.INTER_AREA : 크기를 줄일 때 사용
- cv2.INTER_CUBIC : 크기 늘릴 때 사용(속도 느리지만 퀄리티가 좋음)
- cv2.INTER_LINEAR : 크기 늘릴 때 사용(기본 값)
import cv2
img = cv2.imread('img.jpg')
dst = cv2.resize(img, None, fx=0.5,fy=0.5, interpolation=cv2.INTER_AREA) #x y를 0.5배씩 줄임
cv2.imshow('img',img)
cv2.imshow('dst',dst)
cv2.waitKey(0)
cv2.destroyAllWindows()
import cv2
img = cv2.imread('img.jpg')
dst = cv2.resize(img, None, fx=2,fy=2, interpolation=cv2.INTER_CUBIC) #x y를 0.5배씩 줄임
cv2.imshow('img',img)
cv2.imshow('dst',dst)
cv2.waitKey(0)
cv2.destroyAllWindows()
import cv2
cap = cv2.VideoCapture('video.mp4')
while cap.isOpened():
ret, frame = cap.read()
if not ret:
break
frame_resized = cv2.resize(frame, (400,400))
cv2.imshow('video',frame_resized)
if cv2.waitKey(1) == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
import cv2
cap = cv2.VideoCapture('video.mp4')
while cap.isOpened():
ret, frame = cap.read()
if not ret:
break
frame_resized = cv2.resize(frame, None, fx=0.5,fy=0.5,interpolation=cv2.INTER_AREA)
cv2.imshow('video',frame_resized)
if cv2.waitKey(1) == ord('q'):
break
cap.release()
cv2.destroyAllWindows()