Example #1
0
        private async Task captureThread()
        {
            var count = 0;

            try {
                var capture = new VideoCapture(deviceId);
                while (!cancelToken.IsCancellationRequested)
                {
                    if (capture.IsOpened())
                    {
                        Bitmap bitmap      = null;
                        var    normalFrame = new Mat();
                        capture.Read(normalFrame);

                        try {
                            bitmap = Effector?.ToBitmap(normalFrame);
                        }
                        catch (Exception e) {
                            error = e.Message;
                        }

                        if (bitmap == null)
                        {
                            bitmap = BitmapConverter.ToBitmap(normalFrame);
                        }
                        normalFrame.Dispose();

                        if (count == 0)
                        {
                            count++;
                            BeginInvoke(new MethodInvoker(() => {
                                if (this.bitmap != null)
                                {
                                    this.bitmap.Dispose();
                                }

                                this.bitmap = bitmap;
                                UpdateImage();
                                count--;
                            }));
                        }
                    }

                    await Task.Delay(1);
                }

                capture.Release();
            }
            catch (Exception e) {
                error = e.Message;
            }
        }