예제 #1
0
파일: Form1.cs 프로젝트: lexa105/FaceToWork
        private void Device_NewFrame(object sender, NewFrameEventArgs eventArgs)
        {
            var    oldimage = pictureBox1.Image;
            Bitmap video    = filter_cubic.Apply((Bitmap)eventArgs.Frame.Clone());

            videoframe = new Image <Bgr, byte>(video);
            GrayFrame  = new Image <Gray, byte>(video);

            Rectangle[] rectangles = oclface.DetectMultiScale(GrayFrame, 1.2, 10);
            if (rectangles.Length != 0)
            {
                Thread.Sleep(300);
            }

            foreach (Rectangle rectangle in rectangles)
            {
                using (Graphics graphics = Graphics.FromImage(video)) //ziska graphics z bitmap
                {
                    using (Pen pen = new Pen(Color.Red, 1))
                    {
                        graphics.DrawRectangle(pen, rectangle);
                    }
                }
            }

            pictureBox1.Image = video;

            if (oldimage != null) //kdyz nebude predchozi frame v pictureBox1 smaze se a uvolni se Memory
            {
                oldimage.Dispose();
            }
            GC.Collect();
        }
예제 #2
0
        public double[] Encode(Bitmap source)
        {
            Bitmap frame;

            if (source.PixelFormat != System.Drawing.Imaging.PixelFormat.Format8bppIndexed)
            {
                frame = Grayscale.CommonAlgorithms.RMY.Apply(source);
            }
            else
            {
                frame = source;
            }

            if (!frame.Size.Equals(frameSize))
            {
                frame = resizer.Apply(frame);
            }

            double[]         samples = new double[fftSize * frameSize.Width];
            alglib.complex[] slice   = new alglib.complex[fftSize];
            double           maxSlice;
            int sampleIndex = 0;

            int colsCount = frameSize.Width;
            int startRow  = startLine;
            int endRow    = startRow + frameSize.Height;

            for (int x = 0; x < colsCount; x++)
            {
                for (int y = startRow; y < endRow; y++)
                {
                    slice[y].x = (frame.GetPixel(x, frameSize.Height - (y - startRow) - 1).R / 255.0) * short.MaxValue;
                }

                for (int y = 0; y < fftSize; y++)
                {
                    slice[y].x *= randomizerMask[y];
                }

                alglib.fftc1dinv(ref slice);

                maxSlice = double.MinValue;
                for (int y = 0; y < slice.Length; y++)
                {
                    if (Math.Abs(slice[y].x) > maxSlice)
                    {
                        maxSlice = Math.Abs(slice[y].x);
                    }
                }

                for (int i = 0; i < slice.Length; i++)
                {
                    samples[sampleIndex] = (short)Math.Round(slice[i].x * short.MaxValue / maxSlice);
                    sampleIndex++;
                }
            }

            return(samples);
        }
예제 #3
0
        public static void ExtractRegionImages1(Bitmap frame1, Bitmap frame2)
        {
            frame1 = greyscaleFilter1.Apply(frame1);
            frame2 = greyscaleFilter1.Apply(frame2);
            lock (_lock1)
            {
                cropFilter1.Rectangle = Region1;
                ROI1 = circleFilter2.Apply(resizeFilter1.Apply(cropFilter1.Apply(frame1)));
                diffFilter1.OverlayImage = circleFilter2.Apply(resizeFilter1.Apply(cropFilter1.Apply(frame2)));
                ROI1Diff = diffFilter1.Apply(ROI1);
                subFilter1.OverlayImage = invertFilter1.Apply(threshFilter1.Apply(ROI1Diff));
                ROI1DropDiff            = subFilter1.Apply(ROI1Diff);

                cropFilter1.Rectangle = Region2;
                ROI2 = circleFilter2.Apply(resizeFilter1.Apply(cropFilter1.Apply(frame1)));
                diffFilter1.OverlayImage = circleFilter2.Apply(resizeFilter1.Apply(cropFilter1.Apply(frame2)));
                ROI2Diff = diffFilter1.Apply(ROI2);
                subFilter1.OverlayImage = invertFilter1.Apply(threshFilter1.Apply(ROI2Diff));
                ROI2DropDiff            = subFilter1.Apply(ROI2Diff);

                cropFilter1.Rectangle = Region5;
                ROI5 = circleFilter2.Apply(resizeFilter1.Apply(cropFilter1.Apply(frame1)));
                diffFilter1.OverlayImage = circleFilter2.Apply(resizeFilter1.Apply(cropFilter1.Apply(frame2)));
                ROI5Diff = diffFilter1.Apply(ROI5);
                subFilter1.OverlayImage = invertFilter1.Apply(threshFilter1.Apply(ROI5Diff));
                ROI5DropDiff            = subFilter1.Apply(ROI5Diff);

                cropFilter1.Rectangle = Region6;
                ROI6 = circleFilter2.Apply(resizeFilter1.Apply(cropFilter1.Apply(frame1)));
                diffFilter1.OverlayImage = circleFilter2.Apply(resizeFilter1.Apply(cropFilter1.Apply(frame2)));
                ROI6Diff = diffFilter1.Apply(ROI6);
                subFilter1.OverlayImage = invertFilter1.Apply(threshFilter1.Apply(ROI6Diff));
                ROI6DropDiff            = subFilter1.Apply(ROI6Diff);
            }
        }
