bool LoadImageProcessor()
 {
     //LOAD IMAGE PROCESSOR
     try
     {
         IsProcessing = true;
         imgProcessor = ImageProcessor.Instance;
         Helpers.Log.LogThisInfo("ImageProcessor version:    {0} \n", imgProcessor.GetVersion());
         if (imgProcessor.NodeList.GetNodePresent("DemosaicingMethod") == true)
         {
             imgProcessor.NodeList["DemosaicingMethod"].Value = "NearestNeighbor";                     // NearestNeighbor, Bilinear3x3, Baumer5x5
             Helpers.Log.LogThisInfo("    Demosaicing method:    {0} \n", (string)imgProcessor.NodeList["DemosaicingMethod"].Value);
         }
         Helpers.Log.LogThisInfo("\n");
         IsProcessing = false;
         return(true);
     }
     catch (BGAPI2.Exceptions.IException ex)
     {
         Helpers.Log.LogThisInfo("ExceptionType:    {0} \n", ex.GetType());
         Helpers.Log.LogThisInfo("ErrorDescription: {0} \n", ex.GetErrorDescription());
         Helpers.Log.LogThisInfo("in function:      {0} \n", ex.GetFunctionName());
         IsProcessing = false;
         return(false);
     }
 }
예제 #2
0
 public BaumerCamera()
 {
     imgProcessor = new BGAPI2.ImageProcessor();
     if (CameraSystem != null)
     {
         CameraSystem.SearchAllCamera();
     }
 }
예제 #3
0
        /// <summary>
        /// Takes a raw buffer and copy it into an existing RGB24 Bitmap.
        /// </summary>
        public unsafe bool FillRGB24(BGAPI2.Buffer buffer, Bitmap outputImage)
        {
            if (buffer == null || buffer.IsIncomplete || buffer.MemPtr == IntPtr.Zero)
            {
                return(false);
            }

            if (buffer.Width != (ulong)outputImage.Width || buffer.Height != (ulong)outputImage.Height)
            {
                return(false);
            }

            bool filled = false;

            // If the input image is a bayer pattern it will be debayered by default by the image processor.
            // If it's Mono it will be converted to RGB by the image processor.
            // The input image cannot be JPEG because we temporarily switch off that option before acquisition.
            BGAPI2.ImageProcessor imgProcessor     = new BGAPI2.ImageProcessor();
            BGAPI2.Image          img              = imgProcessor.CreateImage((uint)buffer.Width, (uint)buffer.Height, buffer.PixelFormat, buffer.MemPtr, buffer.SizeFilled);
            BGAPI2.Image          transformedImage = imgProcessor.CreateTransformedImage(img, "BGR8");
            img.Release();
            img = transformedImage;

            // Push the transformed image into the passed output bitmap.
            Rectangle  rect    = new Rectangle(0, 0, outputImage.Width, outputImage.Height);
            BitmapData bmpData = null;

            try
            {
                bmpData = outputImage.LockBits(rect, ImageLockMode.WriteOnly, outputImage.PixelFormat);
                IntPtr[] ptrBmp = new IntPtr[] { bmpData.Scan0 };
                NativeMethods.memcpy(bmpData.Scan0.ToPointer(), img.Buffer.ToPointer(), rect.Width * rect.Height * 3);
                filled = true;
            }
            catch (Exception e)
            {
                log.ErrorFormat("Error while copying bitmap. {0}", e.Message);
            }
            finally
            {
                if (bmpData != null)
                {
                    outputImage.UnlockBits(bmpData);
                }
            }

            img.Release();

            return(filled);
        }