http://labs.eecs.tottori-u.ac.jp/sd/Member/oyamada/OpenCV/html/py_tutorials/py_tutorials.html
This was just an installation, so I omitted it
cv2.imread() cv2.imshow() cv2.imwrite()
Just a brief explanation about. Others, video, drawing, painting with mouse, color palette are omitted.
The process specified in this section is more related to Numpym than openCV. Writing optimized OpenCV code requires knowledge of Numpy.
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
>>>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
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
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