0
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

OpenCVの基本コード(python)

Last updated at Posted at 2021-01-13

はじめに

pythonのopencvコード一覧。まだまだ書き足すつもりです。

ライブラリの読み込み

import cv2 # opencv
import numpy as np # numpy

画像の読み込み

img = cv2.imread('/home/kono/画像/image01.jpg') # imgに入れる

画像の書き出し

cv2.imwrite("/home/kono/画像/output_img.jpg", img)

画像の表示(不確定)

cv2.namedWindow('img', cv2.WINDOW_NORMAL) # ウインドウの大きさ設定
cv2.imshow('img', img)
cv2.waitKey(2000) # 画像の表示時間
cv2.waitKey(1)
cv2.destroyAllWindows() # ウインドウをすべて閉じる
cv2.waitKey(1)

ガウシアンフィルタ

gaus = cv2.GaussianBlur(img, ksize=(3, 3), sigmaX=10)

カーネルサイズと標準偏差x, yを指定

HSVでマスク処理

hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV) # HSV変換
lower_color = np.array([10, 100, 100]) # HSV下の値
upper_color = np.array([20, 240, 160]) # HSV上の値
hsv_mask = cv2.inRange(hsv, lower_color, upper_color) # 与えられた範囲で二値化
output = cv2.bitwise_and(img, img, mask = hsv_mask) # マスク
0
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?