I have image opened this way in fast.ai:
img = open_image(img_f)
How do I show it with cv2.imshow ?
The first method is to use the urllib Python package to download the image, convert it to an array using NumPy, and finally reshape the array using OpenCV to construct our image. The second method is to use the io.imread function of scikit-image. So which method is better?
The fastai Image classes The fastai library is built such that the pictures loaded are wrapped in an Image. This Image contains the array of pixels associated to the picture, but also has a lot of built-in functions that will help the fastai library to process transformations applied to the corresponding image.
Now, let's analyze the main code. As a first step, we read the image "starry_night.jpg" from the OpenCV samples. In order to do so, a call to the cv::imread function loads the image using the file path specified by the first argument. The second argument is optional and specifies the format in which we want the image.
While convert PIL img to OpenCV img will able to keep transparent channel, although cv2.imshow not display it but save as png will gave result normally. You can call cv2.imwrite ("./"+"fileName.png", img); to export and check the transparent result of OpenCV img.
FastAi already uses this package to work with images. When you do open_image function check the doc string:
def open_image(fn):
""" Opens an image using OpenCV given the file path.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With