#author("2018-07-25T23:45:45+09:00","default:Miyashita","Miyashita")
#author("2019-05-14T09:50:12+09:00","default:Miyashita","Miyashita")
*画像の拡大・縮小 [#o089014b]
**画像の縮小 [#hda0a7b1]
まず,OpenCVを使って読み込み,画素数を取得する.
#codeprettify(lang-python){{
まず,OpenCVを使って読み込み,サイズを取得する.
#codeprettify{{
import cv2
imgorg = cv2.imread('example.jpg')
h, w = imgorg.shape[:2]
}}
例えば,縦横比を変えずにこれを256x256以下になるまで1/2に縮小したければ,
#codeprettify(lang-python){{
#codeprettify{{
while h >= 256 or w >= 256:
    imgorg = cv2.resize(imgorg, (int(w/2), int(h/2)), interpolation = cv2.INTER_LINEAR) 
    h, w = imgorg.shape[:2]
}}
縮小するにしても間引きするのか内挿するのかいくつかあるため,interpolationでパターンを指定できる.上記は内挿.~
拡大も大体同じ.

Front page   Edit Diff Attach Copy Rename Reload   New List of pages Search Recent changes   Help   RSS of recent changes