簡體   English   中英

C++ rtsp stream 在 Windows Z6450242531912981C3683CAE88A326A

[英]C++ rtsp stream in Windows Forms

我有一個程序可以從相機接收 rtsp 視頻並將其傳輸到圖片框。 它只工作幾秒鍾,然后程序掛起,幫助查找錯誤。

private: System::Void start_Click(System::Object^ sender, System::EventArgs^ e) {
if (start->Text == "Start stream"){
    start->Text = "Stop stream";
}
else if (start->Text == "Stop stream") {
    pictureBox1->Refresh();
    start->Text = "Start stream";
}
cv::VideoCapture stream = cv::VideoCapture(ip[n]);
cv::Mat frame;
while (start->Text == "Stop stream")
{
    stream.read(frame);
    System::Drawing::Graphics^ graphics = pictureBox1->CreateGraphics();
    System::IntPtr ptr(frame.ptr());
    System::Drawing::Bitmap^ b = gcnew System::Drawing::Bitmap(frame.cols, frame.rows, frame.step, System::Drawing::Imaging::PixelFormat::Format24bppRgb, ptr);
    System::Drawing::RectangleF rect(0, 0, pictureBox1->Width, pictureBox1->Height);
    graphics->DrawImage(b, rect);
    delete graphics;    
}

通過更改 while(expression) 修復

cv::VideoCapture stream = cv::VideoCapture(ip[n]);
        cv::Mat frame;
        if (stream.isOpened())
        {
            flag = true;
            while (cv::waitKeyEx(1) != 27)
            {
                stream.read(frame);
                System::Drawing::Graphics^ graphics = pictureBox1->CreateGraphics();
                System::IntPtr ptr(frame.ptr());
                System::Drawing::Bitmap^ b = gcnew System::Drawing::Bitmap(frame.cols, frame.rows, frame.step, System::Drawing::Imaging::PixelFormat::Format24bppRgb, ptr);
                System::Drawing::RectangleF rect(0, 0, pictureBox1->Width, pictureBox1->Height);
                graphics->DrawImage(b, rect);
                delete graphics;
            }
        }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM