1

I have a small project whereby I capture images from a webcam and decode the qr.

The following code captures an image and stores it to a local file, but only when it is not in the while loop. The system.threading appears to make the captured image just black. If i don't use it(the loop), it captures far too many images a second.

So is there a way of changing the aforge.video framerate so that i can capture an image every x seconds without while loop?

   public partial class WebForm1 : System.Web.UI.Page
{
    public int FrameRate { get; set; }

    private FilterInfoCollection VideoCaptureDevices;
    private VideoCaptureDevice FinalVideo;

    protected void Page_Load(object sender, EventArgs e)
    {
        inputDevices.Items.Clear();

        VideoCaptureDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
        foreach (FilterInfo VideoCaptureDevice in VideoCaptureDevices)
        {
            inputDevices.Items.Add(VideoCaptureDevice.Name);
        }
        inputDevices.SelectedIndex = 0;     
    }

    public void Start_OnClick(object sender, EventArgs e)
    {
        FinalVideo = new VideoCaptureDevice(VideoCaptureDevices[inputDevices.SelectedIndex].MonikerString);
        FinalVideo.NewFrame += new NewFrameEventHandler(FinalVideo_NewFrame);
        FinalVideo.Start();
    }
    void FinalVideo_NewFrame(object sender, NewFrameEventArgs eventArgs)
    {
        int i = 0;
        while (i < 10)
        {
            Bitmap video = (Bitmap)eventArgs.Frame.Clone();
            video.Save("C:\\Users\\Wayneio\\Desktop\\image\\test" + i + ".jpg");
            i++;
            System.Threading.Thread.Sleep(5000);
        }

    }
    public void Stop_OnClick(object sender, EventArgs e)
    {
        this.FinalVideo.Stop();
    }
}

Additionally I get this error when trying to stop the capture via the asp button:

 Object reference not set to an instance of an object on this.FinalVideo.Stop();

Tried this to no avail: ((VideoCaptureDevice)FinalVideo).DesiredFrameRate = 10;

4

1 に答える 1

-1

開始ビデオをコーディングする前に、このようにフレームレートを設定します

 FinalVideo.DesiredFrameRate = 10;
 FinalVideo.Start();

保存するフレームをスキップする別のオプションは、グローバル カウンター値 myCounter がある場合に常に true とは限らない関数を使用することです。

以下のようなモジュロ計算を行う ix mycounter を 10 で割ると 1 に等しい

 myCounter++
 if (m(ycounter %% 10))==1) { //code to save your bitmap   }
于 2012-11-06T19:00:25.917 に答える