예제 #4
0
        public static void ExtractRegionsDevice2(Bitmap frame1, Bitmap frame2)
        {
            frame1 = greyscaleFilter2.Apply(frame1);
            frame2 = greyscaleFilter2.Apply(frame2);
            lock (_lock2)
            {
                cropFilter2.Rectangle = Region3;
                ROI3 = circleFilter2.Apply(resizeFilter2.Apply(cropFilter2.Apply(frame1)));
                diffFilter2.OverlayImage = circleFilter2.Apply(resizeFilter2.Apply(cropFilter2.Apply(frame2)));
                ROI3Diff = diffFilter2.Apply(ROI3);
                subFilter2.OverlayImage = invertFilter2.Apply(threshFilter2.Apply(ROI3Diff));
                ROI3DropDiff            = subFilter2.Apply(ROI3Diff);

                cropFilter2.Rectangle = Region4;
                ROI4 = circleFilter2.Apply(resizeFilter2.Apply(cropFilter2.Apply(frame1)));
                diffFilter2.OverlayImage = circleFilter2.Apply(resizeFilter2.Apply(cropFilter2.Apply(frame2)));
                ROI4Diff = diffFilter2.Apply(ROI4);
                subFilter2.OverlayImage = invertFilter2.Apply(threshFilter2.Apply(ROI4Diff));
                ROI4DropDiff            = subFilter2.Apply(ROI4Diff);

                cropFilter2.Rectangle = Region7;
                ROI7 = circleFilter2.Apply(resizeFilter2.Apply(cropFilter2.Apply(frame1)));
                diffFilter2.OverlayImage = circleFilter2.Apply(resizeFilter2.Apply(cropFilter2.Apply(frame2)));
                ROI7Diff = diffFilter2.Apply(ROI7);
                subFilter2.OverlayImage = invertFilter2.Apply(threshFilter2.Apply(ROI7Diff));
                ROI7DropDiff            = subFilter2.Apply(ROI7Diff);

                cropFilter2.Rectangle = Region8;
                ROI8 = circleFilter2.Apply(resizeFilter2.Apply(cropFilter2.Apply(frame1)));
                diffFilter2.OverlayImage = circleFilter2.Apply(resizeFilter2.Apply(cropFilter2.Apply(frame2)));
                ROI8Diff = diffFilter2.Apply(ROI8);
                subFilter2.OverlayImage = invertFilter2.Apply(threshFilter2.Apply(ROI8Diff));
                ROI8DropDiff            = subFilter2.Apply(ROI8Diff);
            }
        }
예제 #5
0
        public string GetLetter(Bitmap bmp)
        {
            List <Bitmap> brailePictures = pictures.BitmapList;

            try
            {
                foreach (var i in brailePictures)
                {
                    Size           size   = GetSize(i.Size, bmp.Size);
                    ResizeBilinear filter = new ResizeBilinear(size.Width, size.Height);
                    bmp = filter.Apply(bmp);
                    TemplateMatch[] matches = exhaustiveTemplateMatching.ProcessImage(i, bmp);
                    float           sim     = matches[0].Similarity;

                    if (sim >= similar)
                    {
                        similar     = sim;
                        letterCount = count;
                    }

                    count++;
                    Debug.WriteLine("The count is" + count);
                }


                return(Letters[letterCount]);
            }
            catch (IndexOutOfRangeException)
            {
                Debug.WriteLine("The letter could not be Identified");
                return("Unknown");
            }
        }
예제 #6
0
        private void ApplyFilters(ref Bitmap bitmap)
        {
            if (IsLuminance.IsChecked != null && IsLuminance.IsChecked.Value)
            {
                bitmap = _grayscale.Apply(bitmap);
            }

            if (IsRemovedNoises.IsChecked != null && IsRemovedNoises.IsChecked.Value)
            {
                _noiseRemoval.ApplyInPlace(bitmap);
            }

            if (IsResized.IsChecked == null || !IsResized.IsChecked.Value)
            {
                return;
            }
            try
            {
                _resizer.NewWidth = int.Parse(NewWidthTextBox.Text);
            }
            catch
            {
                _resizer.NewWidth = DefaultResizeWidth;
            }
            _resizer.NewHeight = (int)(Convert.ToSingle(bitmap.Height) / bitmap.Width * _resizer.NewWidth);
            bitmap             = _resizer.Apply(bitmap);
        }
예제 #7
0
        /// <summary>
        /// Processes the specified SRC image.
        /// </summary>
        /// <param name="srcImage">The SRC image.</param>
        /// <remarks></remarks>
        public void Process(Bitmap srcImage)
        {
            resize.NewWidth  = srcImage.Width / Scale;
            resize.NewHeight = srcImage.Height / Scale;

            FilteredBoard = resize.Apply(srcImage);

            ImageFilters.HSLFilter(FilteredBoard, targetHue, targetSat, targetBri, hueTol, satTol, briTol);

            median.ApplyInPlace(FilteredBoard);

            GaussianBlur blr = new GaussianBlur(1, 2);

            blr.ApplyInPlace(FilteredBoard);

            List <IntPoint> cors = new List <IntPoint>();

            try
            {
                cors = quadFinder.ProcessImage(FilteredBoard);
            }
            catch { }

            if (ValidCorners(cors))
            {
                EnlargeCorners(cors);
                SortCorners(cors);
                UpdateCorners(cors);
            }
        }
예제 #8
0
        // =========================================================
        private void ZoomFunct(ref Bitmap frame, double Factor)
        {
            if (Factor < 0.1)
            {
                return;
            }

            int centerX  = frame.Width / 2;
            int centerY  = frame.Height / 2;
            int OrgSizeX = frame.Width;
            int OrgSizeY = frame.Height;

            int fromX = centerX - (int)(centerX / Factor);
            int fromY = centerY - (int)(centerY / Factor);
            int SizeX = (int)(OrgSizeX / Factor);
            int SizeY = (int)(OrgSizeY / Factor);

            try {
                Crop CrFilter = new Crop(new Rectangle(fromX, fromY, SizeX, SizeY));
                frame = CrFilter.Apply(frame);
                ResizeBilinear RBfilter = new ResizeBilinear(OrgSizeX, OrgSizeY);
                frame = RBfilter.Apply(frame);
            } catch {
            }
        }
예제 #9
0
        /// <summary>
        /// Predict a hand written digit from the pictureBox
        /// </summary>
        private void PredictDigit()
        {
            // получаем нарисованную мышью цифру
            Bitmap bitmap = new Bitmap(handWrittenPictureBox.Image);

            // приводим изображение к размеру 28x28
            ResizeBilinear resizer = new ResizeBilinear(ImageWidth, ImageHeight);
            Bitmap         img     = resizer.Apply(bitmap);

            // Раскладываем изображение в пиксели
            IEnumerable <byte> pixels = Enumerable.Range(0, ImageWidth)
                                        .SelectMany(y => Enumerable.Range(0, ImageHeight), (y, x) => img.GetPixel(x, y).B);

            // нормализуем пиксели
            double[] input = pixels
                             .Select(p => new { p, v = 1.0 * (BlackColourCode - p) / BlackColourCode })
                             .Select(t => t.v > 0.1 ? t.v : 0)
                             .ToArray();

            // запускаем вычисление нейросетью вектора с вероятностями
            double[] predictions = _network.Compute(input.ToArray());

            // показываем результат в элементах ProgressBar
            for (int i = 0; i < SymbolsCount; i++)
            {
                _bars[i].Value = (int)(100 * predictions[i]);
            }

            Refresh();
        }
예제 #10
0
        public Bitmap GetThumb(string path, int maxSize)
        {
            using (var original = Image.FromFile(path))
            {
                //if (original.Width <= maxSize && original.Height < maxSize)
                //    return original;

                // Figure out the ratio
                var ratioX = maxSize / (double)original.Width;
                var ratioY = maxSize / (double)original.Height;
                // use whichever multiplier is smaller
                var ratio = ratioX < ratioY ? ratioX : ratioY;

                // now we can get the new height and width
                var newHeight = Convert.ToInt32(original.Height * ratio);
                var newWidth  = Convert.ToInt32(original.Width * ratio);

                // create filter
                var filter = new ResizeBilinear(newWidth, newHeight);
                // apply the filter
                var newImage = filter.Apply(original);

                return(newImage);
            }
        }
