I want to get only the first channel (blue) in the BGR image, and then save it to disk. When I use cv2.split (), everything is fine
>>> import cv2 >>> a = cv2.imread("/home/s18/theVIDEO/1_resized.jpg") >>> b = cv2.split(a)[0] >>> type(b) <type 'numpy.ndarray'> >>> b array([[223, 222, 224, ..., 88, 80, 71], [222, 221, 225, ..., 84, 78, 67], [220, 221, 225, ..., 77, 71, 62], ..., [163, 178, 182, ..., 107, 107, 106], [148, 170, 186, ..., 104, 104, 103], [156, 181, 201, ..., 102, 101, 100]], dtype=uint8) >>> b.shape (600, 800) >>> cv2.imwrite("/home/s18/theVIDEO/1_resized2.jpg", b) True
But when using the simulate cut operation, I get an error
>>> c = a[:,:,0] >>> c >>> type(c) <type 'numpy.ndarray'> array([[223, 222, 224, ..., 88, 80, 71], [222, 221, 225, ..., 84, 78, 67], [220, 221, 225, ..., 77, 71, 62], ..., [163, 178, 182, ..., 107, 107, 106], [148, 170, 186, ..., 104, 104, 103], [156, 181, 201, ..., 102, 101, 100]], dtype=uint8) >>> c.shape (600, 800) >>> cv2.imwrite("/home/s18/theVIDEO/1_resized3.jpg", c) False
Elements of arrays b and c are equal, sizes and classes are also simulative. Why couldn’t I use simple slicing to get one of the channels?