画像のリサイズ

2015/8/13

Python2.7.6, OpenCV 3.0.0

import cv2

im = cv2.imread('test.jpg')
height = im.shape[0]
width = im.shape[1]
half_size = cv2.resize(im, (width/2, height/2) )


Webカメラで取得した画像のリサイズ

# -*- coding: utf-8 -*-
import cv2

capture = cv2.VideoCapture(0)
capture.set(3, 2016)  # Width
capture.set(4, 1512)  # Height
capture.set(5, 15)   # FPS

if capture.isOpened() is False:
    raise("IO Error")

cv2.namedWindow("Capture", cv2.WINDOW_AUTOSIZE)

while True:

    ret, image = capture.read()

    if ret == False:
        continue

    im_resize = cv2.resize(image, (640,480))
    cv2.imshow("Capture", im_resize)

    if cv2.waitKey(33) >= 0:
        break

cv2.destroyAllWindows()

何かキーボードを押して終了

OpenCV API Reference » imgproc. Image Processing » Geometric Image Transformations http://docs.opencv.org/modules/imgproc/doc/geometric_transformations.html#resize