阅读和处理图像(OpenCV/C )

Reading and processing images (opencv/c++)

本文关键字:OpenCV 图像 处理      更新时间:2023-10-16

我的项目正在识别图像的面孔。图像具有相同的名称,并偶尔更改
因此,我想每次更改
时加载和处理图像我该如何修改:

    while (image==NULL) {
    image = cvLoadImage("ayman.jpg", 1);
}
cout << endl << "My image was finally loaded!";    

对不起我的英语

好吧,假设您的图像在更改(随机)时的图像有所不同。我们如何检测到它是另一个图像,与上一张图像不同?

我们将提取图像的3个功能,它是:红色通道,绿色通道和蓝色通道的平均值(是向量)。因此,如果图像相同,则3均值是相同的,但是如果它不同,则图像已更改。

所以认为我们处于无限循环(您的while)。

while(true) {
    // we are going to say here if the image has changed or not
}

我们还可以吗?这是代码:

    image = cvLoadImage("ayman.jpg", 1);
    Scalar meanOfImage = mean(image);
    while (true) {
        Scalar meanAtThisMoment = mean(image);
        // This are the three features (it's in real one, but one vector of 3).
        // We are going to compare the three to be more clear.
        if (meanAtThisMoment[0] == meanOfImage[0]
            &&
            meanAtThisMoment[1] == meanOfImage[1]
            &&
            meanAtThisMoment[2] == meanOfImage[2]) {
            cout << endl << "The image hasn't been changed yet.";
            image = cvLoadImage("ayman.jpg", 1); // added!! forgot this, sorry
        } else {
            cout << endl << "The image has been changed!!!";
            // and now we set the meanOfImage (the main mean) of the new image to compare with the future images.
            meanOfImage = meanAtThisMoment;

        }
    }