使用Mat OpenCV访问像素 [英] Access pixels with Mat OpenCV
本文介绍了使用Mat OpenCV访问像素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用OpenCV 2.3访问RGB中的像素。
我正在尝试这样但是它就像每帧像素都是一帧又一帧,因为我没有输出。图像来自我的网络摄像头,我可以看到它们。
Btw RED = 0;
I would like to access pixels in RGB with OpenCV 2.3. I'm trying like this but it's like every pixels are equal frame after frame because I got no output. Images are from my webcam and I can see them. Btw RED = 0;
THX
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()
制作一份深层副本。
You are creating two Mat objects that point to the same data. clone()
makes a deep copy.
这篇关于使用Mat OpenCV访问像素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文