Convert RGB to gray / other color spaces
cv2.cvtColor(src, code[, dst[, dstCn]]) → dst
Parameters: |
|
---|
The conventional ranges for R, G, and B channel values are:
- 0 to 255 for CV_8U images
- 0 to 65535 for CV_16U images
- 0 to 1 for CV_32F images
Example:
Converting to grayscale:
Steps:
- Convert to gray scale
- Show result
Code:
------------------------------------------
-------------------------------------------
------------------------------------------
import cv2 # Load a color image img = cv2.imread('image1.jpg',1) #convert RGB image to Gray gray=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY) #Display the color image cv2.imshow('color_image',img) #Display the gray image cv2.imshow('gray_image',gray) cv2.waitKey(0) cv2.destroyAllWindows()
-------------------------------------------
No comments:
Post a Comment