OpenCV basic code (python)

Introduction

python opencv code list. I will add more.

Loading the library

import cv2 # opencv
import numpy as np # numpy

Loading images

img = cv2.imread('/home/kono/image/image01.jpg') #Put in img

Export image

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

Image display (uncertain)

cv2.namedWindow('img', cv2.WINDOW_NORMAL) #Window size setting
cv2.imshow('img', img)
cv2.waitKey(2000) #Image display time
cv2.waitKey(1)
cv2.destroyAllWindows() #Close all windows
cv2.waitKey(1)

Gaussian filter

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

Specify kernel size and standard deviation x, y

Mask processing with HSV

hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV) #HSV conversion
lower_color = np.array([10, 100, 100]) #Value below HSV
upper_color = np.array([20, 240, 160]) #Value on HSV
hsv_mask = cv2.inRange(hsv, lower_color, upper_color) #Binarization within a given range
output = cv2.bitwise_and(img, img, mask = hsv_mask) #mask

Recommended Posts

OpenCV basic code (python)
[Python] Using OpenCV with Python (Basic)
Basic study of OpenCV with Python
RF Python Basic_01
Python2.7 + CentOS7 + OpenCV3
python character code
Basic Python writing
OpenCV Samples (Python)
[Note] openCV + python
RF Python Basic_02
Python basic course (12 functions)
Python basic grammar / algorithm
Python Basic Course (7 Dictionary)
python openCV installation (memo)
Python basic course (2 Python installation)
Basic sorting in Python
Binarization with OpenCV / Python
Python basic course (9 iterations)
Python code acceleration approach
Rewrite Python2 code to Python3 (2to3)
[python] class basic methods
infomap python draw code
Python Basic Course (11 exceptions)
Before writing Python code
Summary about Python3 + OpenCV3
Python basic course (6 sets)
Python3 cheat sheet (basic)
Introduction to OpenCV (python)-(2)
About Python3 character code
Python Basic Course (Introduction)
OpenCV3 Python API list
Python basic memorandum part 2
python basic on windows ②
Python basic memo --Part 2
Python basic course (13 classes)
Python basic grammar note (4)
Python basic grammar note (3)
Python OpenCV tutorial memo
Python, OpenCV camera capture
Basic knowledge of Python
Python basic grammar memo
Python basic memo --Part 1
OpenCV for Python beginners
python memorandum super basic
Python basic course (8 branches)
Python basic if statement
Python Basic Course (3 Python Execution)
Python Basic --Pandas, Numpy-
Get country code with python
Python with VS Code (Windows 10)
Basic Python 3 grammar (some Python iterations)
Python application: Pandas Part 1: Basic
"Apple processing" with OpenCV3 + Python3
Refactoring Learned in Python (Basic)
BASIC authentication with Python bottle
Image editing with python OpenCV
Camera capture with Python + OpenCV
Python basic dict sort order
Python basic course (10 inclusion notation)
Python installation and basic grammar
Python Basic Grammar Memo (Part 1)