Пример #1
0
        private void SetFramegrabberValue(String nodeName, Int64 int64Val)
        {
            if (null == myCamera)
            {
                return;
            }

            IntPtr hDevice = IntPtr.Zero;

            Jai_FactoryWrapper.EFactoryError error = Jai_FactoryWrapper.J_Camera_GetLocalDeviceHandle(myCamera.CameraHandle, ref hDevice);
            if (Jai_FactoryWrapper.EFactoryError.Success != error)
            {
                return;
            }

            if (IntPtr.Zero == hDevice)
            {
                return;
            }

            IntPtr hNode;

            error = Jai_FactoryWrapper.J_Camera_GetNodeByName(hDevice, nodeName, out hNode);
            if (Jai_FactoryWrapper.EFactoryError.Success != error)
            {
                return;
            }

            if (IntPtr.Zero == hNode)
            {
                return;
            }

            error = Jai_FactoryWrapper.J_Node_SetValueInt64(hNode, false, int64Val);
            if (Jai_FactoryWrapper.EFactoryError.Success != error)
            {
                return;
            }

            //Special handling for Active Silicon CXP boards, which also has nodes prefixed
            //with "Incoming":
            if ("Width" == nodeName || "Height" == nodeName)
            {
                string strIncoming = "Incoming" + nodeName;
                IntPtr hNodeIncoming;
                error = Jai_FactoryWrapper.J_Camera_GetNodeByName(hDevice, strIncoming, out hNodeIncoming);
                if (Jai_FactoryWrapper.EFactoryError.Success != error)
                {
                    return;
                }

                if (IntPtr.Zero == hNodeIncoming)
                {
                    return;
                }

                error = Jai_FactoryWrapper.J_Node_SetValueInt64(hNodeIncoming, false, int64Val);
            }
        }
Пример #2
0
        /*
         *      private void saveButton_Click(object sender, EventArgs e)
         *      {
         *          // Have we got any images to save to disk?
         *          if (myCamera != null && !myCamera.IsAsyncImageRecordingRunning && (myCamera.TotalAsyncImagesRecordedCount > 0))
         *          {
         *              // Prompt the user if he wants to continue or not with the image save
         *              if (MessageBox.Show(this, "Image save might take long time!\nAre you sure you want to continue?", "Image Save", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.OK)
         *              {
         *                  // Disable the Image Recording buttons as long as we are saving the images
         *                  asynchImageRecordingGroupBox.Enabled = false;
         *
         *                  // Get the recorded images as a list
         *                  List<Jai_FactoryWrapper.ImageInfo> imageList = myCamera.GetAsyncRecordedImages();
         *
         *                  // Any images recorded?
         *                  if (imageList != null && (imageList.Count > 0))
         *                  {
         *                      // Run through the list of recorded images
         *                      for (int index = 0; index < myCamera.TotalAsyncImagesRecordedCount; index++)
         *                      {
         *                          Jai_FactoryWrapper.EFactoryError error = Jai_FactoryWrapper.EFactoryError.Success;
         *
         *                          // Get the recorded image at this index
         *                          Jai_FactoryWrapper.ImageInfo ii = imageList[index];
         *
         *                          // Are we saving the images in "raw" format or in Tiff?
         *                          if (saveRawCheckBox.Checked)
         *                          {
         *                              // Save the image to disk
         *                              error = Jai_FactoryWrapper.J_Image_SaveFileRaw(ref ii, "D:\\CStest\\RecordedImage" + index.ToString("000") + ".raw");
         *                          }
         *                          else
         *                          {
         *                              // Create local image that will contain the converted image
         *                              Jai_FactoryWrapper.ImageInfo localImageInfo = new Jai_FactoryWrapper.ImageInfo();
         *
         *                              // Allocate buffer that will contain the converted image
         *                              // In this sample we re-allocate the buffer over-and-over because we assume that the recorded images could be
         *                              // of different size (If we have been using the Sequence functionality in the cameras)
         *                              error = Jai_FactoryWrapper.J_Image_Malloc(ref ii, ref localImageInfo);
         *
         *                              // Convert the raw image to image format
         *                              error = Jai_FactoryWrapper.J_Image_FromRawToImage(ref ii, ref localImageInfo, 4096, 4096, 4096);
         *
         *                              // Save the image to disk
         *                              error = Jai_FactoryWrapper.J_Image_SaveFile(ref localImageInfo, "D:\\CStest\\RecordedImage" + index.ToString("000") + ".tif");
         *
         *                              //Free the conversion buffer
         *                              error = Jai_FactoryWrapper.J_Image_Free(ref localImageInfo);
         *                          }
         *                          Application.DoEvents();
         *                      }
         *
         *                      MessageBox.Show(this, "The recorded images has been saved!", "Image save", MessageBoxButtons.OK, MessageBoxIcon.Information);
         *                  }
         *
         *                  // Re-enable the Image Recording buttons
         *                  asynchImageRecordingGroupBox.Enabled = true;
         *              }
         *          }
         *      }
         */
        private void saveButton_Click(object sender, EventArgs e)
        {
            // Have we got any images to save to disk?

            if (myCamera != null && !myCamera.IsAsyncImageRecordingRunning && (myCamera.TotalAsyncImagesRecordedCount > 0))
            {
                // Prompt the user if he wants to continue or not with the image save
                // if (MessageBox.Show(this, "Image save might take long time!\nAre you sure you want to continue?", "Image Save", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.OK)
                // {
                // Disable the Image Recording buttons as long as we are saving the images
                asynchImageRecordingGroupBox.Enabled = false;

                // Get the recorded images as a list
                List <Jai_FactoryWrapper.ImageInfo> imageList = myCamera.GetAsyncRecordedImages();

                // Any images recorded?

                if (imageList != null && (imageList.Count > 0))
                {
                    // Run through the list of recorded images
                    int index = myCamera.TotalAsyncImagesRecordedCount - 1;
                    Jai_FactoryWrapper.EFactoryError error = Jai_FactoryWrapper.EFactoryError.Success;

                    // Get the recorded image at this index
                    Jai_FactoryWrapper.ImageInfo ii = imageList[index];

                    // Are we saving the images in "raw" format or in Tiff?

                    // Create local image that will contain the converted image
                    Jai_FactoryWrapper.ImageInfo localImageInfo = new Jai_FactoryWrapper.ImageInfo();

                    // Allocate buffer that will contain the converted image
                    // In this sample we re-allocate the buffer over-and-over because we assume that the recorded images could be
                    // of different size (If we have been using the Sequence functionality in the cameras)
                    error = Jai_FactoryWrapper.J_Image_Malloc(ref ii, ref localImageInfo);

                    // Convert the raw image to image format
                    error = Jai_FactoryWrapper.J_Image_FromRawToImage(ref ii, ref localImageInfo, 4096, 4096, 4096);

                    // Save the image to disks
                    error = Jai_FactoryWrapper.J_Image_SaveFile(ref localImageInfo, "C:\\Users\\aida\\Desktop\\wechat_jump\\" + "phone.png");

                    //Free the conversion buffer
                    error = Jai_FactoryWrapper.J_Image_Free(ref localImageInfo);

                    Application.DoEvents();

                    // MessageBox.Show(this, "The recorded images has been saved!", "Image save", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }

                // Re-enable the Image Recording buttons
                asynchImageRecordingGroupBox.Enabled = true;
                //}
            }
            //Thread.Sleep(2000);
            startCaptureButton_Click(sender, e);
            return;
        }
Пример #3
0
        unsafe void HandleImage1(ref Jai_FactoryWrapper.ImageInfo ImageInfo)//回调函数,ImageInfo为图像结构体,ImageBuffer为图像数据指针
        {
            bool bCheck = CheckBox_SAVE.Checked;

            if (ImageInfo.PixelFormat == Jai_FactoryWrapper.EPixelFormatType.GVSP_PIX_MONO8)//黑白相机
            {
                long counterStart = 0;
                KSJWin.QueryPerformanceCounter(ref counterStart);
                long counterEnd = 0;
                KSJWin.QueryPerformanceCounter(ref counterEnd);
                long nFreq = 0;
                KSJWin.QueryPerformanceFrequency(ref nFreq);
                float fInterval = (float)(counterEnd - counterStart);
                float fElapse   = fInterval / (float)nFreq * 1000;  // MS
                TextBox_ELAPSE_TIME.Text = string.Format("Elapse: {0}ms", fElapse);
                if (bCheck)
                {
                    Jai_FactoryWrapper.J_Image_SaveFileEx(ref ImageInfo, "image.bmp", Jai_FactoryWrapper.ESaveFileFormat.Bmp, 75);        //保存函数
                }
            }
            else
            {
                Jai_FactoryWrapper.J_Image_Malloc(ref ImageInfo, ref m_ConvertedImageInfo);
                Jai_FactoryWrapper.J_Image_FromRawToImage(ref ImageInfo, ref m_ConvertedImageInfo, 4096, 4096, 4096);
                if (bCheck)
                {
                    long counterStart = 0;
                    KSJWin.QueryPerformanceCounter(ref counterStart);
                    long counterEnd = 0;
                    KSJWin.QueryPerformanceCounter(ref counterEnd);

                    long nFreq = 0;
                    KSJWin.QueryPerformanceFrequency(ref nFreq);
                    float fInterval = (float)(counterEnd - counterStart);
                    float fElapse   = fInterval / (float)nFreq * 1000;  // MS
                    TextBox_ELAPSE_TIME.Text = string.Format("Elapse: {0}ms", fElapse);
                    Jai_FactoryWrapper.J_Image_SaveFileEx(ref ImageInfo, "image.bmp", Jai_FactoryWrapper.ESaveFileFormat.Bmp, 75);
                    bCheck = false;
                    CheckBox_SAVE.Checked = false;
                }
                Jai_FactoryWrapper.J_Image_Free(ref m_ConvertedImageInfo);
            }

            return;
        }
Пример #4
0
        private void GaintextBox_TextChanged(object sender, EventArgs e)
        {
            if (myGainNode != null)
            {
                double value = Convert.ToSingle(GaintextBox.Text);
                myGainNode.Value = value;
                if (null == myCamera)
                {
                    return;
                }

                IntPtr hDevice = IntPtr.Zero;
                Jai_FactoryWrapper.EFactoryError error = Jai_FactoryWrapper.J_Camera_GetLocalDeviceHandle(myCamera.CameraHandle, ref hDevice);
                if (Jai_FactoryWrapper.EFactoryError.Success != error)
                {
                    return;
                }

                if (IntPtr.Zero == hDevice)
                {
                    return;
                }

                IntPtr hNode;
                error = Jai_FactoryWrapper.J_Camera_GetNodeByName(hDevice, "Gain", out hNode);
                if (Jai_FactoryWrapper.EFactoryError.Success != error)
                {
                    return;
                }

                if (IntPtr.Zero == hNode)
                {
                    return;
                }

                Jai_FactoryWrapper.J_Node_SetValueDouble(hNode, false, value);
            }
        }
Пример #5
0
        private void SetFramegrabberPixelFormat()
        {
            String nodeName = "PixelFormat";

            if (null == myCamera)
            {
                return;
            }

            IntPtr hDevice = IntPtr.Zero;

            Jai_FactoryWrapper.EFactoryError error = Jai_FactoryWrapper.J_Camera_GetLocalDeviceHandle(myCamera.CameraHandle, ref hDevice);
            if (Jai_FactoryWrapper.EFactoryError.Success != error)
            {
                return;
            }

            if (IntPtr.Zero == hDevice)
            {
                return;
            }

            long pf = 0;

            error = Jai_FactoryWrapper.J_Camera_GetValueInt64(myCamera.CameraHandle, nodeName, ref pf);
            if (Jai_FactoryWrapper.EFactoryError.Success != error)
            {
                return;
            }
            UInt64 pixelFormat = (UInt64)pf;

            UInt64 jaiPixelFormat = 0;

            error = Jai_FactoryWrapper.J_Image_Get_PixelFormat(myCamera.CameraHandle, pixelFormat, ref jaiPixelFormat);
            if (Jai_FactoryWrapper.EFactoryError.Success != error)
            {
                return;
            }

            StringBuilder sbJaiPixelFormatName = new StringBuilder(512);
            uint          iSize = (uint)sbJaiPixelFormatName.Capacity;

            error = Jai_FactoryWrapper.J_Image_Get_PixelFormatName(myCamera.CameraHandle, jaiPixelFormat, sbJaiPixelFormatName, iSize);
            if (Jai_FactoryWrapper.EFactoryError.Success != error)
            {
                return;
            }

            IntPtr hNode;

            error = Jai_FactoryWrapper.J_Camera_GetNodeByName(hDevice, nodeName, out hNode);
            if (Jai_FactoryWrapper.EFactoryError.Success != error)
            {
                return;
            }

            if (IntPtr.Zero == hNode)
            {
                return;
            }

            error = Jai_FactoryWrapper.J_Node_SetValueString(hNode, false, sbJaiPixelFormatName.ToString());
            if (Jai_FactoryWrapper.EFactoryError.Success != error)
            {
                return;
            }

            //Special handling for Active Silicon CXP boards, which also has nodes prefixed
            //with "Incoming":
            string strIncoming = "Incoming" + nodeName;
            IntPtr hNodeIncoming;

            error = Jai_FactoryWrapper.J_Camera_GetNodeByName(hDevice, strIncoming, out hNodeIncoming);
            if (Jai_FactoryWrapper.EFactoryError.Success != error)
            {
                return;
            }

            if (IntPtr.Zero == hNodeIncoming)
            {
                return;
            }

            error = Jai_FactoryWrapper.J_Node_SetValueString(hNodeIncoming, false, sbJaiPixelFormatName.ToString());
        }
Пример #6
0
        private void replayButton_Click(object sender, EventArgs e)
        {
            // Here we have access to the stored images! Lets show them in an image window!!
            //Create a replay window
            if (myCamera != null && !myCamera.IsAsyncImageRecordingRunning && (myCamera.TotalAsyncImagesRecordedCount > 0))
            {
                IntPtr WindowHandle = IntPtr.Zero;

                // Try to read get the maximum width and height by looking for "SensorWidth" and "SensorHeight"
                Int32 Width      = 0;
                Int32 Height     = 0;
                CNode WidthNode  = myCamera.GetNode("Width");
                CNode HeightNode = myCamera.GetNode("Height");

                Width  = Convert.ToInt32(WidthNode.Max);
                Height = Convert.ToInt32(HeightNode.Max);

                IntPtr nodeHandle;

                uint BytesPerPixel = 4;
                if (Jai_FactoryWrapper.J_Camera_GetNodeByName(myCamera.CameraHandle, "PixelFormat", out nodeHandle) == Jai_FactoryWrapper.EFactoryError.Success)
                {
                    Int64 value = 0;
                    if (Jai_FactoryWrapper.J_Node_GetValueInt64(nodeHandle, false, ref value) == Jai_FactoryWrapper.EFactoryError.Success)
                    {
                        Jai_FactoryWrapper.EPixelFormatType pixeltype = (Jai_FactoryWrapper.EPixelFormatType)value;
                        BytesPerPixel = Jai_FactoryWrapper.GetPixelTypeMemorySize(pixeltype);
                    }
                }

                Jai_FactoryWrapper.SIZE maxSize = new Jai_FactoryWrapper.SIZE(Width, Height);

                Jai_FactoryWrapper.EFactoryError error = Jai_FactoryWrapper.EFactoryError.Success;

                // Calculate the size of the window rect to display the images
                int RectWidth  = 0;
                int RectHeight = 0;

                Jai_FactoryWrapper.RECT frameRect = new Jai_FactoryWrapper.RECT(0, 0, 100, 100);;

                // Does the image fit in width?
                if ((Width + 2 * System.Windows.Forms.SystemInformation.Border3DSize.Width) > System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Width)
                {
                    RectWidth = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Width - 2 * System.Windows.Forms.SystemInformation.Border3DSize.Width;
                }
                else
                {
                    RectWidth = Width;
                }

                // Does the image fit in Height?
                if ((Height + System.Windows.Forms.SystemInformation.Border3DSize.Height + System.Windows.Forms.SystemInformation.CaptionHeight) > System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Height)
                {
                    RectHeight = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Height - System.Windows.Forms.SystemInformation.Border3DSize.Height - System.Windows.Forms.SystemInformation.CaptionHeight;
                }
                else
                {
                    RectHeight = Height;
                }

                frameRect = new Jai_FactoryWrapper.RECT(0, 0, RectWidth, RectHeight);

                // Open the replay view
                error = Jai_FactoryWrapper.J_Image_OpenViewWindowEx(Jai_FactoryWrapper.EIVWWindowType.OverlappedStretch, "Replay", ref frameRect, ref maxSize, IntPtr.Zero, out WindowHandle);

                if (WindowHandle != IntPtr.Zero)
                {
                    List <Jai_FactoryWrapper.ImageInfo> imageList = myCamera.GetAsyncRecordedImages();
                    if (imageList != null && (imageList.Count > 0))
                    {
                        for (int index = 0; index < myCamera.TotalAsyncImagesRecordedCount; index++)
                        {
                            Jai_FactoryWrapper.ImageInfo ii = imageList[index];
                            Jai_FactoryWrapper.J_Image_SetViewWindowTitle(WindowHandle, "Replay (" + index.ToString() + "/" + myCamera.TotalAsyncImagesRecordedCount.ToString() + ")");
                            Jai_FactoryWrapper.J_Image_ShowImage(WindowHandle, ref ii, 4096, 4096, 4096);
                            Application.DoEvents();
                            //Thread.Sleep(10);
                            Delay(10);
                        }
                    }

                    Jai_FactoryWrapper.J_Image_CloseViewWindow(WindowHandle);
                }
            }
        }
Пример #7
0
        private void startCaptureButton_Click(object sender, EventArgs e)
        {
            while (myCamera != null)
            {
                if (myCamera.IsAsyncImageRecordingRunning || (myCamera.TotalAsyncImagesRecordedCount > 0))
                {
                    // DialogResult res = MessageBox.Show(this, "The Asychynchronuous Image Recording is already active or the internal buffer is not empty! Do you want to restart the image recording and discard recorded images?", "Asynchronous Image Capture", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);

                    //                    if (res == DialogResult.Yes)
                    //                  {

                    myCamera.StopAsyncImageRecording();
                    myCamera.FreeAsyncRecordedImages();
                    myCamera.StartAsyncImageRecording(Convert.ToInt32(captureCountNumericUpDown.Value), (CCamera.AsyncImageRecordingMode)recordingModeComboBox.SelectedIndex, Convert.ToInt32(skipCountNumericUpDown.Value));
                    //Application.DoEvents();
                    //                 }
                }
                else
                {
                    myCamera.StartAsyncImageRecording(Convert.ToInt32(captureCountNumericUpDown.Value), (CCamera.AsyncImageRecordingMode)recordingModeComboBox.SelectedIndex, Convert.ToInt32(skipCountNumericUpDown.Value));
                }
                //Thread.Sleep(500);

                /*DateTime d = DateTime.Now;
                 * while (((TimeSpan)DateTime.Now - d).TotalMilliseconds < 1000)
                 * {
                 *  Application.DoEvents();
                 * }*/
                Delay(200);

                Application.DoEvents();
                if (!myCamera.IsAsyncImageRecordingRunning && (myCamera.TotalAsyncImagesRecordedCount > 0))
                {
                    // Prompt the user if he wants to continue or not with the image save
                    // if (MessageBox.Show(this, "Image save might take long time!\nAre you sure you want to continue?", "Image Save", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.OK)
                    // {
                    // Disable the Image Recording buttons as long as we are saving the images
                    //asynchImageRecordingGroupBox.Enabled = false;

                    // Get the recorded images as a list
                    List <Jai_FactoryWrapper.ImageInfo> imageList = myCamera.GetAsyncRecordedImages();

                    // Any images recorded?

                    if (imageList != null && (imageList.Count > 0))
                    {
                        // Run through the list of recorded images
                        int index = myCamera.TotalAsyncImagesRecordedCount - 1;
                        Jai_FactoryWrapper.EFactoryError error = Jai_FactoryWrapper.EFactoryError.Success;

                        // Get the recorded image at this index
                        Jai_FactoryWrapper.ImageInfo ii = imageList[index];

                        // Are we saving the images in "raw" format or in Tiff?

                        // Create local image that will contain the converted image
                        Jai_FactoryWrapper.ImageInfo localImageInfo = new Jai_FactoryWrapper.ImageInfo();

                        // Allocate buffer that will contain the converted image
                        // In this sample we re-allocate the buffer over-and-over because we assume that the recorded images could be
                        // of different size (If we have been using the Sequence functionality in the cameras)
                        error = Jai_FactoryWrapper.J_Image_Malloc(ref ii, ref localImageInfo);

                        // Convert the raw image to image format
                        error = Jai_FactoryWrapper.J_Image_FromRawToImage(ref ii, ref localImageInfo, 4096, 4096, 4096);

                        // Save the image to disks
                        error = Jai_FactoryWrapper.J_Image_SaveFile(ref localImageInfo, "..\\" + "phone.png");

                        //error = Jai_FactoryWrapper.J_Image_SaveFile(ref localImageInfo, "C:\\Users\\aida\\Desktop\\wechat_jump\\" + "phone.png");

                        //Free the conversion buffer
                        error = Jai_FactoryWrapper.J_Image_Free(ref localImageInfo);

                        //myCamera.StopAsyncImageRecording();
                        //myCamera.FreeAsyncRecordedImages();
                        Application.DoEvents();

                        // MessageBox.Show(this, "The recorded images has been saved!", "Image save", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    myCamera.StopAsyncImageRecording();
                    myCamera.StopImageAcquisition();
                    myCamera.StartImageAcquisition(true, 5);


                    // Re-enable the Image Recording buttons
                    //asynchImageRecordingGroupBox.Enabled = true;
                    //}
                }


                //Thread.Sleep(500);
            }
            //     Thread.Sleep(1000);

            // if(!File.Exists("D:\\Cstest\\RecordedImage" + "ppppp" + ".tif"))
            //  {

            //    }
        }
Пример #8
0
        unsafe void HandleImage1(ref Jai_FactoryWrapper.ImageInfo ImageInfo)
        {
            bool bCheck = CheckBox_SAVE.Checked;

            if (ImageInfo.PixelFormat == Jai_FactoryWrapper.EPixelFormatType.GVSP_PIX_MONO8)
            {
                long counterStart = 0;
                KSJWin.QueryPerformanceCounter(ref counterStart);
                HObject Hobj;
                HOperatorSet.GenImage1(out Hobj, "byte", ImageInfo.SizeX, ImageInfo.SizeY, ImageInfo.ImageBuffer);
                long counterEnd = 0;
                KSJWin.QueryPerformanceCounter(ref counterEnd);
                long nFreq = 0;
                KSJWin.QueryPerformanceFrequency(ref nFreq);
                float fInterval = (float)(counterEnd - counterStart);
                float fElapse   = fInterval / (float)nFreq * 1000;  // MS
                TextBox_ELAPSE_TIME.Text = string.Format("Elapse: {0}ms", fElapse);
                if (bCheck)
                {
                    HOperatorSet.WriteImage(Hobj, "bmp", 0, "JAIToHalcon.bmp");
                }
            }
            else
            {
                Jai_FactoryWrapper.J_Image_Malloc(ref ImageInfo, ref m_ConvertedImageInfo);
                Jai_FactoryWrapper.J_Image_FromRawToImage(ref ImageInfo, ref m_ConvertedImageInfo, 4096, 4096, 4096);
                if (bCheck)
                {
                    long counterStart = 0;
                    KSJWin.QueryPerformanceCounter(ref counterStart);
                    int size = (int)(ImageInfo.SizeX * ImageInfo.SizeY * 3);
                    Marshal.Copy((IntPtr)m_ConvertedImageInfo.ImageBuffer, imagedata, 0, size);
                    for (int i = 0; i < ImageInfo.SizeY; i++)
                    {
                        int nOffset     = (int)(i * ImageInfo.SizeX);
                        int nRealOffset = (int)(i * ImageInfo.SizeX * 3);
                        for (int j = 0; j < ImageInfo.SizeX; j++)
                        {
                            int nPixelOffset = j * 3;
                            arrayR[nOffset + j] = imagedata[nRealOffset + nPixelOffset + 2];
                            arrayG[nOffset + j] = imagedata[nRealOffset + nPixelOffset + 1];
                            arrayB[nOffset + j] = imagedata[nRealOffset + nPixelOffset];
                        }
                    }

                    HObject Hobj;
                    fixed(byte *pR = arrayR, pG = arrayG, pB = arrayB)
                    {
                        HOperatorSet.GenImage3(out Hobj, "byte", ImageInfo.SizeX, ImageInfo.SizeY, new IntPtr(pR), new IntPtr(pG), new IntPtr(pB));
                    }

                    long counterEnd = 0;
                    KSJWin.QueryPerformanceCounter(ref counterEnd);

                    long nFreq = 0;
                    KSJWin.QueryPerformanceFrequency(ref nFreq);
                    float fInterval = (float)(counterEnd - counterStart);
                    float fElapse   = fInterval / (float)nFreq * 1000;  // MS
                    TextBox_ELAPSE_TIME.Text = string.Format("Elapse: {0}ms", fElapse);
                    HOperatorSet.WriteImage(Hobj, "bmp", 0, "JAIToHalcon.bmp");
                    bCheck = false;
                    CheckBox_SAVE.Checked = false;
                }
                Jai_FactoryWrapper.J_Image_Free(ref m_ConvertedImageInfo);
            }

            return;
        }
Пример #9
0
        private void saveButton_Click(object sender, EventArgs e)
        {
            // Have we got any images to save to disk?
            if (myCamera != null && !myCamera.IsAsyncImageRecordingRunning && (myCamera.TotalAsyncImagesRecordedCount > 0))
            {
                // Prompt the user if he wants to continue or not with the image save
                if (MessageBox.Show(this, "Image save might take long time!\nAre you sure you want to continue?", "Image Save", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.OK)
                {
                    // Disable the Image Recording buttons as long as we are saving the images
                    asynchImageRecordingGroupBox.Enabled = false;

                    // Get the recorded images as a list
                    List <Jai_FactoryWrapper.ImageInfo> imageList = myCamera.GetAsyncRecordedImages();

                    // Any images recorded?
                    if (imageList != null && (imageList.Count > 0))
                    {
                        // Run through the list of recorded images
                        for (int index = 0; index < myCamera.TotalAsyncImagesRecordedCount; index++)
                        {
                            Jai_FactoryWrapper.EFactoryError error = Jai_FactoryWrapper.EFactoryError.Success;

                            // Get the recorded image at this index
                            Jai_FactoryWrapper.ImageInfo ii = imageList[index];

                            // Are we saving the images in "raw" format or in Tiff?
                            if (saveRawCheckBox.Checked)
                            {
                                // Save the image to disk
                                error = Jai_FactoryWrapper.J_Image_SaveFileRaw(ref ii, ".\\RecordedImage" + index.ToString("000") + ".raw");
                            }
                            else
                            {
                                // Create local image that will contain the converted image
                                Jai_FactoryWrapper.ImageInfo localImageInfo = new Jai_FactoryWrapper.ImageInfo();

                                // Allocate buffer that will contain the converted image
                                // In this sample we re-allocate the buffer over-and-over because we assume that the recorded images could be
                                // of different size (If we have been using the Sequence functionality in the cameras)
                                error = Jai_FactoryWrapper.J_Image_Malloc(ref ii, ref localImageInfo);

                                // Convert the raw image to image format
                                error = Jai_FactoryWrapper.J_Image_FromRawToImage(ref ii, ref localImageInfo, 4096, 4096, 4096);

                                // Save the image to disk
                                error = Jai_FactoryWrapper.J_Image_SaveFile(ref localImageInfo, ".\\RecordedImage" + index.ToString("000") + ".tif");

                                //Free the conversion buffer
                                error = Jai_FactoryWrapper.J_Image_Free(ref localImageInfo);
                            }
                            Application.DoEvents();
                        }

                        MessageBox.Show(this, "The recorded images has been saved!", "Image save", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }

                    // Re-enable the Image Recording buttons
                    asynchImageRecordingGroupBox.Enabled = true;
                }
            }
        }