• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# Imaging.UnmanagedImage类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中AForge.Imaging.UnmanagedImage的典型用法代码示例。如果您正苦于以下问题:C# UnmanagedImage类的具体用法?C# UnmanagedImage怎么用?C# UnmanagedImage使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



UnmanagedImage类属于AForge.Imaging命名空间,在下文中一共展示了UnmanagedImage类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: ProcessFilter

        /// <summary>
        ///     Process the filter on the specified image.
        /// </summary>
        /// <param name="sourceData">Source image data.</param>
        /// <param name="destinationData">Destination image data.</param>
        protected override unsafe void ProcessFilter(UnmanagedImage sourceData, UnmanagedImage destinationData)
        {
            var pixelSize = Image.GetPixelFormatSize(sourceData.PixelFormat) / 8;

            // get width and height
            var width = sourceData.Width;
            var height = sourceData.Height;

            var srcOffset = sourceData.Stride - width * pixelSize;
            var dstOffset = destinationData.Stride - width;

            // do the job
            var src = (byte*)sourceData.ImageData.ToPointer();
            var dst = (byte*)destinationData.ImageData.ToPointer();

            // for each row
            for (var y = 0; y < height; y++)
            {
                // for each pixel
                for (var x = 0; x < width; x++, src += pixelSize, dst++)
                {
                    var r = (float)src[RGB.R] / 255;
                    var g = (float)src[RGB.G] / 255;
                    var b = (float)src[RGB.B] / 255;

                    var yindex = (float)(0.2989 * r + 0.5866 * g + 0.1145 * b);

                    *dst = (byte)(yindex * 255);
                }

                src += srcOffset;
                dst += dstOffset;
            }
        }
开发者ID:ProjectTako,项目名称:HearthstoneTracker,代码行数:39,代码来源:YCbCrExtractYChannel.cs


示例2: ProcessFilter

        /// <summary>
        ///   Process the filter on the specified image.
        /// </summary>
        /// 
        /// <param name="image">Source image data.</param>
        /// 
        protected unsafe override void ProcessFilter(UnmanagedImage image)
        {
            int width = image.Width;
            int height = image.Height;

            int pixelSize = System.Drawing.Image.GetPixelFormatSize(image.PixelFormat) / 8;
            int stride = image.Stride;
            int offset = stride - image.Width * pixelSize;

            byte* src = (byte*)image.ImageData.ToPointer();

            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++, src += pixelSize)
                {
                    double sum = src[RGB.R] + src[RGB.G] + src[RGB.B];
                    sum = sum == 0 ? 1 : sum;

                    double red = src[RGB.R] / sum;
                    double green = src[RGB.G] / sum;
                    double blue = 1 - red - green;

                    src[RGB.R] = (byte)(red * 255);
                    src[RGB.G] = (byte)(green * 255);
                    src[RGB.B] = (byte)(blue * 255);
                }
                src += offset;
            }
        }
开发者ID:CanerPatir,项目名称:framework,代码行数:35,代码来源:RGChromacity.cs


示例3: ProcessFilter

 protected override void ProcessFilter(UnmanagedImage image)
 {
     foreach (Rectangle rectangle in rectangles)
     {
         Drawing.Rectangle(image, rectangle, markerColor);
     }
 }
开发者ID:insertyourcoin,项目名称:bsuir-misoi,代码行数:7,代码来源:RectanglesMarker.cs


示例4: TemplateColorTracking

        /// <summary>
        /// Get rectangle contain object in current frame
        /// </summary>
        /// <param name="templateInfo">Tracking template information</param>
        /// <param name="source">Frame</param>
        /// <returns>Rectangle contain object</returns>
        public static Rectangle TemplateColorTracking(ImageStatistics templateInfo, ref UnmanagedImage source)
        {
            UnmanagedImage image = source.Clone();
            // create filter
            EuclideanColorFiltering filter = new EuclideanColorFiltering();
            // set center colol and radius
            filter.CenterColor = new RGB(
                (byte)templateInfo.Red.Mean,
                (byte)templateInfo.Green.Mean,
                (byte)templateInfo.Blue.Mean);
            filter.Radius = 30;
            // apply the filter
            filter.ApplyInPlace(image);

            image = Grayscale.CommonAlgorithms.BT709.Apply(image);

            OtsuThreshold threshold = new OtsuThreshold();
            threshold.ApplyInPlace(image);

            BlobCounter blobCounter = new BlobCounter();
            blobCounter.ObjectsOrder = ObjectsOrder.Size;
            blobCounter.ProcessImage(image);

            Rectangle rect = blobCounter.ObjectsCount > 0 ? blobCounter.GetObjectsRectangles()[0] : Rectangle.Empty;
            return rect;
        }
开发者ID:pinkuyt,项目名称:a-pod-project-team-3,代码行数:32,代码来源:ObjectDetector.cs


示例5: FindMaxPixel

        /// <summary>
        /// Looks for the brightest pixel after applying a redness filter. Narrows search first using a resampled copy of the image to eliminate edge dots. 
        /// Expects an image that is already cropped to the interested area for faster processing.
        /// </summary>
        /// <param name="img"></param>
        /// <param name="mouse"></param>
        /// <param name="maxDistanceFromMouse"></param>
        /// <returns></returns>
        public unsafe Point FindMaxPixel(UnmanagedImage img, PointF mouse, float maxDistanceFromMouse)
        {
            int width = 15;
            int height = (int)Math.Ceiling((double)img.Height / (double)img.Width * width);

            if (width <= img.Width && height <= img.Height + 1) {
                width = img.Width;
                height = img.Height;
            }

            double scale = (double)img.Width / (double)width;

            UnmanagedImage lowRed = null;
            try {
                if (width != img.Width && height != img.Height) {
                    using (Bitmap reduced = new Bitmap(width, height, PixelFormat.Format24bppRgb))
                    using (Graphics g = Graphics.FromImage(reduced))
                    using (ImageAttributes ia = new ImageAttributes()) {
                        g.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceCopy;
                        g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
                        g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
                        g.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
                        g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                        ia.SetWrapMode(System.Drawing.Drawing2D.WrapMode.TileFlipXY);
                        g.DrawImage(img.ToManagedImage(false), new Rectangle(0, 0, width, height), 0, 0, img.Width, img.Height, GraphicsUnit.Pixel, ia);
                        //TODO: Not sure if ToManagedImage will stick around after the underying image is disposed. I know that the bitmap data will be gone, guess that's most of it.
                        using (UnmanagedImage rui = UnmanagedImage.FromManagedImage(reduced)) {
                            lowRed = new RedEyeFilter(2).Apply(rui); // Make an copy using the red eye filter
                        }
                    }
                } else {
                    //Don't resample unless needed
                    lowRed = new RedEyeFilter(2).Apply(img);
                }

                Point max = GetMax(lowRed, new PointF(mouse.X / (float)scale, mouse.Y / (float)scale), maxDistanceFromMouse / scale);

                //We weren't scaling things? OK, cool...
                if (scale == 0) return max;

                //Otherwise, let's get the unscaled pixel.
                //Calculate the rectangle surrounding the selected pixel, but in source coordinates.
                int tinySize = (int)Math.Ceiling(scale) + 1;
                Rectangle tinyArea = new Rectangle((int)Math.Floor(scale * (double)max.X), (int)Math.Floor(scale * (double)max.Y), tinySize, tinySize);
                if (tinyArea.Right >= img.Width) tinyArea.Width -= img.Width - tinyArea.Right + 1;
                if (tinyArea.Bottom >= img.Height) tinyArea.Height -= img.Height - tinyArea.Bottom + 1;
                //Filter it and look
                using (UnmanagedImage tiny = new Crop(tinyArea).Apply(img)) {
                    using (UnmanagedImage tinyRed = new RedEyeFilter(2).Apply(tiny)) {
                        max = GetMax(tinyRed);
                        max.X += tinyArea.X;
                        max.Y += tinyArea.Y;
                    }
                }
                return max;
            } finally {
                if (lowRed != null) lowRed.Dispose();
            }
        }