예제 #11
0
        public static void vykresliNalezeneKrizkyDoObrazku(string slozka, int zmencovaciKonstanta, List <RozsirenyBod> souradniceKrizu, string jakUlozit)
        {
            string[]       slozkaObrazku = Directory.GetFiles(slozka, "*.png", SearchOption.TopDirectoryOnly);
            Bitmap         obrazek       = (Bitmap)Bitmap.FromFile(slozkaObrazku[0]);
            ResizeBilinear filterSize1   = new ResizeBilinear(obrazek.Width / zmencovaciKonstanta, obrazek.Height / zmencovaciKonstanta);

            obrazek = filterSize1.Apply(obrazek);
            BitmapData data = obrazek.LockBits(new Rectangle(0, 0, obrazek.Width, obrazek.Height), ImageLockMode.ReadWrite, obrazek.PixelFormat);

            foreach (var m in souradniceKrizu)
            {
                //vykresleni bodu - stredu nalezeneho krizku
                Drawing.Rectangle(data, new Rectangle(m.X, m.Y, 2, 2), Color.Red);
            }
            obrazek.UnlockBits(data);
            obrazek.Save(jakUlozit);



            souradniceKrizu = souradniceKrizu.OrderBy(p => p.X).ToList();

            /* Vypisu vsechny souradnice
             *
             * Console.WriteLine(souradniceKrizu.Count);
             * foreach (var item in souradniceKrizu)
             * {
             *  Console.WriteLine("X: " + item.X + " Y: " + item.Y);
             * }
             * Console.WriteLine("Xxxxxx: " + souradniceKrizu.Count);
             */
        }
예제 #12
0
        /// <summary>
        /// 位图缩放
        /// </summary>
        /// <param name="bmp">源位图</param>
        /// <param name="newW">新宽度</param>
        /// <param name="newH">新高度</param>
        /// <returns>返回变换后的位图</returns>
        public static Bitmap ResizeImage(Bitmap bmp, int newW, int newH)
        {
            // create filter
            ResizeBilinear filter = new ResizeBilinear(newW, newH);

            // apply the filter
            return(filter.Apply(bmp));

            #region 旧代码
            //try
            //{
            //    Bitmap b = new Bitmap(newW, newH, pf);
            //    Graphics g = Graphics.FromImage(b);

            //    // 插值算法的质量
            //    g.InterpolationMode = InterpolationMode.HighQualityBilinear;

            //    g.DrawImage(bmp, new Rectangle(0, 0, newW, newH), new Rectangle(0, 0, bmp.Width, bmp.Height), GraphicsUnit.Pixel);
            //    g.Dispose();

            //    return b;
            //}
            //catch(Exception ex)
            //{
            //    throw new Exception(ex.Message);
            //}
            #endregion
        }
예제 #13
0
        public void resize_bilinear()
        {
            double[,] diag = Matrix.Magic(5);
            diag           = diag.Divide(diag.Max());

            Bitmap input = diag.ToBitmap();

            // Create a new resize bilinear filter
            var filter = new ResizeBilinear(7, 8);

            // Apply the filter
            Bitmap output = filter.Apply(input);

            Assert.AreEqual(7, output.Width);
            Assert.AreEqual(8, output.Height);

            double[,] actual;
            new ImageToMatrix().Convert(output, out actual);

            string str = actual.ToString(CSharpMatrixFormatProvider.InvariantCulture);

            double[,] expected =
            {
                {  0.67843137254902, 0.874509803921569,  0.56078431372549, 0.0784313725490196, 0.274509803921569,  0.47843137254902,               0.6 },
                { 0.827450980392157, 0.580392156862745, 0.356862745098039,  0.227450980392157, 0.423529411764706, 0.556862745098039, 0.623529411764706 },
                { 0.725490196078431, 0.356862745098039, 0.262745098039216,  0.376470588235294, 0.576470588235294, 0.662745098039216, 0.698039215686274 },
                { 0.250980392156863,  0.23921568627451, 0.341176470588235,  0.525490196078431, 0.725490196078431, 0.811764705882353, 0.847058823529412 },
                {  0.27843137254902, 0.333333333333333, 0.474509803921569,  0.662745098039216, 0.792156862745098, 0.635294117647059, 0.498039215686275 },
                { 0.403921568627451,  0.47843137254902, 0.627450980392157,  0.780392156862745, 0.749019607843137,               0.4, 0.145098039215686 },
                { 0.427450980392157, 0.592156862745098, 0.776470588235294,  0.843137254901961,  0.36078431372549, 0.282352941176471, 0.294117647058824 },
                {  0.43921568627451, 0.635294117647059, 0.835294117647059,  0.866666666666667, 0.207843137254902, 0.235294117647059, 0.356862745098039 }
            };

            Assert.IsTrue(expected.IsEqual(actual, 1e-6));
        }
