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

标签 c++ image opencv rgb pixel

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

相关文章:

c++ - OpenGL - 矩形中的模板测试

c++ - 合并位移

c++ - 如何让 mciSendString 同时处理变量和空格?

c# - 在 Blazor WebAssembly 中调整图像大小 (jpg)?

javascript - 如何提高加载新叠加图像的 map 性能

php - 如何在 PHP 中将所有图像转换为 JPG 格式?

c++ - 在 C++ 中使用 zeromq 将序列化的 Mat 对象发送到另一台计算机

c++ - 我可以对我的 conan 包的用户隐藏我的链接标志吗?

python - 无法重建分解图像

algorithm - 训练强大的级联分类器时要考虑的建议?