Пример #1
0
 // Stop the camera from streaming.
 static void CameraStop()
 {
     Console.WriteLine("The streaming is now being stopped.");
     Pv.CommandRun(GCamera.Handle, "AcquisitionStop");
     Pv.CaptureEnd(GCamera.Handle);
     // Clear the queue.
     Pv.CaptureQueueClear(GCamera.Handle);
 }
Пример #2
0
        // Setup the camera for capture.
        static bool CameraSetup()
        {
            UInt32 FrameSize = 0;

            // Get the byte size of the buffer.
            if (Pv.AttrUint32Get(GCamera.Handle, "TotalBytesPerFrame", ref FrameSize) == 0)
            {
                GCamera.Buffer = new byte[FrameSize];
                GCamera.GC     = GCHandle.Alloc(GCamera.Buffer, GCHandleType.Pinned);
                // Address of pinned buffer.
                GCamera.Frame.ImageBuffer = GCamera.GC.AddrOfPinnedObject();
                // Buffer size.
                GCamera.Frame.ImageBufferSize = FrameSize;

                // Start the capture mode.
                if (Pv.CaptureStart(GCamera.Handle) == 0)
                {
                    // Set the acquisition mode into continuous and hardware trigger mode, using SyncIn2 (non-isolated).
                    if (Pv.AttrEnumSet(GCamera.Handle, "FrameStartTriggerMode", "SyncIn2") == 0)

                    // Set the acquisition mode into continuous and hardware trigger mode, using SyncIn1 (isolated).
                    // if (Pv.AttrEnumSet(GCamera.Handle, "FrameStartTriggerMode", "SyncIn1") == 0)

                    {
                        // Set the acquisition mode into continuous.
                        if (Pv.CommandRun(GCamera.Handle, "AcquisitionStart") != 0)
                        {
                            // if that fails, reset the camera to non capture mode.
                            Pv.CaptureEnd(GCamera.Handle);
                            return(false);
                        }
                        else
                        {
                            return(true);
                        }
                    }
                    else
                    {
                        return(false);
                    }
                }
                else
                {
                    return(true);
                }
            }
            else
            {
                return(false);
            }
        }
Пример #3
0
        // Setup the camera for capture.
        static bool CameraSetup(ref tCamera Camera)
        {
            UInt32 FrameSize  = 0;
            UInt32 FrameCount = 600;

            // Get the byte size of the buffer.
            if (Pv.AttrUint32Get(Camera.Handle, "TotalBytesPerFrame", ref FrameSize) == 0)
            {
                Camera.Buffer = new byte[FrameSize];
                Camera.GC     = GCHandle.Alloc(Camera.Buffer, GCHandleType.Pinned);
                // Address of the pinned buffer
                Camera.Frame.ImageBuffer = Camera.GC.AddrOfPinnedObject();
                // Buffer size.
                Camera.Frame.ImageBufferSize = FrameSize;

                Console.WriteLine("We have allocated {0} frames of {1} bytes each.", FrameCount, FrameSize);

                // Start the capture mode.
                if (Pv.CaptureStart(Camera.Handle) == 0)
                {
                    // Set the camera in software acquisition mode.
                    if (Pv.AttrEnumSet(Camera.Handle, "FrameStartTriggerMode", "Software") == 0)
                    {
                        // Set the acquisition mode into continuous.
                        if (Pv.CommandRun(Camera.Handle, "AcquisitionStart") != 0)
                        {
                            // If that fails, reset the camera to non capture mode.
                            Pv.CaptureEnd(Camera.Handle);
                            return(false);
                        }
                        else
                        {
                            return(true);
                        }
                    }
                    else
                    {
                        return(false);
                    }
                }
                else
                {
                    return(true);
                }
            }
            else
            {
                return(false);
            }
        }
Пример #4
0
        // Start streaming frames.
        static bool DoStream(ref tCamera Camera)
        {
            tErr           Err;
            UInt32         FrameCount = 0;
            GCHandle       pFrame     = GCHandle.Alloc(Camera.Frame, GCHandleType.Pinned);
            tFrameCallback FrameCB    = new tFrameCallback(FrameDummyCBStream);
            uint           timeout    = 1000;

            // Adjust packet for optimal preformance.
            Pv.CaptureAdjustPacketSize(Camera.Handle, 8228);

            Console.WriteLine("Streaming has started...");

            // Set the camera in acquisition mode.
            if (((Err = Pv.CaptureStart(Camera.Handle)) == 0))
            {
                if ((Pv.CommandRun(Camera.Handle, "AcquisitionStart")) != 0)
                {
                    // If that fails, reset the camera to non capture mode.
                    Pv.CaptureEnd(Camera.Handle);
                    Console.WriteLine("PvCommandRun() failed!");
                    return(false);
                }
                else
                {
                    // Stream for a total of 30 frames.
                    while (FrameCount < 100)
                    {
                        if (Pv.CaptureQueueFrame(Camera.Handle, pFrame.AddrOfPinnedObject(), FrameCB) == 0)
                        {
                            Pv.CaptureWaitForFrameDone(Camera.Handle, pFrame.AddrOfPinnedObject(), timeout);
                            FrameCount++;
                        }
                    }
                    // After the 30 frames, stop streaming.
                    CameraStop(ref Camera);
                    Console.WriteLine("Streaming stopped.");
                    return(true);
                }
            }
            else
            {
                Console.WriteLine("PvCaptureStart() failed with error code {0}.", Err);
                return(false);
            }
        }
Пример #5
0
        // Snap a frame.
        static bool DoSnap(ref tCamera Camera)
        {
            GCHandle       pFrame  = GCHandle.Alloc(Camera.Frame, GCHandleType.Pinned);
            tFrameCallback FrameCB = new tFrameCallback(FrameDummyCBSnap);
            uint           timeout = 1000;

            // Set the camera is acquisition mode.
            if ((Pv.CaptureStart(Camera.Handle)) == 0)
            {
                // Set the acquisition mode to continuous.
                if ((Pv.CommandRun(Camera.Handle, "AcquisitionStart")) != 0)
                {
                    // If that fails,reset the camera to non capture mode.
                    Pv.CaptureEnd(Camera.Handle);
                    return(false);
                }
                else
                {
                    bool failed = false;

                    // Enqueue the single frame.
                    if (Pv.CaptureQueueFrame(Camera.Handle, pFrame.AddrOfPinnedObject(), FrameCB) == 0)
                    {
                        Console.WriteLine("Waiting for the frame...");
                        failed = Pv.CaptureWaitForFrameDone(Camera.Handle, pFrame.AddrOfPinnedObject(), timeout) != 0;
                        Console.WriteLine("Frame is done...");
                        Console.WriteLine("Snapping done.");
                    }
                    else
                    {
                        failed = true;
                    }

                    Pv.CommandRun(Camera.Handle, "AcquisitionStop");
                    Pv.CaptureEnd(Camera.Handle);
                    return(!failed);
                }
            }
            else
            {
                return(false);
            }
        }
Пример #6
0
 public void EndCapture()
 {
     if (!camera.HasValue)
     {
         throw new PvException(tErr.eErrUnavailable);
     }
     Pv.CaptureQueueClear(this.camera.Value);
     foreach (GCHandle handle in framePoolHandles)
     {
         handle.Free();
     }
     foreach (GCHandle handle in frameBufferHandles)
     {
         handle.Free();
     }
     frames = null;
     Pv.CommandRun(this.camera.Value, "AcquisitionStop");
     Pv.CaptureEnd(this.camera.Value);
 }
