cv::Mat image=cv::imread("a.jpg");
cv::Mat image2;
image2.create(image.rows,image.cols,image.type());
cv::cvtColor(image,image2,CV_BGR2GRAY);
怎么取出image2在某点的像素值
opencvè·åç°åº¦å¾åçåç´ å¼çæ¹æ³å¦ä¸ï¼
int main()
{
Mat img = imread("lena.jpg");
imshow("Lena Original", img);
for (int row = 0; row < img.rows; row++)
{
for (int col = 0; col < img.cols; col++)
{
//主è¦æ¯è¿éç代ç
if(*(img.data + img.step[0] * row + img.step[1] * col + img.elemSize1() * 2) > 128)
{
//[row, col]åç´ ç第 1 ééå°å被 * 解æ(blueéé)
*(img.data + img.step[0] * row + img.step[1] * col) = 255;
//[row, col]åç´ ç第 2 ééå°å被 * 解æ(greenéé), å
³äºelemSize1å½æ°çæ´å¤æè¿°è¯·è§ Fn1 éæåçåæé¾æ¥
*(img.data + img.step[0] * row + img.step[1] * col + img.elemSize1()) = 255;
//[row, col]åç´ ç第 3 ééå°å被 * 解æ(redéé)
*(img.data + img.step[0] * row + img.step[1] * col + img.elemSize1() * 2) = 255;
}
}
}
imshow("Lena Modified", img);
cvWaitKey();
return 0;
}
è¾åºï¼
谢谢你 不过这个是c接口的,我大概已经想起了,遍历Mat即可
本回答被提问者和网友采纳