Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/129.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ OpenCV网络摄像头源未在PictureBox visual studio 2015中显示_C++_Winforms_Visual Studio_Opencv_Video Capture - Fatal编程技术网

C++ OpenCV网络摄像头源未在PictureBox visual studio 2015中显示

C++ OpenCV网络摄像头源未在PictureBox visual studio 2015中显示,c++,winforms,visual-studio,opencv,video-capture,C++,Winforms,Visual Studio,Opencv,Video Capture,大家好,我使用opencv从默认摄像头获取网络摄像头提要,我希望在windows窗体上的图片框中显示它。我的网络摄像头打开了,但由于某些原因,该提要从未显示在我的picturebox上。请有人帮我指出/解决这个问题,因为我现在被困在这里。 提前谢谢 在myform.h中,我有以下代码将picturebox发送到myform.cpp文件: System::Windows::Forms::PictureBox^ mypicbox1(void) { opencv_gui::MyForm a

大家好,我使用opencv从默认摄像头获取网络摄像头提要,我希望在windows窗体上的图片框中显示它。我的网络摄像头打开了,但由于某些原因,该提要从未显示在我的picturebox上。请有人帮我指出/解决这个问题,因为我现在被困在这里。 提前谢谢

在myform.h中,我有以下代码将picturebox发送到myform.cpp文件:

System::Windows::Forms::PictureBox^ mypicbox1(void)  
{
    opencv_gui::MyForm aform;
    return aform.pictureBox1;
}
获取视频提要并将其放入myform.cpp中的图片框的代码是:

void opencv_gui::DrawCvImage(const cv::Mat& cvImage)
{
    System::Windows::Forms::PictureBox^ pictureBox = mypicbox1();
    // only color images are supported
    assert(cvImage.type() == CV_8UC3);

    if ((pictureBox->Image == nullptr) || (pictureBox->Width != cvImage.cols) || (pictureBox->Height != cvImage.rows))
    {
        pictureBox->Width = cvImage.cols;
        pictureBox->Height = cvImage.rows;
        pictureBox->Image = gcnew System::Drawing::Bitmap(cvImage.cols, cvImage.rows);
    }

    // Create System::Drawing::Bitmap from cv::Mat
    System::Drawing::Bitmap^ bmpImage = gcnew System::Drawing::Bitmap(
        cvImage.cols, cvImage.rows, cvImage.step,
        System::Drawing::Imaging::PixelFormat::Format24bppRgb,
        System::IntPtr(cvImage.data)
    );

    // Draw Bitmap over a PictureBox
    System::Drawing::Graphics^ g = System::Drawing::Graphics::FromImage(pictureBox->Image);

    g->DrawImage(bmpImage, 0, 0, cvImage.cols, cvImage.rows);
    pictureBox->Refresh();

    delete g;
}


//camera feed
int opencv_gui::video_cap(void)
{
    VideoCapture cap;

    if (!cap.open(0)) // open the default camera (camera 0), use something different from 0 otherwise;
        return 0;
    for (;;)
    {
        Mat frame;
        cap >> frame;
        if (frame.empty()) break; // end of video stream
        DrawCvImage(frame);
        if (waitKey(10) == 27) break; // stop capturing by pressing ESC 
    }
    // the camera will be closed automatically upon exit
    // cap.close();
    return 0;
}
这是我的调试日志:我使用了像“>>>>>>>”这样的箭头来显示重要的参数,并使用了“RED>>>>>>>>>这样的词来显示错误参数

  • cvImage{flags=1124024336 dims=2行=480…}cv::Mat&
  • 分配器0x0000000000000000 cv::MatAllocator* COLS640INT

  • 数据0x000026AC2146F80无符号字符* *(*cvImage).数据0''无符号字符

  • dataend 0x0000026AC2227F80无符号字符*
  • 数据限制0x000026AC2227F80无符号字符*
  • datastart 0x0000026AC2146F80无符号字符* dims 2 int 标志1124024336 int 行480整数
  • 大小{p=0x000000DBDFF0DE80}cv::MatSize

  • p 0x000000DBDFF0DE80 int* *(*cvImage).size.p0 int

  • 步骤{p=0x000000DBDFF0DEC8 buf={Length=2}}cv::MatStep
  • buf{Length=2}无符号_int64[]
  • p 0x000000DBDFF0DEC8无符号\uuuu int64*
  • u 0x0000026AA4814780 cv::UMatData*
  • 红色>>>>>>bmpImage 0x0000026aa62a1fd0{defaultTransparentColor=}系统::绘图::位图^
  • 红色>>>>>>>系统::绘图::图像^0x0000026aa62a1fd0{nativeImage=2657511292512 rawData=userData=}系统::绘图::图像^ defaultTransparentColor系统::绘图::颜色 g系统::绘图::图形^
  • 红色>>>>>>>>>pictureBox 0x0000026aa62a1388{borderStyle=System::Windows::Forms::borderStyle::None image=0x000026AA62A1FA0 sizeMode=System::Windows::Forms::PictureBoxSizeMode::Normal…}系统::Windows::Forms::pictureBox^
  • 红色>>>>>>系统::Windows::Forms::Control^0x0000026aa62a1388{ControlKeyboardRouting=PaletteTracing=FocusTracing=…}系统::Windows::Forms::Control^ AllowDrop假布尔 BorderStyle系统::Windows::Forms::BorderStyle::None系统::Windows::Forms::BorderStyle 因果关系
  • CreateParams 0x0000026aa62a15d8{className=caption=style=1442840576…}系统::窗口::窗体::CreateParams^ 默认ImeMode系统::Windows::Forms::ImeMode::禁用系统::Windows::Forms::ImeMode
  • DefaultSize{Width=100 Height=50}系统::绘图::大小 事件大小已更改0x0000026aa629af50系统::对象^
  • ErrorImage 0x0000026aa629b110{nativeImage=2657511192608 rawData=userData=}系统::绘图::图像^
  • Font 0x0000026aa6280148{}系统::绘图::Font^
  • 前景色{RGB=0x0}系统::绘图::颜色
  • 图像0x0000026aa62a1fa0{nativeImage=2657511290992 rawData=userData=}系统::绘图::图像^
  • [系统::绘图::位图^0x0000026aa62a1fa0{defaultTransparentColor=}系统::绘图::位图^
  • System::MarshalByRefObject ^0x0000026aa62a1fa0{{u_identity=}System::MarshalByRefObject^ 旗帜2整型
  • FrameDimensionsList{Length=1}数组^ 高度480英寸 水平分辨率96.000000浮点
  • 调色板0x0000026aa62a25e8{flags=1129621568条目的={Length=0}}系统::绘图::成像::颜色调色板^
  • 物理尺寸{宽度=640.00000高度=480.00000}系统::绘图::SizeF PixelFormat系统::绘图::成像::PixelFormat::Format32bppArgb系统::绘图::成像::PixelFormat PropertyIdList{Length=0}数组^ PropertyItems{Length=0}数组^
  • RawFormat 0x0000026aa62a3488{…}系统::绘图::成像::图像格式^
  • 尺寸{宽度=640高度=480}系统::绘图::尺寸 标记系统::对象^ 垂直分辨率96.000000浮点 宽度640整数 国家图像2657511290992 原始数据数组^ 用户数据系统::对象^ ImageLocation系统::字符串^
  • 图像矩形{X=0 Y=0宽度=640高度=480}系统::绘图::矩形 ImeMode系统::Windows::Forms::ImeMode::禁用系统::Windows::Forms::ImeMode
  • InitialImage 0x0000026aa629c568{nativeImage=2657511196256 rawData=userData=}系统::绘图::图像^ PICTUREBOXSTATE_异步操作进度1 int PICTUREBOXSTATE_取消挂起2 int PICTUREBOXSTATE_初始化64 int PICTUREBOXSTATE_需要加载图像位置32 int PICTUREBOXSTATE_useDefaultErrorImage 8 int PICTUREBOXSTATE_useDefaultInitialImage 4 int PICTUREBOXSTATE_waitOnLoad 16 int RightToLeft系统::Windows::Forms::RightToLeft::无系统::Windows::Forms::RightToLeft SizeMode System::Windows::Forms::PictureBoxSizeMode::普通系统::Windows::Forms::PictureBoxSizeMode TabIndex 1 int 止跳假波 文本“”系统::字符串^ 等待加载假布尔 borderStyle系统::Windows::Forms::borderStyle::None系统::Windows::Forms::borderStyle contentLength 0 int currentAsyncLoadOperation System::ComponentModel::AsyncOperation^ 当前animating假布尔
  • defaultErrorImage 0x0000026aa629b110{nativeImage=2657
    private: System::Void button2_MouseClick(System::Object^  sender, System::Windows::Forms::MouseEventArgs^  e)
    {
        if (button2->Text == "Stop")
        {
            button2->Text = "Start";
    
        }
        else if (button2->Text == "Start")
        {
            button2->Text = "Stop";
    
        }
    
         VideoCapture capture(0);
         Mat frame;
    
         while (button2->Text == "Stop")
         {
             capture.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, 0, pictureBox1->Width, pictureBox1->Height);
             graphics2->DrawImage(b2, rect2);
    
         }
     }