I'm really stumped on this one. I have an image that was [BGR2GRAY]'d earlier in my code, and now I need to add colored circles and such to it. Of course this can't be done in a 1 channel matrix, and I can't seem to turn the damned thing back into 3.
numpy.dstack()
crashes everything
GRAY2BGR does not exist in opencv2
cv.merge(src1, src2, src3, dst)
has been turned into cv2.merge(mv)
where mv = "a vector of matrices", whatever that means.
Any ideas?
Opencv2.4.3 refmanual
In this article, we will learn how to split a multi-channel image into separate channels and combine those separate channels into a multi-channel image using OpenCV in Python. To do this, we use cv2. split() and cv2. merge() functions respectively.
The cv2. split() function splits the source multichannel image into several single-channel images. The cv2. merge() function merges several single-channel images into a multichannel image.
There are three channels in an RGB image- red, green and blue. The color space where red, green and blue channels represent images is called RGB color space. In OpenCV, BGR sequence is used instead of RGB. This means the first channel is blue, the second channel is green, and the third channel is red.
Here's a way of doing that in Python:
img = cv2.imread("D:\\img.jpg") gray = cv2.cvtColor(img, cv.CV_BGR2GRAY) img2 = np.zeros_like(img) img2[:,:,0] = gray img2[:,:,1] = gray img2[:,:,2] = gray cv2.circle(img2, (10,10), 5, (255,255,0)) cv2.imshow("colour again", img2) cv2.waitKey()
Here's the complete code for OpenCV3:
import cv2 import numpy as np img = cv2.imread('10524.jpg') gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) img2 = np.zeros_like(img) img2[:,:,0] = gray img2[:,:,1] = gray img2[:,:,2] = gray cv2.imwrite('10524.jpg', img2)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With