如何解决Windows 窗体中的 C++ rtsp 流
我有一个程序可以从相机接收 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,pictureBox1->Width,pictureBox1->Height);
graphics->DrawImage(b,rect);
delete graphics;
}
解决方法
通过改变while(表达式)修复
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,pictureBox1->Width,pictureBox1->Height);
graphics->DrawImage(b,rect);
delete graphics;
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。