简体   繁体   English

读取和处理图像(opencv / c ++)

[英]Reading and processing images (opencv/c++)

My project is recognizing faces from images. 我的项目是从图像中识别人脸。 The images have the same name and change occasionally 图像具有相同的名称,并偶尔更改
So i want to load and process the images every time they change 所以我想每次更改图像时加载并处理图像
how can i modify this: 我该如何修改:

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

sorry for my english 对不起我的英语不好

Ok, let's assume than your images are different at the moment they change (random). 好的,我们假设您的图像在更改(随机)时有所不同。 How do we detect that it's another image, different from the previous one? 我们如何检测到它是另一张与上一张不同的图片?

We are going to extract 3 features of your image and it is: the mean of the RED CHANNEL, GREEN CHANNEL and BLUE CHANNEL (it's a vector). 我们将提取图像的3个特征,即:红色通道,绿色通道和蓝色通道的平均值(它是矢量)。 So, if the image is the same, the 3 means are the same, but if it's different, the image has been changed. 因此,如果图像相同,则3个均值相同,但是如果图像不同,则图像已更改。

So think we are in a infinite loop (your while ). 因此,请考虑我们处于无限循环中(您的while )。

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

Are we ok ? 我们可以吗? So this is the code: 所以这是代码:

    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;



        }

    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM