微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

将VideoCapture声明为全局变量

如何解决将VideoCapture声明为全局变量

我正在尝试使用图片框在C ++ / CLI winform应用程序中流式传输网络摄像头。

在计时器的帮助下,我可以在图片框上流式传输网络摄像头,但是VideoCapture cap(0); Mat frame;被连续声明。我该如何将这两个转换为单击按钮并在此计时器内使用。

private: System::Void Timer1_Tick(System::Object^ sender,System::EventArgs^ e) {

            VideoCapture cap(0);
            Mat frame;
            cap.read(frame);
            System::Drawing::Graphics^ graphics2 = pictureBox1->CreateGraphics();
            System::IntPtr ptr2(frame.ptr());
            System::Drawing::Bitmap^ b2 = gcnew System::Drawing::Bitmap(frame.cols,frame.rows,frame.step,System::Drawing::Imaging::PixelFormat::Format24bppRgb,ptr2);
            System::Drawing::RectangleF rect2(0,pictureBox1->Width,pictureBox1->Height);
            graphics2->DrawImage(b2,rect2);
        
    }

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。