예제 #1
0
        // Keeps track of data being streamed from the camera.
        static void ThreadFunc()
        {
            tErr   Err;
            UInt32 Dropped, Done, Completed;
            UInt32 Total, Missed, Errs;
            int    Before, Now, Elapsed;
            double Fps;
            float  Rate;

            Dropped   = 0;
            Missed    = 0;
            Completed = 0;
            Errs      = 0;
            Rate      = 0;
            Fps       = 0;
            Elapsed   = 0;
            Total     = 0;
            Done      = 0;

            // Start timing.
            Before = GetTickCount();

            // Get some infomation about the streaming process.
            while (Close == false && ((Err = Pv.AttrUint32Get(GCamera.Handle, "StatFramesCompleted", ref Completed)) == 0) &&
                   ((Err = Pv.AttrUint32Get(GCamera.Handle, "StatFramesDropped", ref Dropped)) == 0) &&
                   ((Err = Pv.AttrUint32Get(GCamera.Handle, "StatPacketsMissed", ref Missed)) == 0) &&
                   ((Err = Pv.AttrUint32Get(GCamera.Handle, "StatPacketsErroneous", ref Errs)) == 0) &&
                   ((Err = Pv.AttrFloat32Get(GCamera.Handle, "StatFrameRate", ref Rate)) == 0))
            {
                // Store the elapsed time.
                Now = GetTickCount();

                // Keep track of the total amount of frames completed.
                Total += (Completed - Done);

                // Keep track of the total time that has elapsed.
                Elapsed += (Now - Before);

                // Updates the Fps rate every 500 milliseconds.
                if (Elapsed >= 500)
                {
                    Fps     = (double)(Total * 1000.0) / (double)Elapsed;
                    Elapsed = 0;
                    Total   = 0;
                }

                // Display the current infomation.
                //Console.WriteLine("Completed : {0} Dropped : {1} Missed : {2} Err {3} Rate: {4:.00} <{5:.00}>", Completed, Dropped, Missed, Errs, Rate, Fps);

                Before = GetTickCount();
                Done   = Completed;
                Thread.Sleep(20);
            }
            Console.WriteLine();
        }