In [1]:
import cv2
In [2]:
im = cv2.imread('data/src/lena.jpg')
In [3]:
print(type(im))
In [4]:
print(im.shape)
In [5]:
print(im.dtype)
In [6]:
im[:, :, (0, 1)] = 0
In [7]:
cv2.imwrite('data/dst/lena_opencv_red.jpg', im)
Out[7]:
In [8]:
cv2.imwrite('data/dst/lena_opencv_red_high.jpg', im, [cv2.IMWRITE_JPEG_QUALITY, 100])
Out[8]:
In [9]:
cv2.imwrite('data/dst/lena_opencv_red_low.jpg', im, [cv2.IMWRITE_JPEG_QUALITY, 50])
Out[9]:
In [10]:
im_gray = cv2.imread('data/src/lena.jpg', cv2.IMREAD_GRAYSCALE)
# im_gray = cv2.imread('data/src/lena.jpg', 0)
In [11]:
print(type(im_gray))
In [12]:
print(im_gray.shape)
In [13]:
print(im_gray.dtype)
In [14]:
cv2.imwrite('data/dst/lena_opencv_gray.jpg', im_gray)
Out[14]:
In [15]:
im_gray_read = cv2.imread('data/dst/lena_opencv_gray.jpg')
In [16]:
print(im_gray_read.shape)
In [17]:
import numpy as np
In [18]:
print(np.array_equal(im_gray_read[:, :, 0], im_gray_read[:, :, 1]))
In [19]:
print(np.array_equal(im_gray_read[:, :, 1], im_gray_read[:, :, 2]))
In [20]:
im = cv2.imread('xxxxxxx')
In [21]:
print(im)
In [22]:
# print(im.shape)
# AttributeError: 'NoneType' object has no attribute 'shape'
In [23]:
im = cv2.imread('data/src/sample.csv')
In [24]:
print(im)
In [25]:
im = cv2.imread('xxxxxxx')
In [26]:
if im:
print('Image is read.')
else:
print('Image is not read.')
In [27]:
im = cv2.imread('xxxxxxx')
In [28]:
if not im:
print('Image is not read.')
else:
print('Image is read.')