2012-03-06 72 views
-1

我用「imwrite」顯示的BackgroundImage是成功的窗口形式顯示的圖像,但它到磁盤損壞:opencv C++:如何在windows窗體應用程序中顯示攝像頭捕獲?

private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) 
{ 
    namedWindow("video",0); 
    VideoCapture cap(0); 
    flag = true; 
    while(flag){ 
     Mat frame; 
     cap >> frame; // get a new frame from camera 
     **imwrite("vdo.jpg",frame);** 
     this->panel1->BackgroundImage = System::Drawing::Image::FromFile("vdo.jpg");           
     waitKey(5); 
     delete panel1->BackgroundImage; 
     this->panel1->BackgroundImage = nullptr; 
    } 
} 

當我試圖顯示不imwrite並使用「位圖」,它不會在這裏工作是來源:

this->panel1->BackgroundImage = System::Drawing::Bitmap(frame); 

我的代碼有什麼問題嗎?感謝您的幫助:)))

+1

「它不會工作」是不是問題描述 – 2012-03-06 14:22:31

+0

[如何在Windows窗體應用程序中顯示cv :: Mat的可能的重複?](http://stackoverflow.com/questions/9580397/how-to-display-a-cvmat-in-a -Windows形式施用) – mevatron 2012-03-08 04:23:50

回答

0

我認爲這是因爲位圖的構造函數不會將類Mat直接作爲參數。 你應該將數據從OPENCV墊自行轉換爲.NET位圖 :)

0

對於顯示圖像,你可能需要這個(另一種選擇),

pictureBox1->Image = gcnew //replacement of cvShowImage 

System::Drawing::Bitmap(Img->width, Img->height, Img->widthStep, 

System::Drawing::Imaging::PixelFormat::Format24bppRgb,(System::IntPtr)Img->imageData); 

pictureBox1->Refresh(); 
相關問題