Reputation: 625
I have a snippet code from colorblobdetection but I don't know what is the purpose of CvType.CV_8UC4. The Link here does not really explain how does it works.
public void onCameraViewStarted(int width, int height) {
mRgba = new Mat(height, width, CvType.CV_8UC4);
mDetector = new ColorBlobDetector();
mSpectrum = new Mat();
mBlobColorRgba = new Scalar(255);
mBlobColorHsv = new Scalar(255);
SPECTRUM_SIZE = new Size(200, 64);
CONTOUR_COLOR = new Scalar(255,0,0,255);
}
Upvotes: 14
Views: 23820
Reputation: 303
All Answers are correct, additionally: the 4th channel is not in every situation an alpha/transparency information. Sometimes it is used if the incomming buffer was an 24bit color image with a padding byte (most at the front or end) to fill it up so that addressing a specific pixel can be done atomically (just by the adress) without finding the specific byte offset. E.g. QImage loads jpegs as 32bit images while only 3 of the 4 bytes are relevant.
So the CV_8UC4 can be used directly for that. BTW, without the use of Transforming RGB to somewhat like HSV all channels are treated separately, and therefore:
It might be a good idea to reformat it to a 3bpp image if there are a lot of heavy cv-operations comming in the next processing steps. This can reduce the processing-time on roughly 25% because of the missing useless 4th channel.
Upvotes: 1
Reputation: 2843
This makes a specific form of Matrix.
Where 8u
means each element will be unsigned (only positive) integers, 8-bit.
The reason there are 4 channels (like 4 slices that layer together to make an image of different colours) is to make up the image. The first 3 in this are R, G, B, and the last is Alpha, which is a value between 0 and 1 representing transparency. When these slices combine you get the correct combination of colours.
Upvotes: 13
Reputation: 16248
OpenCV types can be read the following:
CV_
8U
: Unsigned int 8-bitC4
: Four channels.Thus mRgba = new Mat(height, width, CvType.CV_8UC4);
creates a Matrix with four color channels and values in the range 0 to 255.
Upvotes: 36