cv :: Mat推回std :: vector问题

时间:2018-08-21 16:03:02

标签: c++ opencv camera video-processing push-back

目标是从basler相机(带有pylon)中读取图像以获取opencv矩阵,然后使用std::vector方法将其加载到push_back()容器中。我的尝试失败了,因为所有保存的元素都将是最后一个。因此,如果我推回295元素,则所有295图像都将是相同的(最后一个)。我将编写一个摘要代码:

    try
    {
       auto TestCam1 = interfaces::Basler::ICamera_Basler_USB3("21993673", true); 
       interfaces::ICamera* Camera1 = TestCam1.getCamera(); //We can use Basler_USB3 as an ICamera
       Camera1->open();
       cout << "Cam1 opened" << endl;

       static_cast<ICamera_Basler_USB3*>(Camera1)->Set_Sensor_Pixel_Format("BayerBG12");
       static_cast<ICamera_Basler_USB3*>(Camera1)->Set_Width(500);
       static_cast<ICamera_Basler_USB3*>(Camera1)->Set_Height(500);
       static_cast<ICamera_Basler_USB3*>(Camera1)->Set_Exposure_Auto(false);
       static_cast<ICamera_Basler_USB3*>(Camera1)->Set_Exposure(exp_val);
       static_cast<ICamera_Basler_USB3*>(Camera1)->Set_Enable_Acquisition_Frame_Rate(true);
       static_cast<ICamera_Basler_USB3*>(Camera1)->Set_Acquisition_Frame_Rate(20);

       unsigned int cam_width=static_cast<ICamera_Basler_USB3*>(Camera1)->Get_Width();
       unsigned int cam_height=static_cast<ICamera_Basler_USB3*>(Camera1)->Get_Height();


       cv::Mat cv_img1(cam_width, cam_height, CV_16UC3);
       std::vector<cv::Mat> video;


       bool first_run = true;


       Camera1->initGrabStream();

       while(1){

           cv_img1=Camera1->getLastFrameStream(); //give back frame_time and frame_num
           video.push_back(cv_img1);

           std::cout << "Buffer size: " << video.size() << std::endl;

           if (video.size() == 295 && first_run == true)
           {

               funtionToEvaluateRecordedVideo(video);
               first_run = false;
               video.erase(video.begin(), video.end());
           }
           else if (video.size() == 40 && first_run == false)
           {
               funtionToEvaluateRecordedVideo(video);
               video.erase(video.begin(), video.end());
           }



           // Here the interesting thing (and my problem) is that BOTH 
           // window shows the same image!
           cv::imshow("Camera disp", video[video.size()-1]*15);
           cv::imshow("Debug, buffer img1", video[0]*15);
           if(waitKey(1) > 0)
           {
               Camera1->close();
               break;
           }

       }
       Camera1->Stop_Recording();
   }
   catch (GenICam::GenericException &e)
   {
       // Error handling.
       cerr << "An exception occurred." << endl
       << e.GetDescription() << endl;
       exitCode = 1;
   }

总结问题:当前帧(从相机获取)推回到容器std::vector的末端。出于某种原因,容器向量的所有元素都是相同的,最后一个是相同的。

0 个答案:

没有答案