Esempio n. 1
0
        private void ActionWork(ManagedImage managedImage)
        {
            m_oldManagedIMage       = new ManagedImage(m_processedManagedImage);
            m_processedManagedImage = new ManagedImage();

            managedImage.Convert(FlyCapture2Managed.PixelFormat.PixelFormatBgr, m_processedManagedImage);

            uint gain = managedImage.imageMetadata.embeddedGain, shutter = managedImage.imageMetadata.embeddedShutter;
            bool isNeedCorrect = (m_oldGain != gain) && (m_oldShutter != shutter);

            if (isNeedCorrect)
            {
                CalcIMage();
            }
            else
            {
                ManagedImage temp = new ManagedImage();
                m_processedManagedImage.ConvertToWriteAbleBitmap(temp);
                temp.writeableBitmap.Freeze();
                m_newResultImage = temp.writeableBitmap;
                OnNewResultImageIsReady();
            }

            m_oldGain = gain; m_oldShutter = shutter;

            if (this.IsNeedSaveAllImages)
            {
                Task.Run(() => SaveImage());
            }
        }
Esempio n. 2
0
        private unsafe void InitializeNewResultImage(ManagedImage mImg)
        {
            //byte* managedImageDataPtr = mImg.data; IntPtr dataPtr = new IntPtr(managedImageDataPtr);
            m_pixelsFormat = mImg.pixelFormat;
            ManagedImage manImg = new ManagedImage();

            if (m_pixelsFormat == PixelFormat.PixelFormatMono12 || m_pixelsFormat == PixelFormat.PixelFormatMono16 || m_pixelsFormat == PixelFormat.PixelFormatMono8 || m_pixelsFormat == PixelFormat.PixelFormatSignedMono16)
            {
                mImg.Convert(PixelFormat.PixelFormatMono8, manImg);
            }
            else
            {
                mImg.Convert(PixelFormat.PixelFormatBgr, manImg);
            }


            int   height = (int)manImg.rows, width = (int)manImg.cols, stride = (int)manImg.stride, dataSize = height * stride, bpp = (int)manImg.bitsPerPixel / 8;
            byte *imageData = manImg.data;
            //byte[] imgData = new byte[dataSize];

            //Marshal.Copy(dataPtr, imgData, 0, dataSize);
            Point     cursorPosition = this.CurrentCursorPosition;
            int       xRec = (int)(cursorPosition.X / this.VideoStreamAreaActualWidth * width), yRec = (int)(cursorPosition.Y / this.VideoStreamAreaActualHeight * height);
            Int32Rect rec = GetValidRectangle(xRec, yRec, width, height);

            m_currentRec = rec;

            byte[] currBytes = new byte[rec.Height * rec.Width * bpp];

            ManagedImage managImgForWrbmp = new ManagedImage();

            manImg.ConvertToWriteAbleBitmap(managImgForWrbmp);
            WriteableBitmap bmpTemp = managImgForWrbmp.writeableBitmap;

            bmpTemp.CopyPixels(rec, currBytes, rec.Width * bpp, 0);
            m_currentBytes = currBytes;
            OnSetNeededCameraProperty();
            OnCurrentBytesUpdated();

            int xBegin = rec.X, xEnd = rec.X + rec.Width, yBegin = rec.Y, yEnd = rec.Y + rec.Height;

            for (int xPix = xBegin; xPix <= xEnd; xPix++)
            {
                for (int yPix = yBegin; yPix <= yEnd; yPix++)
                {
                    if (yPix == yBegin || yPix == yEnd || xPix == xBegin || xPix == xEnd)
                    {
                        int pixelPosition = yPix * stride + xPix * bpp;

                        if (manImg.pixelFormat == PixelFormat.PixelFormatBgr)
                        {
                            imageData[pixelPosition]     = 0;
                            imageData[pixelPosition + 1] = 0;
                            imageData[pixelPosition + 2] = 0;
                        }
                        else
                        {
                            imageData[pixelPosition] = 0;
                        }
                    }
                }
            }

            ManagedImage temp = new ManagedImage();

            manImg.ConvertToBitmapSource(temp);
            temp.bitmapsource.Freeze();
            this.NewResultImage = temp.bitmapsource;
            OnNewResultImageIsReady();
        }