简体   繁体   English

网络摄像头从相机保存而不冻结应用

[英]Webcam saving from camera without freezing application

Hey I am trying to save a video of a webcam and save it as uncompressed. 嘿,我正在尝试保存网络摄像头的视频,并将其保存为未压缩。 However Anytime click on the save button the application freezes until the save is complete. 但是,无论何时单击保存按钮,应用程序都会冻结,直到保存完成。 I will be grateful for any advice given. 我将不胜感激任何建议。 I am using managed code for the webcam "FLea 3" (from Points grey) 我正在使用托管代码“FLea 3”的托管代码(来自Points灰色)

    private void button1_Click(object sender, EventArgs e)
    {
       uint k_numImages = 100;
       // ManagedAVIRecorder aviRecorder = new ManagedAVIRecorder();
       // List<ManagedImage> imageList = new List<ManagedImage>();



            List<ManagedImage> imageList = new List<ManagedImage>();
            ManagedImage rawImage = new ManagedImage(m_rawImage);
           for (int imageCnt = 0; imageCnt < k_numImages; imageCnt++)
       // while (m_grabImages == true)
            {
                m_camera.RetrieveBuffer(rawImage);
                ManagedImage tempImage = new ManagedImage(rawImage);
                imageList.Add(tempImage);

             }


            if (m_grabImages==true)
            {
           //Encoding bit
            string aviFileName;



            AviOption option = new AviOption();
            option.frameRate = 24;
            aviFileName = String.Format("SaveCSharp-aviuncompressed");
            aviRecorder.AVIOpen(aviFileName, option);
           // aviFileName = String.Format("SaveCSharp-h264");
          //  H264Option option = new H264Option();
          //  option.frameRate = 24;
          //  option.bitrate = 20000000;
          //  option.height = Convert.ToInt32(m_rawImage.rows);
           // option.width = Convert.ToInt32(m_rawImage.cols);
         //   aviRecorder.AVIOpen(aviFileName, option);

         for (int imageCnt = 0; imageCnt < imageList.Count; imageCnt++)
                {
                    aviRecorder.AVIAppend(imageList[imageCnt]);



                }
             aviRecorder.AVIClose();
            }




        }

    private void button2_Click(object sender, EventArgs e)
    {
    //  aviRecorder.AVIClose();
    }
    }



   }

You most likely want to run the record operation on another thread. 您很可能希望在另一个线程上运行记录操作。 However, that'll get slightly tricky as you have to pass messages back and forth to the recorder thread, to tell it when to stop, for example. 但是,这会变得有点棘手,因为你必须来回传递消息到记录器线程,告诉它何时停止,例如。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM