#include
#include
#include
#includeusing namespace cv;
using namespace std;int main(int argc, char** argv)
{
Mat image;
Mat III=Mat(255,255,CV_8UC3);//uchar *pd = II.data;
Mat IIIBlue = III.clone();
for(int i=0;i<255;i++)
for (int j = 0; j < 255; j++)
{
//*pd++ = i;
//II.at(i, j) = j;
IIIBlue.at(i, j)[0] = j;
IIIBlue.at(i, j)[1] = 0;
IIIBlue.at(i, j)[2] = 0;
}Mat IIIGreen = III.clone();
for (int i = 0; i<255; i++)
for (int j = 0; j < 255; j++)
{
//*pd++ = i;
//II.at(i, j) = j;
IIIGreen.at(i, j)[0] = 0;
IIIGreen.at(i, j)[1] = j;
IIIGreen.at(i, j)[2] = 0;
}Mat IIIRed = III.clone();
for (int i = 0; i<255; i++)
for (int j = 0; j < 255; j++)
{
//*pd++ = i;
//II.at(i, j) = j;
IIIRed.at(i, j)[0] = 0;
IIIRed.at(i, j)[1] = 0;
IIIRed.at(i, j)[2] = j;
}
Mat I8UC3 = Mat(255, 255, CV_8UC3);//uchar *pd = II.data;
for (int i = 0; i<255; i++)
for (int j = 0; j < 255; j++)
{
//*pd++ = i;
I8UC3.at(i, j) = i;
}
Mat I8UC1 = Mat(255, 255, CV_8UC1);//uchar *pd = II.data;
for (int i = 0; i<255; i++)
for (int j = 0; j < 255; j++)
{
//*pd++ = i;
I8UC1.at(i, j) = i;
}Mat I8UC1_ = Mat(255, 255, CV_8UC1);
uchar *pd = I8UC1_.data;
for (int i = 0; i<255; i++)
for (int j = 0; j < 255; j++)
{
*pd++ = i;
}
//uchar *L0 = II.ptr(0);
//uchar *L1 = II.ptr(1);
//print(image);
printf("MAT Blue channle=%d,type=%d\n", IIIBlue.channels(), IIIBlue.type());
printf("MAT Green channle=%d,type=%d\n", IIIGreen.channels(), IIIGreen.type());
printf("MAT Green channle=%d,type=%d\n", I8UC3.channels(), I8UC3.type());printf("CV_8UC3 channle=%d,type=%d\n", I8UC3.channels(), I8UC3.type());
printf("CV_8UC1 channle=%d,type=%d\n", I8UC1.channels(), I8UC1.type());printf("CV_8UC1_Data channle=%d,type=%d\n", I8UC1_.channels(), I8UC1_.type());
namedWindow("Display window", WINDOW_AUTOSIZE); // Create a window for display.
imshow("Blue", IIIBlue); // Show our image inside it.
imshow("Green", IIIGreen); // Show our image inside it.
imshow("Red", IIIRed); // Show our image inside it.
imshow("CV_8UC3", I8UC3); // Show our image inside it.
imshow("CV_8UC1", I8UC1); // Show our image inside it.imshow("CV_8UC1_Data", I8UC1_); // Show our image inside it.
waitKey(0); // Wait for a keystroke in the window
return 0;
}
运行结果如下图: