2015-05-14 83 views
0

我的項目是從圖像識別面孔。這些圖像具有相同的名稱和更改偶爾
所以我想加載和每次處理圖像他們改變
我怎麼能修改此:閱讀和處理圖像(opencv/c + +)

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

對不起,我的英語

+0

哪些操作系統?在linux中你可以使用inotify。 – Nidhoegger

+0

我正在使用linux –

+0

你能用一個例子來具體描述嗎? –

回答

0

好吧,讓我們假設你的圖像在他們改變的時刻是不同的(隨機)。我們如何檢測到它是另一幅與前一幅不同的圖像?

我們要提取圖像的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; 



     } 

    } 
+0

對不起,隊友,我忘了添加一行!我評論爲「//添加!!忘了這個,對不起」...請嘗試告訴我它是否工作;) –

+0

謝謝拉法我改變了圖像,但Xterm一直告訴我,「圖像還沒有改變「。 –

+0

考慮刪除第一個cout(該句子:'cout << endl <<「圖像尚未更改,因此只有在它被更改時纔會收到通知)。如果可以,你可以接受它作爲正確的答案:) –