可能重複:
OpenCV rgb value for cv::Point in cv::Mat如何使用獲得的R,G,B值opencv2.3
如你所知,在MATLAB很容易得到R/G/B值使用r = image(:,:,1)
。
但在OpenCV中(前2.2),我們必須用指針這樣的:
plImage* img=cvCreateImage(cvSize(640,480),IPL_DEPTH_32F,3); ((float *)(img->imageData + i*img->widthStep))[j*img->nChannels + 0]=111; // B ((float *)(img->imageData + i*img->widthStep))[j*img->nChannels + 1]=112; // G ((float *)(img->imageData + i*img->widthStep))[j*img->nChannels + 2]=113; // R
但作爲openCV2.3出來,很容易得到這樣一個通道圖像的像素值:
Mat image;
int pixel = image.at<uchar>(row,col);
所以我只是想知道它還有一個簡單的方法來得到多通道圖像的r,g,b像素值就像在Matlab中一樣嗎?任何幫助將不勝感激=)
這是我回答這個同一個問題一陣子回來:http://stackoverflow.com/questions/7899108/opencv-get-pixel- information-from-mat-image/7903042#7903042 – mevatron