开发者ID:stukalin,项目名称:ImageResizer,代码行数:67,代码来源:ManualSearcher.cs


示例6: dessinePoint

 public void dessinePoint(IntPoint point, UnmanagedImage img,int nbPixel,Color col)
 {
     for (int i = point.X - nbPixel / 2; i < point.X + nbPixel / 2 + 1; i++)
     {
         for (int j = point.Y - nbPixel / 2; j < point.Y + nbPixel / 2 + 1; j++)
         {
             img.SetPixel(i, j, col);
         }
     }
 }
开发者ID:KiLMaN,项目名称:LPIE_Robot_Color,代码行数:10,代码来源:ImgWebCam.cs


示例7: ColeurVersNB

        public void ColeurVersNB()
        {
            /* Deprecated trop longue */
            /* Convertie l'image en noir et blanc */

            UnmanagedImage image = UnmanagedImage.Create(UnImgReel.Width, UnImgReel.Height,
                    PixelFormat.Format8bppIndexed);
            Grayscale.CommonAlgorithms.BT709.Apply(UnImgReel, image);

            imgNB = image;
        }
开发者ID:KiLMaN,项目名称:LPIE_Robot_Color,代码行数:11,代码来源:ImgWebCam.cs


示例8: ConvertToGrayscale

 public static void ConvertToGrayscale(UnmanagedImage source, UnmanagedImage destination)
 {
     if (source.PixelFormat != PixelFormat.Format8bppIndexed)
     {
         Grayscale.CommonAlgorithms.BT709.Apply(source, destination);
     }
     else
     {
         source.Copy(destination);
     }
 }
开发者ID:tdhieu,项目名称:iSpy,代码行数:11,代码来源:Tools.cs


示例9: GdiDrawImage

        public static void GdiDrawImage(this Graphics graphics, UnmanagedImage image, Rectangle r)
        {

            IntPtr hdc = graphics.GetHdc();
            IntPtr memdc = GdiInterop.CreateCompatibleDC(hdc);
            IntPtr bmp = image.ImageData;
            GdiInterop.SelectObject(memdc, bmp);
            GdiInterop.SetStretchBltMode(hdc, 0x04);
            GdiInterop.StretchBlt(hdc, r.Left, r.Top, r.Width, r.Height, memdc, 0, 0, image.Width, image.Height, GdiInterop.TernaryRasterOperations.SRCCOPY);
            GdiInterop.DeleteObject(bmp);
            GdiInterop.DeleteDC(memdc);
            graphics.ReleaseHdc(hdc);
        }
开发者ID:tdhieu,项目名称:iSpy,代码行数:13,代码来源:GraphicsHelper.cs


