Python OpenCV tutorial memo

http://labs.eecs.tottori-u.ac.jp/sd/Member/oyamada/OpenCV/html/py_tutorials/py_tutorials.html

Get started with OpenCV-Python

This was just an installation, so I omitted it

GUI function of OpenCV

Handle images

cv2.imread() cv2.imshow() cv2.imwrite()

Just a brief explanation about. Others, video, drawing, painting with mouse, color palette are omitted.

Basic processing

Basic processing on the image

The process specified in this section is more related to Numpym than openCV. Writing optimized OpenCV code requires knowledge of Numpy.

How to access and change pixel values

Read a color image with imread (). You can access the pixel values by specifying the row and column coordinates of a pixel. BGR image pixel values are an array of color component values The pixel value of a grayscale image returns the brightness value.

>>> px = img[100,100]
>>> print px
[157 166 200] #Coordinate:x:100, y:100[B, G , R]The value of the

#If you want only the number of Blue
>>> blue = img[100,100, 0] # B:0, G:1, R:1
157

Acquisition of image attribute information

>>>img.shape()
(342, 548, 3) #Number of rows, number of columns, number of channels(3 BGR..?)

>>>img.size() #Number of pixels

>>> img.dtype #Data type

Area of interest (ROI) in the image

You may need to do something about a particular area of the image. When detecting eyes from the image, first the face is detected for the entire image, and then the eyes are detected inside the detected face. This method not only makes the factory accurate, but also improves performance (because eye detection only needs to benefit from drinking some areas in the image). 」

ball = img[100:150, 200:250] # top:bottom, left:Cut out with right

img[200:250, 200:250] = ball #copy

Splitting and integrating color components of images

The blue, green, and red components of the image can be split into independent color components if desired. It is also possible to combine independent color components to recreate a BGR image.

b, g, r = cv2.split(img)
img = cv2.merge((b,g,r))

Only a specific color component can be extracted. b = img [:,:, 0] #x axis range (all) y axis range (all) 0 = B Now you can get the B numbers of all coordinates in an array.

Can also be set [:,:, 0] = 0

Recommended Posts

Python OpenCV tutorial memo
python openCV installation (memo)
Python memo
python memo
Python memo
Python tutorial
python memo
Python memo
Python memo
Python memo
[OpenCV] Personal memo
[Python] Memo dictionary
Python2.7 + CentOS7 + OpenCV3
Python Django Tutorial (5)
Python Django Tutorial (2)
Python tutorial summary
python beginner memo (9.1)
★ Memo ★ Python Iroha
Python Django Tutorial (8)
Python Django Tutorial (6)
[Python] EDA memo
Python 3 operator memo
OpenCV Samples (Python)
[Note] openCV + python
[My memo] python
Python3 metaclass memo
[Python] Basemap memo
Python Django Tutorial (7)
Python Django Tutorial (1)
Python Django tutorial tutorial
Python beginner memo (2)
Python Django Tutorial (3)
[Python] Numpy memo
Python Django Tutorial (4)
A memo of a tutorial on running python on heroku
Python class (Python learning memo ⑦)
My python environment memo
[Docker] Tutorial (Python + php)
Python Django tutorial summary
Python module (Python learning memo ④)
Visualization memo by Python
Binarization with OpenCV / Python
Python test package memo
python regular expression memo
Binary search (python2.7) memo
Introduction to OpenCV (python)-(2)
[My memo] python -v / python -V
Python3 List / dictionary memo
Python Tips (my memo)
[Python] Memo about errors
OpenCV3 Python API list
DynamoDB Script Memo (Python)
Python basic memo --Part 2
python recipe book Memo
Basic Python command memo
Python, OpenCV camera capture
FastAPI Tutorial Memo Part 1
Python basic grammar memo
[Python tutorial] Data structure
TensorFlow API memo (Python)
Cloud Run tutorial (python)