cv.Split[转]
Trouble spliting RGB image into its 3 channels with cvSplit Hi Doug, Maybe you have already sorted this out. I just ran into the same problem and I was just going to add to this when I figured out the solution.
In the new 2.1 python bindings you get a bit of a hint about what is happening. the Error raised is OpenCV Error: Assertion failed (dvec[j].size() == src.size() && dvec[j].depth() == src.depth() && dvec[j].channels() == 1 && i < src.channels()) in cvSplit, file /build/buildd/opencv-2.1.0/src/cxcore/cxconvert.cpp, line 877 Traceback (most recent call last): File "channels.py", line 30, in cv.Split(p, ch[0], ch[1], ch[2], ch[3]) cv.error: dvec[j].size() == src.size() && dvec[j].depth() == src.depth() && dvec[j].channels() == 1 && i < src.channels()
This is the problem bit for us. dvec[j].channels() == 1 && i < src.channels() Checking the source of cxconvert.cpp you can see that checks that the arrays you are giving to the function have * 1 channel only * that the number of these arrays is not greater than the number of channels in the image. The problem is that the image I was loading only had 3 channels but cv.Split is able to take 4, so we gave it 4. cvSplit(self.image,self.chan_imgs[0],self.chan_imgs[1],self.chan_imgs[2],self.ch\ an_imgs[3]) If you change the last argument to None (only giving 3 arrays for 3 channels) then your code should run ok. cvSplit(self.image,self.chan_imgs[0],self.chan_imgs[1],self.chan_imgs[2],None) Hope thats useful to you and others In hind-sight this information is in the API documentation as well http://opencv.willowgarage.com/documentation/python/operations_on_arrays.html?hi\ ghlight=split#Split