Ask Your Question

Revision history [back]

In OpenCV an "image" is represented by a cv::Mat datatype

Not all Mats are uint8 data type.

Mat initialization can be done in the following way

cv::Mat test = cv::Mat(rows, cols, type)

As an example, to initialize a 640*480 Mat of type uint8 with one channel:

cv::Mat test = cv::Mat(480, 640, CV_8UC1);

In which "CV" is the prefix of all data types, 8 means the number of bytes of each pixel, U stands for unsigned and C1 means that Mat has one channel.

Other examples:

CV_16FC1 : Mat of type short (int16) with one channel

CV_32FC3 : Mat of type float with three channels

CV_8UC3: Mat of type unsigned char (uint8) with 3 channels (used to display RGB images)

The reason why Uint8 is very common is because it is the standard way to display images, in which each pixel ranges between 0 and 255. If it is a gray scale image, a pixel with value 0 is black and a pixel with value 255 is white, and in the middle you have gray.

In OpenCV an "image" is represented by a cv::Mat datatype

Not all Mats are uint8 data type.

Mat initialization can be done in the following way

cv::Mat test = cv::Mat(rows, cols, type)

As an example, to initialize a 640*480 Mat of type uint8 with one channel:

cv::Mat test = cv::Mat(480, 640, CV_8UC1);

In which "CV" is the prefix of all data types, 8 means the number of bytes of each pixel, U stands for unsigned and C1 means that Mat has one channel.

Other examples:

CV_16FC1 CV_16SC1 : Mat of type short (int16) with one channel

CV_32FC3 : Mat of type float with three channels

CV_8UC3: Mat of type unsigned char (uint8) with 3 channels (used to display RGB images)

The reason why Uint8 is very common is because it is the standard way to display images, in which each pixel ranges between 0 and 255. If it is a gray scale image, a pixel with value 0 is black and a pixel with value 255 is white, and in the middle you have gray.

In OpenCV an "image" is represented by a cv::Mat datatype

Not all Mats are uint8 data type.

Mat initialization can be done in the following way

cv::Mat test = cv::Mat(rows, cols, type)

As an example, to initialize a 640*480 Mat of type uint8 with one channel:

cv::Mat test = cv::Mat(480, 640, CV_8UC1);

In which "CV" is the prefix of all data types, 8 means the number of bytes of each pixel, U stands for unsigned and C1 means that Mat has one channel.

Other examples:

CV_16SC1 CV_16UC1 : Mat of type unsigned short (int16) with one channel

CV_32FC3 : Mat of type float with three channels

CV_8UC3: Mat of type unsigned char (uint8) with 3 channels (used to display RGB images)

The reason why Uint8 is very common is because it is the standard way to display images, in which each pixel ranges between 0 and 255. If it is a gray scale image, a pixel with value 0 is black and a pixel with value 255 is white, and in the middle you have gray.

In OpenCV an "image" is represented by a cv::Mat datatype

Not all Mats are uint8 data type.

Mat initialization can be done in the following way

cv::Mat test = cv::Mat(rows, cols, type)

As an example, to initialize a 640*480 Mat of type uint8 with one channel:

cv::Mat test = cv::Mat(480, 640, CV_8UC1);

In which "CV" is the prefix of all data types, 8 means the number of bytes of each pixel, U stands for unsigned and C1 means that Mat has one channel.

Other examples:

CV_16UC1 : Mat of type unsigned short (int16) (uint16) with one channel

CV_32FC3 : Mat of type float with three channels

CV_8UC3: Mat of type unsigned char (uint8) with 3 channels (used to display RGB images)

The reason why Uint8 is very common is because it is the standard way to display images, in which each pixel ranges between 0 and 255. If it is a gray scale image, a pixel with value 0 is black and a pixel with value 255 is white, and in the middle you have gray.

In OpenCV an "image" is represented by a cv::Mat datatype

Not all Mats are uint8 data type.

Mat initialization can be done in the following way

cv::Mat test = cv::Mat(rows, cols, type)

As an example, to initialize a 640*480 Mat of type uint8 with one channel:

cv::Mat test = cv::Mat(480, 640, CV_8UC1);

In which "CV" is the prefix of all data types, 8 means the number of bytes of each pixel, U stands for unsigned and C1 means that Mat has one channel.

Other examples:

CV_16UC1 : Mat of type unsigned short (uint16) with one channel

CV_32FC3 : Mat of type float with three channels

CV_8UC3: Mat of type unsigned char (uint8) with 3 channels (used to display RGB images)

The reason why Uint8 is very common is because it is the standard way to display images, in which each pixel ranges between 0 and 255. If it is a gray scale image, a pixel with value 0 is black and a pixel with value 255 is white, and gray in the middle you have gray.

In OpenCV an "image" is represented by a cv::Mat datatype

Not all Mats are uint8 data type.

Mat initialization can be done in the following way

cv::Mat test = cv::Mat(rows, cols, type)

As an example, to initialize a 640*480 Mat of type uint8 with one channel:

cv::Mat test = cv::Mat(480, 640, CV_8UC1);

In which "CV" is the prefix of all data types, 8 means the number of bytes of each pixel, U stands for unsigned and C1 means that Mat has one channel.

Other examples:

CV_16UC1 : Mat of type unsigned short (uint16) with one channel

CV_32FC3 : Mat of type float with three channels

CV_8UC3: Mat of type unsigned char (uint8) with 3 channels (used to display RGB images)

CV_32SC2: Mat of type signed integer (int32) with two channels

The reason why Uint8 is very common is because it is the standard way to display images, in which each pixel ranges between 0 and 255. If it is a gray scale image, a pixel with value 0 is black and a pixel with value 255 is white, and gray in the middle