示例10: ProcessFilter

        protected unsafe override void ProcessFilter(UnmanagedImage image, Rectangle rect)
        {
            int pixelSize = (image.PixelFormat == PixelFormat.Format8bppIndexed) ? 1 :
                (image.PixelFormat == PixelFormat.Format24bppRgb) ? 3 : 4;

            if (pixelSize != 4) throw new InvalidImagePropertiesException();

            int startX = rect.Left;
            int startY = rect.Top;
            int stopX = startX + rect.Width;
            int stopY = startY + rect.Height;
            int stride = image.Stride;
            int offset = stride - rect.Width * pixelSize;

            int numberOfPixels = (stopX - startX) * (stopY - startY);

            // color image
            byte* ptr = (byte*)image.ImageData.ToPointer();
            // allign pointer to the first pixel to process
            ptr += (startY * stride + startX * pixelSize);

            double width = Width;
            double inner = InnerAlpha;
            double outer = OuterAlpha;
            double diff =  OuterAlpha - InnerAlpha;
            const short a = RGB.A;
            int w = (int)Math.Round(width);

            for (int y = startY; y < stopY; y++) {
                int ydist = Math.Max(0, Math.Max(startY + w - y, y - (stopY - 1 - w)));

                for (int x = startX; x < stopX; x++, ptr += pixelSize) {
                    int xdist = Math.Max(0, Math.Max(startX + w - x, x - (stopX - 1 - w)));
                    double dist = xdist > 0 && ydist > 0 ? Math.Round(Math.Sqrt(xdist * xdist + ydist * ydist)): Math.Max(xdist,ydist);

                    if (dist <= 0 || w == 0) {
                        ptr[a] = (byte)Math.Round((double)ptr[a] * inner);
                    } else if (dist > w){
                        ptr[a] = (byte)Math.Round((double)ptr[a] * outer);
                    } else {
                        double t = dist / width;
                        //t = Math.Sin(Math.PI * t / 2);
                        t = 3 * t * t - 2 * t * t * t;
                        //t = 6 * Math.Pow(t, 5) - 15 * Math.Pow(t, 4) + 10 * Math.Pow(t, 3);
                        ptr[a] = (byte)Math.Round((double)ptr[a] * (inner + diff * t));
                    }
                }
                ptr += offset;
            }
        }
开发者ID:eakova,项目名称:resizer,代码行数:50,代码来源:FeatherEdge.cs


示例11: ProcessFilter

        /// <summary>
        ///   Process the filter on the specified image.
        /// </summary>
        /// 
        /// <param name="sourceData">Source image data.</param>
        /// <param name="destinationData">Destination image data.</param>
        /// 
        protected unsafe override void ProcessFilter(UnmanagedImage sourceData, UnmanagedImage destinationData)
        {
            int width = sourceData.Width;
            int height = sourceData.Height;
            PixelFormat format = sourceData.PixelFormat;
            int pixelSize = System.Drawing.Bitmap.GetPixelFormatSize(format) / 8;

            sourceData.Clone();

            UnmanagedImage temp = UnmanagedImage.Create(width, height, format);

            int lineWidth = width * pixelSize;

            int srcStride = temp.Stride;
            int srcOffset = srcStride - lineWidth;
            int dstStride = destinationData.Stride;
            int dstOffset = dstStride - lineWidth;

            byte* srcStart = (byte*)temp.ImageData.ToPointer();
            byte* dstStart = (byte*)destinationData.ImageData.ToPointer();


            // first
            Convolution c = new Convolution(masks[0]);
            c.Apply(sourceData, destinationData);

            // others
            for (int i = 1; i < masks.Length; i++)
            {
                c.Kernel = masks[i];
                c.Apply(sourceData, temp);

                byte* src = srcStart;
                byte* dst = dstStart;

                for (int y = 0; y < height; y++)
                {
                    for (int x = 0; x < lineWidth; x++, src++, dst++)
                    {
                        if (*src > *dst)
                            *dst = *src;
                    }

                    dst += dstOffset;
                    src += srcOffset;
                }
            }
        }
开发者ID:natepan,项目名称:framework,代码行数:55,代码来源:CompassConvolution.cs


示例12: ProcessFilter

        /// <summary>
        /// Process the filter on the specified image.
        /// </summary>
        /// <param name="sourceData">Source image data.</param>
        /// <param name="destinationData">Destination image data.</param>
        protected unsafe override void ProcessFilter(UnmanagedImage sourceData, UnmanagedImage destinationData)
        {
            // get width and height
            int width = sourceData.Width;
            int height = sourceData.Height;

            int pixelSize =   System.Drawing.Image.GetPixelFormatSize(sourceData.PixelFormat) / 8;
            int sum;

            var algorithm = Algorithm;

            if (pixelSize <= 4) {
                int srcOffset = sourceData.Stride - width * pixelSize;
                int dstOffset = destinationData.Stride - width;

                // do the job
                byte* src = (byte*)sourceData.ImageData.ToPointer();
                byte* dst = (byte*)destinationData.ImageData.ToPointer();

                for (int y = 0; y < height; y++) {
                    for (int x = 0; x < width; x++, src += pixelSize, dst++) {
                        if (src[RGB.R] == 0) continue;
                        if (algorithm == 0) {
                            //held
                            *dst = (byte)Math.Max(src[RGB.R] - Math.Min(src[RGB.G], src[RGB.B]), 0);
                        } else if (algorithm == 1) {
                            //normalized r channel
                            sum = (src[RGB.R] + src[RGB.G] + src[RGB.B]);
                            *dst = (sum != 0) ? (byte)(255 * src[RGB.R] / sum) : (byte)0;
                        } else if (algorithm == 2) {
                            //Smolka
                            *dst = src[RGB.R] == 0 ? (byte)0 : (byte)Math.Min(255, Math.Max(0, ((float)(src[RGB.R] - Math.Max(src[RGB.G], src[RGB.B])) * 255.0F / (float)src[RGB.R])));
                        } else if (algorithm == 3) {
                            //GS
                            *dst = (byte)Math.Pow((Math.Max(0, (src[RGB.R] * 2 - src[RGB.G] - src[RGB.B]) / src[RGB.R])), 2);

                        } else if (algorithm == 4) {
                            //Gabautz
                            *dst = (byte)Math.Min(255, (src[RGB.R] * src[RGB.R] / (src[RGB.G] * src[RGB.G] + src[RGB.B] * src[RGB.B] + 14)));
                        }
                    }
                    src += srcOffset;
                    dst += dstOffset;
                }
            } else throw new NotImplementedException();
        }
开发者ID:stukalin,项目名称:ImageResizer,代码行数:51,代码来源:RedEyeFilter.cs


示例13: ProcessFilter

        /// <summary>
        ///   Process the filter on the specified image.
        /// </summary>
        /// 
        /// <param name="image">Source image data.</param>
        /// 
        protected unsafe override void ProcessFilter(UnmanagedImage image)
        {
            int width = image.Width;
            int height = image.Height;

            int pixelSize = System.Drawing.Image.GetPixelFormatSize(image.PixelFormat) / 8;
            int stride = image.Stride;
            int offset = stride - image.Width * pixelSize;

            byte* src = (byte*)image.ImageData.ToPointer();

            // Get maximum color image values
            int maxR = 0, maxG = 0, maxB = 0;
            for (int i = 0; i < height; i++)
            {
                for (int j = 0; j < width; j++)
                {
                    if (src[RGB.R] > maxR) maxR = src[RGB.R];
                    if (src[RGB.G] > maxG) maxG = src[RGB.G];
                    if (src[RGB.B] > maxB) maxB = src[RGB.B];
                }
            }

            double kr = maxR > 0 ? (255.0 / maxR) : 0;
            double kg = maxG > 0 ? (255.0 / maxG) : 0;
            double kb = maxB > 0 ? (255.0 / maxB) : 0;


            src = (byte*)image.ImageData.ToPointer();
            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++, src += pixelSize)
                {
                    double r = kr * src[RGB.R];
                    double g = kg * src[RGB.G];
                    double b = kb * src[RGB.B];

                    src[RGB.R] = (byte)(r > 255 ? 255 : r);
                    src[RGB.G] = (byte)(g > 255 ? 255 : g);
                    src[RGB.B] = (byte)(b > 255 ? 255 : b);
                }

                src += offset;
            }
        }
开发者ID:qusma,项目名称:framework,代码行数:51,代码来源:WhitePatch.cs