예제 #14
0
        private void BtnChooseFileClick(object sender, EventArgs e)
        {
            var ofd = new OpenFileDialog
            {
                InitialDirectory = Program.AppPath + @"backgrounds\",
                Filter           = "Image Files|*.jpg;*.gif;*.bmp;*.png;*.jpeg",
                FilterIndex      = 1
            };

            if (ofd.ShowDialog(this) == DialogResult.OK)
            {
                string fileName = ofd.FileName;
                Fpc.Fpobject.image = fileName;
                Image img = Image.FromFile(fileName);
                try
                {
                    Fpc.ImgPlan = (Image)img.Clone(); //
                    var rf = new ResizeBilinear(533, 400);
                    _floorPlanImage = rf.Apply((Bitmap)img);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                Fpc.NeedSizeUpdate = true;
                Fpc.NeedsRefresh   = true;
                if (txtName.Text.Trim() == "")
                {
                    txtName.Text = "Plan " + MainForm.NextFloorPlanId;
                }
                _pnlPlan.Invalidate();
            }
            ofd.Dispose();
        }
예제 #15
0
파일: MainForm.cs 프로젝트: BlueMadWolf/IS
        // New frame received by the player
        private void videoSourcePlayer_NewFrame(object sender, ref Bitmap image)
        {
            //DateTime now = DateTime.Now;
            Graphics g = Graphics.FromImage(image);

            // paint current time
            //SolidBrush brush = new SolidBrush( Color.Red );
            //g.DrawString( now.ToString( ), this.Font, brush, new PointF( 5, 5 ) );

            if (radioButtonFixPicNo.Checked)
            {
                Crop           filter   = new Crop(new Rectangle(50, 300, 400, 400));
                Bitmap         newImage = filter.Apply(image);
                ResizeBilinear filter1  = new ResizeBilinear(200, 200);
                newImage = filter1.Apply(newImage);
                GrayscaleBT709 filter2   = new GrayscaleBT709();
                Bitmap         grayImage = filter2.Apply(newImage);
                ResizeBilinear filter3   = new ResizeBilinear(28, 28);
                Bitmap         smallPic  = filter3.Apply(grayImage);

                pictureBox1.Image = grayImage;
                pictureBox2.Image = smallPic;
            }

            //brush.Dispose( );
            g.Dispose( );
        }
예제 #16
0
        /// <summary>
        /// Crop the blob from the image
        /// </summary>
        private Bitmap CropBlob(BlobPanel blob, System.Drawing.Image source, int rotationAngel = 0)
        {
            // Create the target image, this is a squared image.
            int    size     = Math.Max(blob.Height, blob.Width);
            Bitmap newImage = new Bitmap(size, size, PixelFormat.Format24bppRgb);

            // Get the graphics object of the image.
            Graphics g = Graphics.FromImage(newImage);

            // Create the background color to use (the image we create is larger than the blob (as we squared it)
            // so this would be the color of the excess areas.
            Color bColor = Color.FromArgb((int)txtExtractedBackColor.Value, (int)txtExtractedBackColor.Value, (int)txtExtractedBackColor.Value);

            // Fill back color.
            g.FillRectangle(new SolidBrush(bColor), 0, 0, size, size);

            // Now we clip the blob from the PictureBox image.
            g.DrawImage(source, new Rectangle(0, 0, blob.Width, blob.Height), blob.Left, blob.Top, blob.Width, blob.Height, GraphicsUnit.Pixel);
            g.Dispose();

            if (rotationAngel != 0)
            {
                RotateBilinear filter = new RotateBilinear(rotationAngel, true);
                filter.FillColor = bColor;
                // apply the filter
                newImage = filter.Apply(newImage);
            }

            // Resize the image.
            ResizeBilinear resizefilter = new ResizeBilinear((int)txtExportSize.Value, (int)txtExportSize.Value);

            newImage = resizefilter.Apply(newImage);

            return(newImage);
        }
예제 #17
0
        public void ProcessImage(string urlImage)       //Görüntünün işlendiği metot.
        {
            Stopwatch watch = Stopwatch.StartNew();     //Görüntünün işlenmesi sırasında süre tutulması için süre başlatılmaktadır.

            Bitmap root         = new Bitmap(urlImage); //Root Image (Default Image)
            Bitmap bmp          = new Bitmap(root);     //Resize Image
            Bitmap bmp1         = new Bitmap(root);     //Smoothing Image
            Bitmap bmp2         = new Bitmap(root);     //Color Filtering Image
            string outputstring = "";

            ///Root
            outputstring          = this.Ocr(root);
            txtNumbePlate1.Text   = outputstring;
            ptBNumberPlate1.Image = root;


            //Resize Image to : 1920x1080
            outputstring = "";
            ResizeBilinear filterr = new ResizeBilinear(1920, 1080);

            bmp = filterr.Apply(bmp);

            outputstring          = this.Ocr(bmp);
            txtNumbePlate2.Text   = outputstring;
            ptBNumberPlate2.Image = bmp;


            //Smoothing
            outputstring = "";
            if (BitmapFilter.GaussianBlur(bmp1, 4))
            {
                if (BitmapFilter.GaussianBlur(bmp1, 4))
                {
                    if (BitmapFilter.MeanRemoval(bmp1, 9))
                    {
                    }
                }
            }
            outputstring          = this.Ocr(bmp1);
            txtNumbePlate3.Text   = outputstring;
            ptBNumberPlate3.Image = bmp1;


            //Color Filtering
            outputstring = "";
            ColorFiltering filter = new ColorFiltering();

            filter.Green = new IntRange(175, 255);
            bmp2         = filter.Apply(bmp2);

            outputstring          = this.Ocr(bmp2);
            txtNumbePlate4.Text   = outputstring;
            ptBNumberPlate4.Image = bmp2;

            watch.Stop(); //Stop The Timer
            lblTime.Text  = String.Format("Total Time : {0} Seconds", watch.Elapsed.TotalSeconds);
            lblCount.Text = position.ToString() + "/" + lstimages.Count.ToString();
            System.Threading.Thread.Sleep(5000);
        }
        public static Bitmap encryptImage(Bitmap mainImage, Bitmap hiddenImage)
        {
            if (hiddenImage.Height != mainImage.Height || hiddenImage.Width != mainImage.Width)
            {
                ResizeBilinear resizeFilter = new ResizeBilinear(mainImage.Width, mainImage.Height);
                hiddenImage = resizeFilter.Apply(hiddenImage);
            }

            Color pixelContainerImage = new Color();
            Color pixelMsgImage       = new Color();

            byte[] MsgBits;
            byte[] AlphaBits;
            byte[] RedBits;
            byte[] GreenBits;
            byte[] BlueBits;

            byte newAlpha = 0;
            byte newRed   = 0;
            byte newGreen = 0;
            byte newBlue  = 0;

            for (int i = 0; i < mainImage.Height; i++)
            {
                for (int j = 0; j < mainImage.Width; j++)
                {
                    pixelMsgImage = hiddenImage.GetPixel(j, i);
                    MsgBits       = getBits((byte)pixelMsgImage.R);

                    pixelContainerImage = mainImage.GetPixel(j, i);
                    AlphaBits           = getBits((byte)pixelContainerImage.A);
                    RedBits             = getBits((byte)pixelContainerImage.R);
                    GreenBits           = getBits((byte)pixelContainerImage.G);
                    BlueBits            = getBits((byte)pixelContainerImage.B);

                    AlphaBits[6] = MsgBits[0];
                    AlphaBits[7] = MsgBits[1];

                    RedBits[6] = MsgBits[2];
                    RedBits[7] = MsgBits[3];

                    GreenBits[6] = MsgBits[4];
                    GreenBits[7] = MsgBits[5];

                    BlueBits[6] = MsgBits[6];
                    BlueBits[7] = MsgBits[7];

                    newAlpha = getByte(AlphaBits);
                    newRed   = getByte(RedBits);
                    newGreen = getByte(GreenBits);
                    newBlue  = getByte(BlueBits);

                    pixelContainerImage = Color.FromArgb(newAlpha, newRed, newGreen, newBlue);
                    mainImage.SetPixel(j, i, pixelContainerImage);
                }
            }

            return(mainImage);
        }
예제 #19
0
        //used to actually resize the bitmap to match the reference image.
        private static Bitmap resizeBitmap(Bitmap bitmap, int width, int height)
        {
            ResizeBilinear resizer = new ResizeBilinear(width, height);

            Bitmap result = resizer.Apply(bitmap);

            return(result);
        }
예제 #20
0
        private void Device_NewFrame(object sender, NewFrameEventArgs args)
        {
            //var time = DateTime.Now;
            _currentSourceImage = _resizer.Apply(UnmanagedImage.FromManagedImage(args.Frame));
            //MessageBox.Show((DateTime.Now - time).TotalMilliseconds.ToString("F4"));

            _frameRecievedEvent.Set();
        }
예제 #21
0
        public Bitmap Difference(Bitmap leftOperand, Bitmap rightOperand)
        {
            ResizeBilinear resize = new ResizeBilinear(leftOperand.Width, leftOperand.Height);

            rightOperand = resize.Apply(rightOperand);
            Difference filter = new Difference(rightOperand);

            return(filter.Apply(leftOperand));
        }
예제 #22
0
        public Bitmap Subtract(Bitmap leftOperand, Bitmap rightOperand)
        {
            ResizeBilinear resize = new ResizeBilinear(leftOperand.Width, leftOperand.Height);

            rightOperand = resize.Apply(rightOperand);
            Subtract filter = new Subtract(rightOperand);

            return(filter.Apply(leftOperand));
        }
예제 #23
0
        public Bitmap Multiply(Bitmap leftOperand, Bitmap rightOperand)
        {
            ResizeBilinear resize = new ResizeBilinear(leftOperand.Width, leftOperand.Height);

            rightOperand = resize.Apply(rightOperand);
            Multiply filter = new Multiply(rightOperand);

            return(filter.Apply(leftOperand));
        }
예제 #24
0
        public static Bitmap ResizeBilinear(Bitmap bmp, int width, int height)
        {
            // create filter
            ResizeBilinear filter = new ResizeBilinear(width, height);
            // apply the filter
            Bitmap newImage = filter.Apply(bmp);

            return(newImage);
        }
예제 #25
0
파일: MainForm.cs 프로젝트: BlueMadWolf/IS
        public List <double> GetSensorsFromBitmap(Bitmap image)
        {
            List <double> sensors = new List <double>(cnt_blocks_one_line * cnt_blocks_one_line);

            //Bitmap im = (Bitmap)pictureBox1.Image;
            ResizeBilinear filter = new ResizeBilinear(28, 28);
            Bitmap         im     = filter.Apply(image);

            /*
             * for (int y = 0; y < 28; ++y)
             * {
             *  double sum = 0;
             *  for (int x = 0; x < 28; ++x)
             *  {
             *      Color c = im.GetPixel(x, y);
             *      double curr_value = (int)c.R;
             *      sum += curr_value / 255.0;
             *  }
             *  input_camera.Add((sum / 28.0));// * 2 - 1);
             * }
             * for (int x = 0; x < 28; ++x)
             * {
             *  double sum = 0;
             *  for (int y = 0; y < 28; ++y)
             *  {
             *      double curr_value = (int)im.GetPixel(x, y).R;
             *      sum += curr_value / 255.0;
             *  }
             *  input_camera.Add((sum / 28.0));// * 2 - 1);
             * }
             */

            int length = 28 / cnt_blocks_one_line;

            for (int y1 = 0; y1 < cnt_blocks_one_line; ++y1)
            {
                for (int x1 = 0; x1 < cnt_blocks_one_line; ++x1)
                {
                    double sum = 0;
                    for (int y2 = 0; y2 < length; ++y2)
                    {
                        for (int x2 = 0; x2 < length; ++x2)
                        {
                            int y          = y1 * length + y2;
                            int x          = x1 * length + x2;
                            int curr_value = (int)im.GetPixel(x, y).R;
                            sum += curr_value / 255.0;
                        }
                    }
                    int ind = y1 * cnt_blocks_one_line + x1;
                    sensors.Add((sum / length / length));// * 2 - 1);
                }
            }

            return(sensors);
        }
예제 #26
0
        void goruntuGuncelle()
        {
            try
            {
                if (comboBox1.SelectedIndex == 0)
                {
                    //resim döndürme filtresi tanımlandı
                    //bu filtre sistemi yormuyor
                    //diğerleri sistemi zorluyor
                    //resim döndürme saat yönünün tersine doğru yapılıyor

                    //fonksiyona paremetre olarak true verilirse resmin tamamı ekrana sığdırılmıyor
                    //bazı yerler kırpılıyor
                    //fakat resim boyutu (genişliği ve yükseliği) değişmiyor
                    //görüntü daha güzel görünüyor

                    //eğer false olursa resim küçültme büyütme işlemelerinde resim boyutuda (genişliği ve yükseliği) değişiyor
                    //yani false olunca resim daima ekrana sığdırılıyor
                    RotateNearestNeighbor boyutlandirmaFiltresi = new RotateNearestNeighbor(trackBar1.Value, tamEkran);
                    //resim dosyasına filtre uygulandı
                    pictureBox2.Image = boyutlandirmaFiltresi.Apply((Bitmap)pictureBox1.Image);
                    //resim boyut değiştirme filtresi tanımlandı
                    //bu filtre sistemi yormuyor
                    //diğerleri sistemi zorluyor
                    ResizeNearestNeighbor boyutlandirma = new ResizeNearestNeighbor(resim.Width + trackBar2.Value, resim.Height + trackBar2.Value);
                    //resim dosyasına filtre uygulandı
                    pictureBox2.Image = boyutlandirma.Apply((Bitmap)pictureBox1.Image);
                }
                if (comboBox1.SelectedIndex == 1)
                {
                    //resim döndürme filtresi tanımlandı
                    RotateBilinear boyutlandirmaFiltresi = new RotateBilinear(trackBar1.Value, tamEkran);
                    //resim dosyasına filtre uygulandı
                    pictureBox2.Image = boyutlandirmaFiltresi.Apply((Bitmap)pictureBox1.Image);
                    //resim boyut değiştirme filtresi tanımlandı
                    ResizeBicubic boyutlandirma = new ResizeBicubic(resim.Width + trackBar2.Value, resim.Height + trackBar2.Value);
                    //resim dosyasına filtre uygulandı
                    pictureBox2.Image = boyutlandirma.Apply((Bitmap)pictureBox1.Image);
                }
                if (comboBox1.SelectedIndex == 2)
                {
                    //resim döndürme filtresi tanımlandı
                    RotateBicubic boyutlandirmaFiltresi = new RotateBicubic(trackBar1.Value, tamEkran);
                    //resim dosyasına filtre uygulandı
                    pictureBox2.Image = boyutlandirmaFiltresi.Apply((Bitmap)pictureBox1.Image);
                    //resim boyut değiştirme filtresi tanımlandı
                    ResizeBilinear boyutlandirma = new ResizeBilinear(resim.Width + trackBar2.Value, resim.Height + trackBar2.Value);
                    //resim dosyasına filtre uygulandı
                    pictureBox2.Image = boyutlandirma.Apply((Bitmap)pictureBox1.Image);
                }
            }
            catch
            {
            }
        }
예제 #27
0
        private void getFrame(object sender, NewFrameEventArgs eventArgs)
        {
            Bitmap         BsourceImage = (Bitmap)eventArgs.Frame.Clone();
            ResizeBilinear scale_filter = new ResizeBilinear(pictureBox1.Width, pictureBox1.Height);

            BsourceImage      = scale_filter.Apply(BsourceImage);
            pictureBox1.Image = BsourceImage;

            g = Graphics.FromImage(pictureBox1.Image);
            g.DrawRectangle(Pens.Red, new Rectangle(50, 50, 200, 200));
        }
예제 #28
0
        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            if (lastUsableFrame != null)
            {
                string minTemp = rawToTemp(gModeLeft);
                string maxTemp = rawToTemp(gModeRight);

                lblSliderMin.Text = minTemp;
                lblSliderMax.Text = maxTemp;
                lblMinTemp.Text   = minTemp;
                lblMaxTemp.Text   = maxTemp;

                lblLeft.Text  = gModeLeft.ToString();
                lblRight.Text = gModeRight.ToString();
                label2.Text   = maxTempRaw.ToString();

                if (autoRange)//set sliders position
                {
                    trackBar2.Value = gModeLeft;
                    trackBar1.Value = gModeRight;
                }

                bitmap_data = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.WriteOnly, PixelFormat.Format24bppRgb);
                Marshal.Copy(imgBuffer, 0, bitmap_data.Scan0, imgBuffer.Length);
                bitmap.UnlockBits(bitmap_data);

                //crop image to 206x156
                croppedBitmap = cropFilter.Apply(bitmap);

                //upscale 200 %
                bigBitmap = bilinearResize.Apply(croppedBitmap);

                //sharpen image
                if (SharpenImage)
                {
                    sfilter.ApplyInPlace(bigBitmap);
                }

                pictureBox3.Image = bigBitmap;

                if (firstAfterCal)
                {
                    firstAfterCal     = false;
                    pictureBox5.Image = bigBitmap;
                    if (autoSaveImg)
                    {
                        bigBitmap.Save(localPath + @"\export\seek_" + DateTime.Now.ToString("yyyy-MM-dd_hh-mm-ss_fff") + ".png");
                    }
                }

                DrawHistogram();
            }
        }
예제 #29
0
        public Bitmap GetThumb(string path, int width, int height)
        {
            using (var original = Image.FromFile(path))
            {
                // create filter
                var filter = new ResizeBilinear(width, height);
                // apply the filter
                var newImage = filter.Apply(original);

                return(newImage);
            }
        }
        public static System.Drawing.Image ResizeImage(System.Drawing.Image SourceImage)
        {
            try {
//				// binarization filtering sequence
//	            FiltersSequence filter = new FiltersSequence(
//	                new Crop(rect),
//	                new Median(),
//	                new ContrastCorrection(),
//	                //new Mean(),
//	                new AForge.Imaging.Filters.Blur(),
//	                new GrayscaleBT709(),
//	                //new Threshold(),
//	                new Threshold(),
//	                new Invert()
//
//	            );


                // load image
                Bitmap image = (Bitmap)SourceImage;

                // format image
                AForge.Imaging.Image.Clone(image, image.PixelFormat);
                //            AForge.Imaging.Image.FormatImage(ref image);

                // lock the source image
                BitmapData sourceData = image.LockBits(new Rectangle(0, 0, image.Width, image.Height), ImageLockMode.ReadOnly, image.PixelFormat);

                // create filter
                ResizeBilinear filter = new ResizeBilinear(image.Width / 2, image.Height / 2);
                // apply the filter
//	            Bitmap newImage = filter.Apply( image );

                UnmanagedImage binarySource = filter.Apply(new UnmanagedImage(sourceData));


                Bitmap binarizedImage = binarySource.ToManagedImage();


                // unlock source image
                image.UnlockBits(sourceData);

                // dispose temporary binary source image
                binarySource.Dispose();

                System.Drawing.Image img = (System.Drawing.Image)binarizedImage;

                return(img);
            } catch (Exception ex) {
                throw ex;
            }
        }