this piece of code is used to plot an image inside a jupyter cell.
from matplotlib import pyplot as plt
import cv2
img = cv2.imread('img1.png',1)
a = plt.imshow(img)
plt.show()
other parts is easy to understand except opencv.imread
.
the doc of opencv.imread says
Flags specifying the color type of a loaded image:
CV_LOAD_IMAGE_ANYDEPTH - If set, return 16-bit/32-bit image when the input has the corresponding depth, otherwise convert it to 8-bit.
CV_LOAD_IMAGE_COLOR - If set, always convert image to the color one
CV_LOAD_IMAGE_GRAYSCALE - If set, always convert image to the grayscale one
>0 Return a 3-channel color image.
Note In the current implementation the alpha channel, if any, is stripped from the output image. Use negative value if you need the alpha channel.
=0 Return a grayscale image.
<0 Return the loaded image as is (with alpha channel).
I've tried -1, 0 and 1, which works well.
what do other options (such as CV_LOAD_IMAGE_ANYDEPTH) do? how can I use these options in Python?
from matplotlib import pyplot as plt
import cv2
img = cv2.imread('img1.png',CV_LOAD_IMAGE_ANYDEPTH)
a = plt.imshow(img)
plt.show()
direct setting gets error
-------------------------------------------------------------------------- NameError Traceback (most recent call last) <ipython-input-14-8c9e4e747e3f> in <module>() 1 from matplotlib import pyplot as plt 2 import cv2 ----> 3 img = cv2.imread('img1.png',CV_LOAD_IMAGE_ANYDEPTH) 4 a = plt.imshow(img) 5 plt.show() NameError: name 'CV_LOAD_IMAGE_ANYDEPTH' is not defined
using cv2.CV_LOAD_IMAGE_ANYDEPTH
got another error
-------------------------------------------------------------------------- AttributeError Traceback (most recent call last) <ipython-input-29-f6ea92814b06> in <module>() 1 from matplotlib import pyplot as plt 2 import cv2 ----> 3 img = cv2.imread('img1.png',cv2.CV_LOAD_IMAGE_ANYDEPTH) 4 a = plt.imshow(img) 5 plt.show() AttributeError: module 'cv2.cv2' has no attribute 'CV_LOAD_IMAGE_ANYDEPTH'
can any one provide a runnable python code to demonstrate how to use CV_LOAD_IMAGE_ANYDEPTH
?