Esempio n. 1
0
        private void OnStopRecord(object sender, EventArgs e)
        {
            int err;

            err = PCO_SDK_LibWrapper.PCO_SetRecordingState(f_CameraHandle, 0);
            cbGrabCamera.IsEnabled = false;
            if (camDialog != IntPtr.Zero)
            {
                PCO_SDK_LibWrapper.PCO_EnableDialogCam(camDialog, true);
            }
            err = PCO_SDK_LibWrapper.PCO_CancelImages(f_CameraHandle);
            f_CameraTimer.Stop();
        }
Esempio n. 2
0
        private void OnGetDescription(object sender, System.EventArgs e)
        {
            pcoCameraType = new PCO_CameraType();
            pcoDescr      = new PCO_Description();
            pcoStorage    = new PCO_Storage();
            pcoImage      = new PCO_Image();

            pcoDescr.wSize   = (ushort)Marshal.SizeOf(pcoDescr);
            pcoStorage.wSize = (ushort)Marshal.SizeOf(pcoStorage);
            pcoImage.wSize   = (ushort)Marshal.SizeOf(pcoImage);
            var err = PCO_SDK_LibWrapper.PCO_GetCameraDescription(f_CameraHandle, ref pcoDescr);

            err = PCO_SDK_LibWrapper.PCO_GetStorageStruct(f_CameraHandle, ref pcoStorage);

            pcoImage.strSegment = new PCO_Segment[4];

            pcoImage.strSegment[0].wSize = (ushort)Marshal.SizeOf(typeof(PCO_Segment));
            pcoImage.strSegment[1].wSize = (ushort)Marshal.SizeOf(typeof(PCO_Segment));
            pcoImage.strSegment[2].wSize = (ushort)Marshal.SizeOf(typeof(PCO_Segment));
            pcoImage.strSegment[3].wSize = (ushort)Marshal.SizeOf(typeof(PCO_Segment));

            err = PCO_SDK_LibWrapper.PCO_GetImageStruct(f_CameraHandle, ref pcoImage);

            var usfwsize = (ushort)Marshal.SizeOf(typeof(PCO_SC2_Firmware_DESC));

            usfwsize = (ushort)Marshal.SizeOf(typeof(PCO_FW_Vers));
            pcoCameraType.strHardwareVersion.Board  = new PCO_SC2_Hardware_DESC[10];
            pcoCameraType.strFirmwareVersion.Device = new PCO_SC2_Firmware_DESC[10];
            for (var i = 0; i < 10; i++)
            {
                pcoCameraType.strHardwareVersion.Board[i].szName  = "123456789012345";
                pcoCameraType.strFirmwareVersion.Device[i].szName = "123456789012345";
            }
            pcoCameraType.wSize = (ushort)Marshal.SizeOf(pcoCameraType);

            err = PCO_SDK_LibWrapper.PCO_GetCameraType(f_CameraHandle, ref pcoCameraType);

            var szCameraName = new byte[30];

            err = PCO_SDK_LibWrapper.PCO_GetCameraName(f_CameraHandle, szCameraName, 30);

            SetupConvert();

            cbStartCamera.IsEnabled = true;
            cbStopCamera.IsEnabled  = true;
        }
Esempio n. 3
0
        private void ConnectToCamera(object sender, RoutedEventArgs e)
        {
            const ushort boardNum = 1;

            f_CameraHandle  = IntPtr.Zero;
            f_ConvertHandle = IntPtr.Zero;
            convertDialog   = IntPtr.Zero;
            camDialog       = IntPtr.Zero;
            bufwidth        = 0;
            bufheight       = 0;

            // Verify board number validity
            // Open a handle to the camera
            try
            {
                var err = PCO_SDK_LibWrapper.PCO_OpenCamera(ref f_CameraHandle, boardNum);
                if (err == 0)
                {
                    ushort wrecState = 0;
                    cbStartCamera.IsEnabled    = false;
                    cbStopCamera.IsEnabled     = false;
                    cbGetDescription.IsEnabled = true;
                    cbOpenCamera.IsEnabled     = false;
                    cbCloseCamera.IsEnabled    = true;

                    PCO_SDK_LibWrapper.PCO_GetRecordingState(f_CameraHandle, ref wrecState);
                    if (wrecState != 0)
                    {
                        PCO_SDK_LibWrapper.PCO_SetRecordingState(f_CameraHandle, 0);
                    }

                    // buttonOpenCamDialog.Enabled = true;
                }
                else
                {
                    err = PCO_SDK_LibWrapper.PCO_ResetLib();
                }
            }
            catch (Exception ex)
            {
                LogBox.Items.Insert(0, new LogBoxItem {
                    Dt = DateTime.Now, LogText = $"Ошибка соединения с камерой {ex}"
                });
            }
        }
Esempio n. 4
0
        private void SetupConvert()
        {
            pcoDescr       = new PCO_Description();
            pcoDescr.wSize = (ushort)Marshal.SizeOf(pcoDescr);
            int err = 0;

            err = PCO_SDK_LibWrapper.PCO_GetCameraDescription(f_CameraHandle, ref pcoDescr);
            PCO_ConvertStructures.PCO_SensorInfo strsensorinf = new PCO_ConvertStructures.PCO_SensorInfo();
            PCO_ConvertStructures.PCO_Display    strDisplay   = new PCO_ConvertStructures.PCO_Display();
            strsensorinf.wSize              = (ushort)Marshal.SizeOf(strsensorinf);
            strDisplay.wSize                = (ushort)Marshal.SizeOf(strDisplay);
            strsensorinf.wDummy             = 0;
            strsensorinf.iConversionFactor  = 0;
            strsensorinf.iDataBits          = pcoDescr.wDynResDESC;
            strsensorinf.iSensorInfoBits    = 1;
            strsensorinf.iDarkOffset        = 100;
            strsensorinf.dwzzDummy0         = 0;
            strsensorinf.strColorCoeff.da11 = 1.0;
            strsensorinf.strColorCoeff.da12 = 0.0;
            strsensorinf.strColorCoeff.da13 = 0.0;
            strsensorinf.strColorCoeff.da21 = 0.0;
            strsensorinf.strColorCoeff.da22 = 1.0;
            strsensorinf.strColorCoeff.da23 = 0.0;
            strsensorinf.strColorCoeff.da31 = 0.0;
            strsensorinf.strColorCoeff.da32 = 0.0;
            strsensorinf.strColorCoeff.da33 = 1.0;
            strsensorinf.iCamNum            = 0;
            strsensorinf.hCamera            = f_CameraHandle;

            int errorCode;

            /* We created a pointer to a convert object here */
            errorCode = PCO_Convert_LibWrapper.PCO_ConvertCreate(ref f_ConvertHandle, ref strsensorinf, PCO_Convert_LibWrapper.PCO_COLOR_CONVERT);

            PCO_ConvertStructures.PCO_Convert pcoConv = new PCO_ConvertStructures.PCO_Convert();;

            pcoConv.wSize = (ushort)Marshal.SizeOf(pcoConv);
            errorCode     = PCOConvertDll.PCO_Convert_LibWrapper.PCO_ConvertGet(f_ConvertHandle, ref pcoConv);
            pcoConv.wSize = (ushort)Marshal.SizeOf(pcoConv);

            IntPtr debugIntPtr = f_ConvertHandle;

            PCO_ConvertStructures.PCO_Convert pcoConvertlocal = (PCO_ConvertStructures.PCO_Convert)Marshal.PtrToStructure(debugIntPtr, typeof(PCO_ConvertStructures.PCO_Convert));
        }
Esempio n. 5
0
        private void OnStartRecord(object sender, EventArgs e)
        {
            int    err;
            uint   dwWarn = 0, dwError = 0, dwStatus = 0;
            ushort width     = 0;
            ushort height    = 0;
            ushort widthmax  = 0;
            ushort heightmax = 0;

            // It is recommended to call this function in order to get information about the camera internal state
            err = PCO_SDK_LibWrapper.PCO_GetCameraHealthStatus(f_CameraHandle, ref dwWarn, ref dwError, ref dwStatus);
            PCO_SDK_LibWrapper.PCO_SetTriggerMode(f_CameraHandle, 0);
            err = PCO_SDK_LibWrapper.PCO_ArmCamera(f_CameraHandle);
            err = PCO_SDK_LibWrapper.PCO_GetSizes(f_CameraHandle, ref width, ref height, ref widthmax, ref heightmax);
            err = PCO_SDK_LibWrapper.PCO_CamLinkSetImageParameters(f_CameraHandle, (UInt16)width, (UInt16)height);

            err = PCO_SDK_LibWrapper.PCO_SetRecordingState(f_CameraHandle, 1);
            cbGrabCamera.IsEnabled = true;
            if (camDialog != IntPtr.Zero)
            {
                PCO_SDK_LibWrapper.PCO_EnableDialogCam(camDialog, false);
            }
            f_CameraTimer.Start();
        }
Esempio n. 6
0
        private void OnGrabImage(object sender, EventArgs evt)
        {
            int err = 0;
            int size;

            System.IntPtr evhandle;
            Bitmap        imagebmp;
            UIntPtr       buf;
            bool          bauto = true;     // set this to true to get auto min max

            UInt16 width       = 0;
            UInt16 height      = 0;
            UInt16 widthmax    = 0;
            UInt16 heightmax   = 0;
            int    ishift      = 16 - pcoDescr.wDynResDESC;
            int    ipadd       = width / 4;
            int    iconvertcol = pcoDescr.wColorPatternDESC / 0x1000;
            int    max;
            int    min;

            ipadd *= 4;
            ipadd  = width - ipadd;

            err  = PCO_SDK_LibWrapper.PCO_GetSizes(f_CameraHandle, ref width, ref height, ref widthmax, ref heightmax);
            size = width * height * 2;

            buf      = UIntPtr.Zero;
            evhandle = IntPtr.Zero;
            if ((bufwidth != width) || (bufheight != height))
            {
                if (bufnr != -1)
                {
                    PCO_SDK_LibWrapper.PCO_FreeBuffer(f_CameraHandle, bufnr);
                }
                bufnr     = -1;
                imagedata = new byte[(width + ipadd) * height * 3];

                err = PCO_SDK_LibWrapper.PCO_AllocateBuffer(f_CameraHandle, ref bufnr, size, ref buf, ref evhandle);
                if (err == 0)
                {
                    bufwidth  = width;
                    bufheight = height;
                }
            }
            else
            {
                err = PCO_SDK_LibWrapper.PCO_GetBuffer(f_CameraHandle, bufnr, ref buf, ref evhandle);
            }

            if ((convertDialog == IntPtr.Zero) && (f_ConvertHandle != IntPtr.Zero))
            {
                var hdl = new WindowInteropHelper(this).Handle;
                PCO_Convert_LibWrapper.PCO_OpenConvertDialog(ref convertDialog, hdl, "Convert Dialog", WM_APPp100, f_ConvertHandle, 500, 100);
            }

            //Mandatory for Cameralink and GigE. Don't care for all other interfaces, so leave it intact here.

            err = PCO_SDK_LibWrapper.PCO_AddBufferEx(f_CameraHandle, 0, 0, bufnr, (UInt16)width, (UInt16)height, (UInt16)pcoDescr.wDynResDESC);

            bool bImageIsOk = false;
            uint res        = WaitForSingleObject(evhandle, 3000);

            if (res == 0)
            {
                bImageIsOk = true;
            }
            if (!bImageIsOk)
            {
                return;
            }
            // End Event Block

            unsafe
            {
                short *bufi = (short *)buf.ToPointer();
                max = 0;
                min = 65535;
                for (int i = 20 * width; i < height * width; i++)
                {
                    bufi[i] >>= ishift;
                    if (bufi[i] > max)
                    {
                        max = bufi[i];
                    }
                    if (bufi[i] < min)
                    {
                        min = bufi[i];
                    }
                }
                if (max <= min)
                {
                    max = min + 1;
                }
            }
            PCO_Convert_LibWrapper.PCO_Convert16TOCOL(f_ConvertHandle, 0, iconvertcol, width, height,
                                                      buf, imagedata);

            if ((convertDialog != IntPtr.Zero) && (f_ConvertHandle != IntPtr.Zero))
            {
                PCO_Convert_LibWrapper.PCO_SetDataToDialog(convertDialog, width, height, buf, imagedata);
            }

            if (bauto)
            {
                PCO_ConvertStructures.PCO_Display strDisplay = new PCO_ConvertStructures.PCO_Display(1)
                {
                    wSize = (ushort)Marshal.SizeOf(typeof(PCO_ConvertStructures.PCO_Display))
                };

                err = PCO_Convert_LibWrapper.PCO_ConvertGetDisplay(f_ConvertHandle, ref strDisplay);
                strDisplay.iScale_min = min;
                strDisplay.iScale_max = max;

                err = PCO_Convert_LibWrapper.PCO_ConvertSetDisplay(f_ConvertHandle, ref strDisplay);
                err = PCO_Convert_LibWrapper.PCO_SetConvertDialog(convertDialog, f_ConvertHandle);
            }
            Dispatcher.Invoke(() => Debug.WriteLine(CbPixelFormatConv.SelectedValue));
            imagebmp = new Bitmap(width, height, PixelFormat.Format24bppRgb);                                                 //Format24bppRgb
            Rectangle  dimension         = new Rectangle(0, 0, imagebmp.Width, imagebmp.Height);
            BitmapData picData           = imagebmp.LockBits(dimension, ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb); //Format24bppRgb
            IntPtr     pixelStartAddress = picData.Scan0;

            //Copy the pixel data into the bitmap structure
            Marshal.Copy(imagedata, 0, pixelStartAddress, imagedata.Length);

            imagebmp.UnlockBits(picData);
            bool isOnSave = false;

            Dispatcher.Invoke(() => isOnSave = cbSaveCameraImage.IsChecked.Value);
            if (isOnSave)
            {
                string propPath = "";
                string prefix   = "00";
                Dispatcher.Invoke(() =>
                {
                    propPath = tbSaveCamPath.Text;
                    prefix   = tbSaveCamPrefix.Text;
                });
                if (propPath.Length <= 0)
                {
                    propPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
                }
                var dt    = DateTime.Now;
                var fName = $"{propPath}\\{prefix}-{dt.Month}-{dt.Day}-{dt.Hour}-{dt.Minute}-{dt.Second}_{dt.Millisecond}.jpg";
                if (!Properties.Settings.Default.CameraMaxFrameOn)
                {
                    imagebmp.Save(fName, ImageFormat.Jpeg);
                }
                else if (countSaved <= MaxCameraFrame)
                {
                    imagebmp.Save(fName, ImageFormat.Jpeg);
                    Dispatcher.Invoke(() => tbCurrentFrame.Text = countSaved.ToString());
                    countSaved++;
                }
            }

            Dispatcher.Invoke(() =>
            {
                BitmapImage bmpImage = BitmapToImageSource(imagebmp);
                PictureBox1.Source   = null;
                PictureBox1.Source   = bmpImage;
                LogBox.Items.Insert(0, new LogBoxItem {
                    Dt = DateTime.Now, LogText = "Получено изображение с камеры"
                });
            });
        }