AForge.Video.Ximea.XimeaCamera.StartAcquisition C# (CSharp) Метод

StartAcquisition() публичный Метод

Begin camera's work cycle and start data acquisition from it.

The IsAcquisitionStarted property can be used at any time to find if the acquisition was started or not.

An error occurred while communicating with a camera. See error /// message for additional information. No camera was opened, so can not access its methods.
public StartAcquisition ( ) : void
Результат void
        public void StartAcquisition( )
        {
            lock ( sync )
            {
                CheckConnection( );

                int errorCode = XimeaAPI.xiStartAcquisition( deviceHandle );
                HandleError( errorCode );

                isAcquisitionStarted = true;
            }
        }

Usage Example

Пример #1
0
        // Worker thread
        private void WorkerThread()
        {
            var reasonToStop = ReasonToFinishPlaying.StoppedByUser;

            try
            {
                camera.StartAcquisition();

                // while there is no request for stop
                while (!stopEvent.WaitOne(0, false))
                {
                    // start time
                    var start = DateTime.Now;

                    // get next frame
                    var bitmap = camera.GetImage(15000, false);

                    framesReceived++;
                    bytesReceived += bitmap.Width * bitmap.Height * (Bitmap.GetPixelFormatSize(bitmap.PixelFormat) >> 3);

                    if (NewFrame != null)
                    {
                        NewFrame(this, new NewFrameEventArgs(bitmap));
                    }

                    // free image
                    bitmap.Dispose();

                    // wait for a while ?
                    if (frameInterval > 0)
                    {
                        // get frame duration
                        var span = DateTime.Now.Subtract(start);

                        // miliseconds to sleep
                        var msec = frameInterval - (int)span.TotalMilliseconds;

                        if ((msec > 0) && (stopEvent.WaitOne(msec, false)))
                        {
                            break;
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                reasonToStop = ReasonToFinishPlaying.VideoSourceError;
                // provide information to clients
                if (VideoSourceError != null)
                {
                    VideoSourceError(this, new VideoSourceErrorEventArgs(exception.Message));
                }
            }
            finally
            {
                try
                {
                    camera.StopAcquisition();
                }
                catch
                {
                }
            }

            if (PlayingFinished != null)
            {
                PlayingFinished(this, reasonToStop);
            }
        }