示例14: EvaluateLocallyWAbs

        public static double EvaluateLocallyWAbs(UnmanagedImage image)
        {
            byte[,] pixels = image.GetPixels();

            int width = pixels.GetLength(0);
            int height = pixels.GetLength(1);

            double aggregate = 0;

            for (int i = 0; i < width - 1; i++)
            {
                for (int j = 0; j < height; j++)
                {
                    aggregate += Math.Abs((pixels[i, j] - pixels[i + 1, j]));
                }
            }

            for (int i = 0; i < width; i++)
            {
                for (int j = 0; j < height - 1; j++)
                {
                    aggregate += Math.Abs((pixels[i, j] - pixels[i, j + 1]));
                }
            }

            for (int i = 0; i < width - 1; i++)
            {
                for (int j = 0; j < height - 1; j++)
                {
                    aggregate += Math.Abs((pixels[i, j] - pixels[i + 1, j + 1]));
                }
            }

            for (int i = 0; i < width - 1; i++)
            {
                for (int j = 1; j < height; j++)
                {
                    aggregate += Math.Abs((pixels[i, j] - pixels[i + 1, j - 1]));
                }
            }

            return (1D / (width * height * Math.Pow(255, 2))) * aggregate;
        }
开发者ID:nikodemrafalski,项目名称:Fuzz,代码行数:43,代码来源:ContrastMeasures.cs


示例15: Correct

        public void Correct(UnmanagedImage img, double aFocalLinPixels, int limit, double scale, int offx, int offy)
        {
            if (Math.Abs(_aFocalLinPixels - aFocalLinPixels) > Double.Epsilon || limit != _mFeLimit ||
                Math.Abs(scale - _mScaleFeSize) > Double.Epsilon || img.Width != _w || img.Height != _h ||
                _offsetx != offx || _offsety != offy)
            {
                Init(aFocalLinPixels, limit, scale, img.Width, img.Height, offx, offy);
            }
            var correctImage = UnmanagedImage.Create(img.Width, img.Height, img.PixelFormat);
            img.Copy(correctImage);
            int c = 0;
            for (int x = 0; x < _w; x++)
            {
                for (int y = 0; y < _h; y++)
                {
                    img.SetPixel(x, y, correctImage.GetPixel(_map[c, 0], _map[c, 1]));
                    c++;
                }

            }
            correctImage.Dispose();
        }
开发者ID:tdhieu,项目名称:iSpy,代码行数:22,代码来源:FishEyeCorrect.cs


示例16: ImageStatisticsHSL

        /// <summary>
        /// Initializes a new instance of the <see cref="ImageStatisticsHSL"/> class.
        /// </summary>
        /// 
        /// <param name="image">Image to gather statistics about.</param>
        /// <param name="mask">Mask array which specifies areas to collect statistics for.</param>
        /// 
        /// <remarks><para>The mask array must be of the same size as the specified source image, where 0 values
        /// correspond to areas which should be excluded from processing. So statistics is calculated only for pixels,
        /// which have none zero corresponding value in the mask.
        /// </para></remarks>
        /// 
        /// <exception cref="UnsupportedImageFormatException">Source pixel format is not supported.</exception>
        /// <exception cref="ArgumentException">Mask must have the same size as the source image to get statistics for.</exception>
        /// 
        public ImageStatisticsHSL( UnmanagedImage image, byte[,] mask )
        {
            CheckSourceFormat( image.PixelFormat );
            CheckMaskProperties( PixelFormat.Format8bppIndexed,
                new Size( mask.GetLength( 1 ), mask.GetLength( 0 ) ), new Size( image.Width, image.Height ) );

            unsafe
            {
                fixed ( byte* maskPtr = mask )
                {
                    ProcessImage( image, maskPtr, mask.GetLength( 1 ) );
                }
            }
        }
开发者ID:RevDevBev,项目名称:aforge.net,代码行数:29,代码来源:ImageStatisticsHSL.cs


