11월, 2019의 게시물 표시

Basic Cooking #1 -Open,Save, Resize, Display

이미지
OpenCV Open image Use cv2.imread function to open an image file. import cv2 img = cv2 . imread( "dog.jpg" , cv2 . IMREAD_COLOR) height, width, channels = img . shape print( "JPG H:%d W:%d, Channel:%d" % (height, width, channels)) #There's no channel value when open with grayscale img = cv2 . imread( "dog.jpg" , cv2 . IMREAD_GRAYSCALE) height, width = img . shape print( "JPG H:%d W:%d " % (height, width)) img = cv2 . imread( "linux.png" , cv2 . IMREAD_COLOR) height, width, channels = img . shape print( "PNG 1 H:%d W:%d, Channel:%d" % (height, width, channels)) img = cv2 . imread( "linux.png" , cv2 . IMREAD_UNCHANGED) height, width, channels = img . shape print( "PNG 2 H:%d W:%d, Channel:%d" % (height, width, channels)) <open.py> Flags cv2.IMREAD_COLOR : BGR format image is opened. So the channel will be 3. cv2.IMREAD_GRAYSCALE : only 1