opencv C ++:如何在Windows窗体应用程序中显示网络摄像头捕获?

时间:2012-03-06 07:30:23

标签: c++ opencv c++-cli

我使用“imwrite”来显示BackgroundImage是否成功以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的情况下显示并使用“Bitmap”它不会在这里工作是源:

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

我的代码有问题吗?谢谢你的帮助:)))

2 个答案:

答案 0 :(得分:0)

我认为这是因为Bitmap的构造函数不直接将类Mat 作为参数。 您应该自己将数据从 OPENCV Mat 转换为 .NET Bitmap :)

答案 1 :(得分: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();