how to save the color graph n open cv

Solutions on MaxInterview for how to save the color graph n open cv by the best coders in the world

showing results for - "how to save the color graph n open cv"
Alex
28 Apr 2016
1import cv2
2
3#Reading images in color and grayscale
4color_img = cv2.imread('cat.jpeg')
5gray_img = cv2.imread('cat.jpeg',0)
6
7#Displaying the image
8cv2.imshow('Cat image', color_img)
9
10#Storing the key pressed by user 
11k = cv2.waitKey(0)
12
13#Check if user hits ‘c’ or ‘g’ key
14if( k == ord('c') ):
15  cv2.imwrite('color.jpg', color_img )
16  print("Image is saved color")
17  cv2.destroyAllWindows()
18
19if( k == ord('g') ):
20  cv2.imwrite('gray.jpg', gray_img )
21  print("Image saved in grayscale")
22  cv2.destroyAllWindows()