Notes about Opencv3 series
Basically, it is a thing while checking the official document.
windows10 home 64bit Python 3.7.9 opencv 3.4.2.17 Jupyter Notebook used (Anaconda not used)
For the image, I used the meat I took. Use .png as the format. .jpg is fine
opencv_test.ipynb
cap_dir = "Specify the folder where the images used are saved"
From now on, this variable is used.
opencv_test.ipynb
img1 = cv2.imread(cap_dir,0)
img2 = cv2.imread(cap_dir,1)
img3 = cv2.imread(cap_dir,-1)
img4 = cv2.imread(cap_dir,cv2.IMREAD_GRAYSCALE)
img5 = cv2.imread(cap_dir,cv2.IMREAD_COLOR)
img6 = cv2.imread(cap_dir,cv2.IMREAD_UNCHANGED)
1st argument: Image you want to load Second argument: Flags for images
If you just use it normally, 0 or 1 is fine. I think it's okay to use it in color or gray because it is what to do in the processing after reading.
Rather, I've never seen an alpha channel. I do not understand even if I look at the image.
opencv_test.ipynb
img = cv2.imread(cap_dir,1)
cv2.namedWindow('niku',cv2.WINDOW_NORMAL)
cv2.imshow('niku',img)
cv2.waitKey(0)
cv2.destroyAllWindows()
cv2.imshow (1st argument, 2nd argument) 1st argument: Display window name (input as character type) Second argument: The image you want to display
cv2.waitKey (first argument) First argument: Keyboard input wait time (ms unit) I thought it was a weight, but it seems to be the official input reception time If you set it to 0, you will be waiting for unlimited input.
cv2.destroyAllWindows (1st argument) 1st argument: Close all open windows if not entered. If you enter the name of the window you want to close when multiple windows are open Close the window with the name you entered
cv2.namedWindow (1st argument, 2nd argument)
1st argument: Window name (character type)
Second argument: cv2.WINDOW_AUTOSIZE
is set by default.
Normally opened images have a fixed window size
If you enter cv2.WINDOW_NORMAL
in the second argument
The size can be changed arbitrarily by operating the mouse.
However, as a caveat, if the first argument is different from the name set in the first argument of imshow Another window without an image will be launched and it will be meaningless.
The following is when the names do not match The size of the window can be changed on the left side
opencv_test.ipynb
cv2.imwrite('test.png',img)
1st argument: Saved image name Second argument: Saved image
Now when you save the image, it will be saved in the same place where the script is.
opencv_test.ipynb
save_dir = "Directory where you want to save images"
save_name = "Image name"
save_ext = ".png "
cv2.imwrite((save_dir + save_name + save_ext),img)
Then you can save the image in the specified location.
Perhaps the above usage will be the default.
Other things will be put together one by one.
Recommended Posts