OpenCV by python
install (Ubuntu 16.04)
pip3 install opencv-python
start using
import cv2 import numpy as np
Functiond of python opencv
画像ファイルの読み込み / importing an image file
cv2.imread("test.jpg") # RGB 全てを読み込み cv2.imread("test.jpg", 0) # 最初のチャンネルだけを読み込み。
リサイズ
cv2.resize(img, (2000, 2000))
アフィン変換(回転, 拡大縮小, 平行移動などの組み合わせ)
cv2.warpAffine
HSV変換
img_hsv=cv2.cvtColor(img_bgr, cv2.COLOR_BGR2HSV)
カラーをグレースケールに
img_gray=cv2.cvtColor(img_bgr, cv2.COLOR_BGR2GRAY)
チャンネルの入れ替え
img_rgb=cv2.cvtColor(img_bgr, cv2.COLOR_BGR2RGB)
ガウスぼかし
cv2.GaussianBlur(img_rgb, (15,15), 0)
位相限定相関法 (Phase Only Correlation: POC)
- マニュアル
- python opencvのPOCは, 単バンドかつ実数値関数が前提であることに注意しよう!!
import cv2 import numpy as np sample1=cv2.imread("sample1.jpg", 0) # POC is only ok for single-band images. No multi-band images! sample2=cv2.imread("sample2.jpg", 0) cv2.phaseCorrelate(sample1.astype(np.float32), sample2.astype(np.float32)) # it does not work for int array
output:
((-19.98326409703651, -10.016491571299696), 0.8107634333372116) ... ((x displacement, y displacement), response) ... If you displace sample 1 with this vector, you get sample2. ... "response" (from 0 to 1) is something like a correlation coefficient (perhaps).
Keyword(s):
References:[とらりもんHOME]