- read image
- get the image size
- show image
- move image window to the specified position
- save image
- convert the color space
01 from cv2 import *02
03 # read image
04 # imread() returns the image as a NumPy array
05 # the image is stored in BGR order!
06 '''
07 flags-
08 CV_LOAD_IMAGE_GRAYSCALE - always convert image to the grayscale one
09 CV_LOAD_IMAGE_COLOR - always convert image to the color one
10 CV_LOAD_IMAGE_ANYDEPTH - load the image as is
11 '''
12 im = imread("lena.jpg")
13 print(type(im))
14
15 # image info
16 height, width, channel = im.shape
17 print(height, width, channel)
18 # or for a grayscale image
19 #height, width = im.shape
20
21 # show image
22 namedWindow("lena")
23 imshow("lena", im)
24
25 # move window to the specified position
26 # cv2.moveWindow(winname, x, y)
27 moveWindow("lena", 10, 10)
28 waitKey()
29
30 # save image
31 #imwrite("lena1.jpg", im)
32
33 # color space
34 '''
35 cv2.COLOR_BGR2GRAY
36 cv2.COLOR_BGR2RGB
37 cv2.COLOR_GRAY2BGR
38 '''
39 gray = cvtColor(im, COLOR_BGR2GRAY)
40 namedWindow("lena_gray")
41 imshow("lena_gray", gray)
42 waitKey()
43
44 destroyAllWindows()
03 # read image
04 # imread() returns the image as a NumPy array
05 # the image is stored in BGR order!
06 '''
07 flags-
08 CV_LOAD_IMAGE_GRAYSCALE - always convert image to the grayscale one
09 CV_LOAD_IMAGE_COLOR - always convert image to the color one
10 CV_LOAD_IMAGE_ANYDEPTH - load the image as is
11 '''
12 im = imread("lena.jpg")
13 print(type(im))
14
15 # image info
16 height, width, channel = im.shape
17 print(height, width, channel)
18 # or for a grayscale image
19 #height, width = im.shape
20
21 # show image
22 namedWindow("lena")
23 imshow("lena", im)
24
25 # move window to the specified position
26 # cv2.moveWindow(winname, x, y)
27 moveWindow("lena", 10, 10)
28 waitKey()
29
30 # save image
31 #imwrite("lena1.jpg", im)
32
33 # color space
34 '''
35 cv2.COLOR_BGR2GRAY
36 cv2.COLOR_BGR2RGB
37 cv2.COLOR_GRAY2BGR
38 '''
39 gray = cvtColor(im, COLOR_BGR2GRAY)
40 namedWindow("lena_gray")
41 imshow("lena_gray", gray)
42 waitKey()
43
44 destroyAllWindows()
没有评论:
发表评论