我想使用 OpenCV 2.3 访问 RGB 中的像素。 我正在尝试这样,但它就像每个像素在帧后帧一样相等,因为我没有输出。图片来 self 的网络摄像头,我可以看到它们。 顺便说一句,红色 = 0;
谢谢
Mat frame;
Mat oldFrame;
VideoCapture cap(0);
cap >> oldFrame;
sumFramePix = oldFrame.cols * oldFrame.rows;
nbChannels = oldFrame.channels();
cout << "NbcHANNELs : " << nbChannels << endl;
imshow("Video 1", oldFrame);
while(1)
{
cap >> frame;
imshow("Video 1", frame);
for(int i=0; i<frame.rows; i++)
{
for(int j=0; j<frame.cols; j++)
{
if (frame.ptr<uchar>(i)[nbChannels*j+RED] < oldFrame.ptr<uchar>(i)[nbChannels*j+RED])
{
cout << "==============-";
}
}
}
oldFrame = frame;
if(waitKey(300) >= 0) break;
}
最佳答案
改变
oldFrame = frame;
到
oldFrame = frame.clone();
您正在创建两个指向相同数据的 Mat 对象。 clone()
进行深拷贝。
关于c++ - 使用 Mat OpenCV 访问像素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7183359/