示例17: ProcessFrame

        /// <summary>
        /// Process new video frame.
        /// </summary>
        /// 
        /// <param name="videoFrame">Video frame to process (detect motion in).</param>
        /// 
        /// <remarks><para>Processes new frame from video source and detects motion in it.</para>
        /// 
        /// <para>Check <see cref="MotionLevel"/> property to get information about amount of motion
        /// (changes) in the processed frame.</para>
        /// </remarks>
        /// 
        public unsafe void ProcessFrame( UnmanagedImage videoFrame )
        {
            lock ( sync )
            {
                // check previous frame
                if ( previousFrame == null )
                {
                    // save image dimension
                    width = videoFrame.Width;
                    height = videoFrame.Height;

                    // alocate memory for previous and current frames
                    previousFrame = UnmanagedImage.Create( width, height, PixelFormat.Format8bppIndexed );
                    motionFrame = UnmanagedImage.Create( width, height, PixelFormat.Format8bppIndexed );

                    frameSize = motionFrame.Stride * height;

                    // temporary buffer
                    if ( suppressNoise )
                    {
                        tempFrame = UnmanagedImage.Create( width, height, PixelFormat.Format8bppIndexed );
                    }

                    // convert source frame to grayscale
                    Tools.ConvertToGrayscale( videoFrame, previousFrame );

                    return;
                }

                // check image dimension
                if ( ( videoFrame.Width != width ) || ( videoFrame.Height != height ) )
                    return;

                // convert current image to grayscale
                Tools.ConvertToGrayscale( videoFrame, motionFrame );

                // pointers to previous and current frames
                byte* prevFrame = (byte*) previousFrame.ImageData.ToPointer( );
                byte* currFrame = (byte*) motionFrame.ImageData.ToPointer( );
                // difference value
                int diff;

                // 1 - get difference between frames
                // 2 - threshold the difference
                // 3 - copy current frame to previous frame
                for ( int i = 0; i < frameSize; i++, prevFrame++, currFrame++ )
                {
                    // difference
                    diff = (int) *currFrame - (int) *prevFrame;
                    // copy current frame to previous
                    *prevFrame = *currFrame;
                    // treshold
                    *currFrame = ( ( diff >= differenceThreshold ) || ( diff <= differenceThresholdNeg ) ) ? (byte) 255 : (byte) 0;
                }

                if ( suppressNoise )
                {
                    // suppress noise and calculate motion amount
                    AForge.SystemTools.CopyUnmanagedMemory( tempFrame.ImageData, motionFrame.ImageData, frameSize );
                    erosionFilter.Apply( tempFrame, motionFrame );
                }

                // calculate amount of motion pixels
                pixelsChanged = 0;
                byte* motion = (byte*) motionFrame.ImageData.ToPointer( );

                for ( int i = 0; i < frameSize; i++, motion++ )
                {
                    pixelsChanged += ( *motion & 1 );
                }
            }
        }
开发者ID:centrolutions,项目名称:AForge.NET,代码行数:84,代码来源:TwoFramesDifferenceDetector.cs


示例18: ProcessFilter

 /// <summary>
 ///   Process the filter on the specified image.
 /// </summary>
 /// 
 /// <param name="sourceData">Source image data.</param>
 /// <param name="destinationData">Destination image data.</param>
 /// 
 protected override void ProcessFilter(UnmanagedImage sourceData, UnmanagedImage destinationData)
 {
     convolution.Apply(sourceData, destinationData);
 }
开发者ID:qusma,项目名称:framework,代码行数:11,代码来源:RobinsonEdgeDetector.cs


