2
我正在尝试使用OpenCV从网络摄像机抓取帧并将其转换为HSV(色调,饱和度,值)Mat对象并将其阈值。OpenCV访问MAT对象中的RGB值
当我打印所有像素的阈值图像像素值时,它给我[0,0,0],甚至黑色像素值也是[0,0,0]。 如果所选像素是黑色的,我需要做一些计算;我怎样才能访问像素值?
imgOriginal=frame from camera
Mat imgHSV;
cvtColor(imgOriginal, imgHSV, COLOR_BGR2HSV); //Convert the captured frame from BGR to HSV
Mat imgThresholded;
inRange(imgHSV, Scalar(iLowH, iLowS, iLowV), Scalar(iHighH, iHighS, iHighV), imgThresholded); //Threshold the image
//morphological opening (remove small objects from the foreground)
erode(imgThresholded, imgThresholded, getStructuringElement(MORPH_ELLIPSE, Size(5, 5)));
dilate(imgThresholded, imgThresholded, getStructuringElement(MORPH_ELLIPSE, Size(5, 5)));
//morphological closing (fill small holes in the foreground)
dilate(imgThresholded, imgThresholded, getStructuringElement(MORPH_ELLIPSE, Size(5, 5)));
erode(imgThresholded, imgThresholded, getStructuringElement(MORPH_ELLIPSE, Size(5, 5)));
//************************************
std::vector<cv::Vec3b> pixels(imgThresholded.rows * imgThresholded.cols);
cv::Mat m(imgThresholded.rows, imgThresholded.cols, CV_8UC3, &pixels[0]);
imgThresholded.copyTo(m);
for(int i =0;i<1000;i++)
cout<<pixels[0];
if(pixels[0][0]==black)
// do some calculations!
由于其工作... – gamal 2014-09-11 08:16:58
感谢来自Vec3b其工作... 我怎么能提取RGB值.... INT R = INT G = INT B = – gamal 2014-09-11 11:27:37
如果在我的代码中的img是RGB,那么R = pixel [2],G = pixel [1],B = pixel [0] – Bull 2014-09-11 13:25:10