I will not say much nonsense, directly on the code!
#coding=utf-8 The core class in opencv is matrix, which is the abbreviation of matrix and represents matrix. This class is in the header file opencv2 / core\ core.hpp It contains a lot of basic matrix operations, C + + need to reference Python contains numpy, so you don't need to use mat '' ' #The image storage mode in opencv is (h, W, channel), and the order is BGR import cv2 import sys if __name__=='__main__': if len(sys.argv)>1: img=cv2.imread(sys.argv,cv2.CV_LOAD_IMAGE_UNCHANGED) b=img[:, :, 0] g=img[:, :, 1] r=img[:, :, 2] cv2.imshow('img', img) cv2.imshow('B',b) cv2.imshow('G', g) cv2.imshow('R', r) cv2.waitKey(0) cv2.destroyAllWindows() else: print 'can not open the image'
Call::~/PycharmProjects/OpenCV$ python show_RGB.py timg.jpeg
The above example of Python opencv reading RGB channel diagram is the whole content shared by Xiaobian. I hope to give you a reference, and also hope that you can support developeppaer more.