1. 程式人生 > >opencv 畫素點位置描述的不同

opencv 畫素點位置描述的不同

Mat image, image_3c;
image.create(Size(800, 600), CV_8UC1);//單通道
image_3c.create(Size(800, 600), CV_8UC3);//3通道

image.setTo(0);
image_3c.setTo(0);

image.at<uchar>(10, 200) = 255;//使用at函式的地方,用的是10,200
Point point(20, 100);
image.at<uchar>(point) = 250;

image_3c.at<uchar>(10, 300) = 255;
image_3c.at<uchar>(10, 302) = 254;
Point point_3c(20, 200);
image_3c.at<uchar>(point_3c) = 250;

double maxVal = 0;//最大值一定要賦初值,否則執行時就會報錯
Point maxLoc;
minMaxLoc(image, NULL, &maxVal, NULL, &maxLoc);
cout << "單通道影象最大值:" << maxVal << endl;
double min_3c, max_3c;
//注意多通道在使用minMaxLoc()函式是不能給出其最大最小的座標的,因為每個畫素點其實
//有多個座標,所以是不會給出的
minMaxLoc(image_3c, &min_3c, &max_3c, NULL, NULL);
cout << "3通道影象最大值是:" << max_3c << endl;

imshow("test", image);

waitKey(2000);

imshow("test_3c", image_3c);

waitKey(000);