Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the purpose of CvType.CV_8UC4

Tags:

opencv

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);
}
like image 678
Shulz Avatar asked Sep 17 '16 06:09

Shulz


Video Answer


2 Answers

OpenCV types can be read the following:

  • CV_
  • 8U: Unsigned int 8-bit
  • C4: 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.

like image 101
Unapiedra Avatar answered Oct 27 '22 01:10

Unapiedra


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.

enter image description here

like image 44
Caspar Wylie Avatar answered Oct 27 '22 01:10

Caspar Wylie