Пример #7
0
        // Setup the camera for capture.
        static bool CameraStart(ref tCamera Camera)
        {
            UInt32 FrameSize = 0;

            // Adjust packet for optimal preformance.
            Pv.CaptureAdjustPacketSize(Camera.Handle, 8228);

            // Get the bytes size of the buffer.
            if (Pv.AttrUint32Get(Camera.Handle, "TotalBytesPerFrame", ref FrameSize) == 0)
            {
                Camera.Buffer = new byte[FrameSize];
                Camera.GC     = GCHandle.Alloc(Camera.Buffer, GCHandleType.Pinned);
                // Address of the pinned buffer.
                Camera.Frame.ImageBuffer = Camera.GC.AddrOfPinnedObject();
                // Buffer size.
                Camera.Frame.ImageBufferSize = FrameSize;

                // Start the capture mode.
                if (Pv.CaptureStart(Camera.Handle) == 0)
                {
                    //  Set the acquisition mode into continuous.
                    if (Pv.CommandRun(Camera.Handle, "AcquisitionStart") != 0)
                    {
                        // If that fails, reset the camera to non capture mode.
                        Pv.CaptureEnd(Camera.Handle);
                        return(false);
                    }
                    else
                    {
                        return(true);
                    }
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }
Пример #8
0
 // Stop the streaming.
 static void CameraStop(ref tCamera Camera)
 {
     Pv.CommandRun(Camera.Handle, "AcquisitionStop");
     Pv.CaptureEnd(Camera.Handle);
     Pv.CaptureQueueClear(Camera.Handle);
 }
Пример #9
0
        // Setup the camera up for streaming.
        static bool CameraStart()
        {
            UInt32 FrameSize = 0;

            // Adjust packet size for optimal performance.
            Pv.CaptureAdjustPacketSize(GCamera.Handle, 8228);

            // Determines how big the frame buffers should be.
            if (Pv.AttrUint32Get(GCamera.Handle, "TotalBytesPerFrame", ref FrameSize) == 0)
            {
                tFrame   Frame   = new tFrame();
                byte[]   Buffer  = new byte[FrameSize];
                GCHandle pBuffer = GCHandle.Alloc(Buffer, GCHandleType.Pinned);

                // Set the frame's fields.
                // Handle to the Camera.
                Frame.Context.Field0 = new IntPtr(GCamera.Handle);
                // Address of the pinned object.
                Frame.ImageBuffer = pBuffer.AddrOfPinnedObject();
                // Buffer size.
                Frame.ImageBufferSize = FrameSize;

                // Start the capture mode.
                if (Pv.CaptureStart(GCamera.Handle) == 0)
                {
                    // Set the camera in continuous acquisition mode,and in "Freerun".
                    if (Pv.AttrEnumSet(GCamera.Handle, "FrameStartTriggerMode", "Freerun") == 0)
                    {
                        // Set the acquisition mode into continuous.
                        if (Pv.CommandRun(GCamera.Handle, "AcquisitionStart") != 0)
                        {
                            // If that fails, reset the camera to non-capture mode.
                            Pv.CaptureEnd(GCamera.Handle);

                            Console.WriteLine("Failed to start.");
                            return(false);
                        }
                        else
                        {
                            // Pin down a copy of the frame structure.
                            GCHandle pFrame = GCHandle.Alloc(Frame, GCHandleType.Pinned);

                            // Enqueue the frame.
                            Pv.CaptureQueueFrame(GCamera.Handle, pFrame.AddrOfPinnedObject(), FrameCB);

                            return(true);
                        }
                    }
                    else
                    {
                        return(false);
                    }
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }
Пример #10
0
        // Setup the camera up for streaming.
        static bool CameraStart()
        {
            tFrameCallback       lFrameCB = new tFrameCallback(FrameDoneCB);
            tCameraEventCallback lEventCB = new tCameraEventCallback(EventDone);
            UInt32 FrameSize = 0;
            IntPtr Context   = IntPtr.Zero;


            if (Pv.AttrExists(GCamera.Handle, "EventsEnable1") == tErr.eErrNotFound)
            {
                Console.WriteLine("This camera does not support event notifications.");
                return(false);
            }

            // Adjust packet size for optimal performance.
            Pv.CaptureAdjustPacketSize(GCamera.Handle, 8228);

            // Determines how big the frame buffers should be.
            if (Pv.AttrUint32Get(GCamera.Handle, "TotalBytesPerFrame", ref FrameSize) == 0)
            {
                tFrame   Frame   = new tFrame();
                byte[]   Buffer  = new byte[FrameSize];
                GCHandle pBuffer = GCHandle.Alloc(Buffer, GCHandleType.Pinned);

                // Set the frame's fields.
                // Handle to the Camera.
                Frame.Context.Field0 = new IntPtr(GCamera.Handle);
                // Address of the pinned object.
                Frame.ImageBuffer = pBuffer.AddrOfPinnedObject();
                // Buffer size.
                Frame.ImageBufferSize = FrameSize;

                // Setup the event channel.
                Pv.AttrUint32Set(GCamera.Handle, "EventsEnable1", 0);
                Pv.AttrEnumSet(GCamera.Handle, "EventSelector", "AcquisitionStart");
                Pv.AttrEnumSet(GCamera.Handle, "EventNotification", "On");
                Pv.AttrEnumSet(GCamera.Handle, "EventSelector", "AcquisitionEnd");
                Pv.AttrEnumSet(GCamera.Handle, "EventNotification", "On");
                Pv.AttrEnumSet(GCamera.Handle, "EventSelector", "FrameTrigger");
                Pv.AttrEnumSet(GCamera.Handle, "EventNotification", "On");


                if (Pv.CameraEventCallbackRegister(GCamera.Handle, lEventCB, Context) != tErr.eErrSuccess)
                {
                    Console.WriteLine("There was an error accessing the driver.");
                    return(false);
                }

                // Start the capture mode.
                if (Pv.CaptureStart(GCamera.Handle) == 0)
                {
                    if (Pv.AttrFloat32Set(GCamera.Handle, "FrameRate", 5) == 0)
                    {
                        // Set the camera in continuous acquisition mode,and in "Freerun".
                        if (Pv.AttrEnumSet(GCamera.Handle, "FrameStartTriggerMode", "FixedRate") == 0)
                        {
                            // Set the acquisition mode into continuous.
                            if (Pv.CommandRun(GCamera.Handle, "AcquisitionStart") != 0)
                            {
                                // If that fails, reset the camera to non-capture mode.
                                Pv.CaptureEnd(GCamera.Handle);

                                Console.WriteLine("Failed to start.");
                                return(false);
                            }
                            else
                            {
                                // Pin down a copy of the frame structure.
                                GCHandle pFrame = GCHandle.Alloc(Frame, GCHandleType.Pinned);

                                // Enqueue the frame.
                                Pv.CaptureQueueFrame(GCamera.Handle, pFrame.AddrOfPinnedObject(), lFrameCB);

                                return(true);
                            }
                        }
                        else
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        return(false);
                    }
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }
Пример #11
0
 // Stop the streaming.
 static void CameraStop()
 {
     Pv.CommandRun(GCamera.Handle, "AcquisitionStop");
     Pv.CaptureEnd(GCamera.Handle);
 }
Пример #12
0
 // Stop the streaming.
 static void CameraStop(ref tCamera Camera)
 {
     Console.WriteLine("Streaming is being stopped.");
     Pv.CommandRun(Camera.Handle, "AcquisitionStop");
     Pv.CaptureEnd(Camera.Handle);
 }