2014-03-05 41 views
0

我试图实现帧差分法进行背景扣除。问题是当我尝试在窗口中显示帧差异。我逼债得到任何输出[黑色窗口]。这是代码实现帧差分法[背景减法]

#include <highgui.h> 
#include <iostream> 
using namespace cv; 

int main() 
{ 

    VideoCapture cap("Camouflage/b%05d.bmp"); 
    if(!cap.isOpened()) 
    { 
     std::cout<<"failed to open image sequence"; 
     return 1; 
    } 
    char c; 
    Mat frame1, frame2, frame3; 
    namedWindow("Original Frames",1); 
    namedWindow("Frame Difference",1); 
    while(1) 
    { 
     cap>>frame1; 
     if(frame1.empty()) 
     { 
      std::cout<<"Frame1Message->End of sequence"<<std::endl; 
      break; 
     } 
     cap>>frame2; 
     if(frame2.empty()) 
     { 
      std::cout<<"Frame2Message->End of sequence"<<std::endl; 
      break; 
     } 
     // absdiff(frame1,frame2,frame3); 

     frame3=frame1.clone(); 
     frame3=frame3-frame2; 
     //imwrite("C:/Users/hp/Desktop/file 
     imshow("Frame Difference",frame3); 
     c=waitKey(90); 
     if(c==27) 
      break; 

     imshow("Original Frames",frame1); 
     c=waitKey(90); 
     if(c==27)   
      break; 
    } 
} 

任何人都可以帮我吗?..读音字卡住。

UPDATE

VideoCapture并没有为我,所以我使用cvCapture工作。我认为它不会读取图像序列,但它worked.This是我做过什么

CvCapture* capture = cvCreateFileCapture("Camouflage/b%05d.bmp"); 

图像名称可以是任何类似b00000,b00010,b00001等。

+0

frame3中的值可能非常小。尝试imshow(“Frame Difference”,frame3 * 100); – berak

+0

刚试过。获得相同的输出。 –

回答

0

您正在打开带有VideoCapture的bmp文件。尝试一个视频,但在两个帧之间没有延迟捕获可能会导致一些问题。

+0

我读取逐帧读取的图像序列。反正它不适用于视频。 –