示例19: VideoNewFrame

        private void VideoNewFrame(object sender, NewFrameEventArgs e)
        {
            var nf = NewFrame;
            var f = e.Frame;
            if (_requestedToStop || nf==null || f==null)
                return;

            if (_lastframeEvent > DateTime.MinValue)
            {
                if ((Helper.Now<_nextFrameTarget))
                {
                    return;
                }
                CalculateFramerates();
            }

            _lastframeEvent = Helper.Now;

            Bitmap bmOrig = null;
            bool bMotion = false;
            lock (_sync)
            {
                try
                {
                    bmOrig = ResizeBmOrig(f);

                    if (RotateFlipType != RotateFlipType.RotateNoneFlipNone)
                    {
                        bmOrig.RotateFlip(RotateFlipType);
                    }

                    _width = bmOrig.Width;
                    _height = bmOrig.Height;

                    if (ZPoint == Point.Empty)
                    {
                        ZPoint = new Point(bmOrig.Width / 2, bmOrig.Height / 2);
                    }

                    if (CW.NeedMotionZones)
                        CW.NeedMotionZones = !SetMotionZones(CW.Camobject.detector.motionzones);

                    if (Mask != null)
                    {
                        ApplyMask(bmOrig);
                    }

                    if (CW.Camobject.alerts.active && Plugin != null && Alarm!=null)
                    {
                        bmOrig = RunPlugin(bmOrig);
                    }

                    var bmd = bmOrig.LockBits(new Rectangle(0, 0, bmOrig.Width, bmOrig.Height), ImageLockMode.ReadWrite, bmOrig.PixelFormat);

                    //this converts the image into a windows displayable image so do it regardless
                    using (var lfu = new UnmanagedImage(bmd))
                    {
                        if (_motionDetector != null)
                        {
                            bMotion = ApplyMotionDetector(lfu);
                        }
                        else
                        {
                            MotionDetected = false;
                        }

                        if (CW.Camobject.settings.FishEyeCorrect)
                        {
                            _feCorrect.Correct(lfu, CW.Camobject.settings.FishEyeFocalLengthPX,
                                CW.Camobject.settings.FishEyeLimit, CW.Camobject.settings.FishEyeScale, ZPoint.X,
                                ZPoint.Y);
                        }

                        if (ZFactor > 1)
                        {
                            var f1 = new ResizeNearestNeighbor(lfu.Width, lfu.Height);
                            var f2 = new Crop(ViewRectangle);
                            try
                            {
                                using (var imgTemp = f2.Apply(lfu))
                                {
                                    f1.Apply(imgTemp, lfu);
                                }
                            }
                            catch (Exception ex)
                            {
                                ErrorHandler?.Invoke(ex.Message);
                            }
                        }

                    }
                    bmOrig.UnlockBits(bmd);
                    PiP(bmOrig);
                    AddTimestamp(bmOrig);
                }
                catch (UnsupportedImageFormatException ex)
                {
                    CW.VideoSourceErrorState = true;
                    CW.VideoSourceErrorMessage = ex.Message;

//.........这里部分代码省略.........
开发者ID:Jaejoon,项目名称:iSpy,代码行数:101,代码来源:Camera.cs


示例20: ApplyMotionDetector

        private bool ApplyMotionDetector(UnmanagedImage lfu)
        {
            if (Alarm != null && lfu!=null)
            {
                _processFrameCount++;
                if (_processFrameCount >= CW.Camobject.detector.processeveryframe || CW.Calibrating)
                {
                    _processFrameCount = 0;

                    try
                    {
                        MotionLevel = _motionDetector.ProcessFrame(Filter != null ? Filter.Apply(lfu) : lfu);
                    }
                    catch(Exception ex)
                    {
                        throw new Exception("Error processing motion: "+ex.Message);
                    }

                    MotionLevel = MotionLevel * CW.Camobject.detector.gain;

                    if (MotionLevel >= _alarmLevel)
                    {
                        if (Math.Min(MotionLevel,0.99) <= _alarmLevelMax)
                        {
                            return true;
                        }
                    }
                    else
                        MotionDetected = false;
                }
            }
            else
                MotionDetected = false;
            return false;
        }
开发者ID:Jaejoon,项目名称:iSpy,代码行数:35,代码来源:Camera.cs



注:本文中的AForge.Imaging.UnmanagedImage类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Math.Matrix3x3类代码示例发布时间:2022-05-24
下一篇:
C# Imaging.BlobCounter类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap