我的项目是从图像识别面孔。这些图像具有相同的名称和更改偶尔
所以我想加载和每次处理图像他们改变
我怎么能修改此:阅读和处理图像(opencv/c + +)
while (image==NULL) {
image = cvLoadImage("ayman.jpg", 1);
}
cout << endl << "My image was finally loaded!";
对不起,我的英语
我的项目是从图像识别面孔。这些图像具有相同的名称和更改偶尔
所以我想加载和每次处理图像他们改变
我怎么能修改此:阅读和处理图像(opencv/c + +)
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;
}
}
对不起,队友,我忘了添加一行!我评论为“//添加!!忘了这个,对不起”...请尝试告诉我它是否工作;) –
谢谢拉法我改变了图像,但Xterm一直告诉我,“图像还没有改变“。 –
考虑删除第一个cout(该句子:'cout << endl <<“图像尚未更改,因此只有在它被更改时才会收到通知)。如果可以,你可以接受它作为正确的答案:) –
哪些操作系统?在linux中你可以使用inotify。 – Nidhoegger
我正在使用linux –
你能用一个例子来具体描述吗? –