gpt4 book ai didi

c++ - 使用 Mat OpenCV 访问像素

转载 作者:太空狗 更新时间:2023-10-29 21:50:01 25 4
gpt4 key购买 nike

我想使用 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com