250x250
Link
๋‚˜์˜ GitHub Contribution ๊ทธ๋ž˜ํ”„
Loading data ...
Notice
Recent Posts
Recent Comments
๊ด€๋ฆฌ ๋ฉ”๋‰ด

Data Science LAB

[Python] OpenCV ๊ธฐ์ดˆ 5 - ์ด๋ฏธ์ง€ ํฌ๊ธฐ์กฐ์ • (resize) ๋ณธ๋ฌธ

๐Ÿ–ฅ๏ธ Computer Vision/Opencv

[Python] OpenCV ๊ธฐ์ดˆ 5 - ์ด๋ฏธ์ง€ ํฌ๊ธฐ์กฐ์ • (resize)

ใ…… ใ…œ ใ…” ใ…‡ 2022. 8. 5. 15:29
728x90

1. ๊ณ ์ • ํฌ๊ธฐ๋กœ ์„ค์ •

cv2.resize( [์ด๋ฏธ์ง€], [(๊ฐ€๋กœ, ์„ธ๋กœ)])
import cv2 
img = cv2.imread('img.jpg')

dst = cv2.resize(img, (400,500)) # width, height ๊ณ ์ • ํฌ๊ธฐ

cv2.imshow('img',img)
cv2.imshow('resize',dst)

cv2.waitKey(0)
cv2.destroyAllWindows()

 

width, height ์ˆœ์„œ๋Œ€๋กœ ์›ํ•˜๋Š” ํฌ๊ธฐ ์„ค์ •

 

 

2. ๋น„์œจ๋กœ ์„ค์ •

cv2.resize( [์ด๋ฏธ์ง€], None, fx = ๋น„์œจ, fy = ๋น„์œจ)
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('resize',dst)

cv2.waitKey(0)
cv2.destroyAllWindows()

๊ฐ€๋กœ, ์„ธ๋กœ๊ฐ€ ๊ฐ๊ฐ 0.5๋ฐฐ๋กœ ์ค„์–ด๋“  ๊ฒƒ์„ ํ™•์ธ

 

3. ๋ณด๊ฐ„๋ฒ•

1. cv2.INTER_AREA : ํฌ๊ธฐ ์ค„์ผ ๋•Œ ์‚ฌ์šฉ
2. cv2.INTER_CUBIC : ํฌ๊ธฐ ๋Š˜๋ฆด ๋•Œ (์†๋„ ๋Š๋ฆผ, ํ€„๋ฆฌํ‹ฐ ์ข‹์Œ)
3. 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) # width, height ๊ณ ์ • ํฌ๊ธฐ

cv2.imshow('img',img)
cv2.imshow('resize',dst)

cv2.waitKey(0)
cv2.destroyAllWindows()

 

4. ๋™์˜์ƒ ํฌ๊ธฐ์กฐ์ •(๊ณ ์ • ํฌ๊ธฐ)

cap = cv2.VideoCapture('video.mp4')

while cap.isOpened():
    ret, frame = cap.read()
    if not ret:
        break
    
    frame_resized = cv2.resize(frame,(400,500))
    
    cv2.imshow('video',frame_resized)
    if cv2.waitKey(1) == ord('q'):
        break
    
cap.release()
cv2.destroyAllWindows()

์ด๋ฏธ์ง€ resize์™€ ๋น„์Šทํ•˜์ง€๋งŒ while๋ฌธ์„ ํ†ตํ•ด ๋ฐ˜๋ณตํ•˜์—ฌ ์ฒ˜๋ฆฌ

 

5. ๋™์˜์ƒ ํฌ๊ธฐ ์กฐ์ • (๋น„์œจ)

cap = cv2.VideoCapture('video.mp4')

while cap.isOpened():
    ret, frame = cap.read()
    if not ret:
        break
    
    frame_resized = cv2.resize(frame,None, fx=1.5, fy=1.5, interpolation=cv2.INTER_CUBIC)
    
    cv2.imshow('video',frame_resized)
    if cv2.waitKey(1) == ord('q'):
        break
    
cap.release()
cv2.destroyAllWindows()
728x90
Comments