public List <bloc> analyse(List <bloc> liste_bloc1, List <bloc> liste_bloc2)
        {
            a = new UnsafeBitmap(image1);
            b = new UnsafeBitmap(image2);
            bloc        rst      = new bloc();
            List <bloc> resultat = new List <bloc>();
            //   List<bloc> liste_bloc1= new List<bloc>();
            //   List<bloc> liste_bloc2= new List<bloc>();
            //   liste_bloc1= decoupage(image1);
            //  liste_bloc2= decoupage(image2);
            DateTime start = DateTime.Now;

            //  MessageBox.Show(liste_bloc1.Count.ToString());
            a.LockBitmap();
            b.LockBitmap();
            object o = new object();

            zmp(ref liste_bloc1, ref liste_bloc2);

            //   MessageBox.Show(liste_bloc1.Count.ToString());
            AForge.Parallel.For(0, liste_bloc1.Count, delegate(int i)
                                //   for(int i=0;i<liste_bloc1.Count;i++)
            {
                rst = diamond_search(liste_bloc1[i]);

                if (lst_contain(liste_bloc1, rst) == true)
                {
                    lock (o)
                    {
                        if ((rst.x != liste_bloc1[i].x) || (rst.y != liste_bloc1[i].y)) //MessageBox.Show("kifkif");
                        {
                            resultat.Add(rst);
                        }
                        //            sad_moyen += SAD(liste_bloc1[i], rst);
                        //          compteur_sad++;
                        // MessageBox.Show(SAD(liste_bloc1[i],rst).ToString());
                        //sad_moyen.Add(SAD(liste_bloc1[i], rst));
                    }
                }
            });


            //  sad_moyen = sad_moyen / compteur_sad;
            //);
            a.UnlockBitmap();
            b.UnlockBitmap();
            //fic_ecr.Close();
            //sady.Close();
            //sadt.Close();
            // MessageBox.Show(sad_moyen.Average().ToString());
            TimeSpan dur = DateTime.Now - start;

            //  MessageBox.Show(dur.ToString());
            return(resultat);
        }
示例#2
0
        public void Iterate()
        {
            _colourClusterAllocation    = new Hashtable(); //for keeping track of colour<->cluster allocation
            _pixelDataClusterAllocation = new Hashtable();
            _clusterColours             = new Hashtable();

            UnsafeBitmap fastBitmap = new UnsafeBitmap(_image);

            fastBitmap.LockBitmap();
            Point size = fastBitmap.Size;
            BGRA *pPixel;

            for (int y = 0; y < size.Y; y++)
            {
                pPixel = fastBitmap[0, y];
                for (int x = 0; x < size.X; x++)
                {
                    PixelData pd = Colour.GetPixelData(pPixel, _model);
                    AllocateToCluster(pd);

                    //increment the pointer
                    pPixel++;
                }
            }
            fastBitmap.UnlockBitmap();

            CalculateClusterCentroids();

            _processedImage = (Bitmap)_image.Clone();

            //segment the image based on the cluster
            fastBitmap = new UnsafeBitmap(_processedImage);
            fastBitmap.LockBitmap();
            for (int y = 0; y < size.Y; y++)
            {
                pPixel = fastBitmap[0, y];
                for (int x = 0; x < size.X; x++)
                {
                    PixelData pd     = Colour.GetPixelData(pPixel, _model);
                    Color     newClr = (Color)_clusterColours[pd.Name];

                    pPixel->red   = newClr.R;
                    pPixel->green = newClr.G;
                    pPixel->blue  = newClr.B;

                    //increment the pointer
                    pPixel++;
                }
            }

            fastBitmap.UnlockBitmap();

            CheckConvergence();
        }
示例#3
0
        private void FindTopXColours(int numColours)
        {
            Dictionary <string, ColourCount> colours = new Dictionary <string, ColourCount>();
            UnsafeBitmap fastBitmap = new UnsafeBitmap(_image);

            fastBitmap.LockBitmap();
            Point size = fastBitmap.Size;
            BGRA *pPixel;

            for (int y = 0; y < size.Y; y++)
            {
                pPixel = fastBitmap[0, y];
                for (int x = 0; x < size.X; x++)
                {
                    //get the bin index for the current pixel colour
                    Color clr = Color.FromArgb(pPixel->red, pPixel->green, pPixel->blue);

                    if (colours.ContainsKey(clr.Name))
                    {
                        ((ColourCount)colours[clr.Name]).Count++;
                    }
                    else
                    {
                        colours.Add(clr.Name, new ColourCount(clr, 1));
                    }

                    //increment the pointer
                    pPixel++;
                }
            }

            fastBitmap.UnlockBitmap();

            //instantiate using actual colours found - which might be less than numColours
            if (colours.Count < numColours)
            {
                numColours = colours.Count;
            }

            _topColours = new Color[numColours];

            List <KeyValuePair <string, ColourCount> > summaryList = new List <KeyValuePair <string, ColourCount> >();

            summaryList.AddRange(colours);

            summaryList.Sort(delegate(KeyValuePair <string, ColourCount> kvp1, KeyValuePair <string, ColourCount> kvp2)
                             { return(Comparer <int> .Default.Compare(kvp2.Value.Count, kvp1.Value.Count)); });


            for (int i = 0; i < _topColours.Length; i++)
            {
                _topColours[i] = Color.FromArgb(summaryList[i].Value.Colour.R, summaryList[i].Value.Colour.G, summaryList[i].Value.Colour.B);
            }
        }
示例#4
0
        public void DrawBitmap(Bitmap bmp)
        {
            UnsafeBitmap ubmp = new UnsafeBitmap(bmp);

            ubmp.LockBitmap();
            try
            {
                DrawBitmap(ubmp);
            }
            finally
            {
                ubmp.UnlockBitmap();
            }
        }
示例#5
0
        private void CreateSecondMark(int scrollBarWid)
        {
            int          w = scrollBarWid - 1;
            int          h = scrollBarWid - 2;
            UnsafeBitmap b = new UnsafeBitmap(w, h);

            b.LockBitmap();
            FormUtil.FillShadedRectangle(b, w, h);
            UnsafeBitmap bh = b.Lighter();
            UnsafeBitmap bp = b.Darker();

            b.UnlockBitmap();
            bh.UnlockBitmap();
            bp.UnlockBitmap();
            secondMark = b.Bitmap;
            secondMark.MakeTransparent();
            secondMarkHighlight = bh.Bitmap;
            secondMarkHighlight.MakeTransparent();
            secondMarkPress = bp.Bitmap;
            secondMarkPress.MakeTransparent();
        }
示例#6
0
        private void CreateBar(int scrollBarWid, int width)
        {
            int          w = CalcBarSize(width);
            int          h = scrollBarWid - 2;
            UnsafeBitmap b = new UnsafeBitmap(w, h);

            b.LockBitmap();
            FormUtil.FillShadedRectangle(b, w, h);
            UnsafeBitmap bh = b.Lighter();
            UnsafeBitmap bp = b.Darker();

            b.UnlockBitmap();
            bh.UnlockBitmap();
            bp.UnlockBitmap();
            bar = b.Bitmap;
            bar.MakeTransparent();
            barHighlight = bh.Bitmap;
            barHighlight.MakeTransparent();
            barPress = bp.Bitmap;
            barPress.MakeTransparent();
        }
示例#7
0
 /// <summary>
 /// Processing the input
 /// </summary>
 /// <param name="image"></param>
 private void GetOnOffState(ref Bitmap image)
 {
     if (line_drawed)
     {
         Rectangle    rect    = new Rectangle(pt.X - 3, pt.Y - 3, 6, 6);
         Bitmap       img     = image.Clone(rect, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
         UnsafeBitmap uBitmap = new UnsafeBitmap(img);
         uBitmap.LockBitmap();
         float avgBritness = 0;
         for (int x = 0; x < 6; x++)
         {
             for (int y = 0; y < 6; y++)
             {
                 byte red, green, blue;
                 red          = uBitmap.GetPixel(x, y).red;
                 green        = uBitmap.GetPixel(x, y).green;
                 blue         = uBitmap.GetPixel(x, y).blue;
                 avgBritness += (299 * red + 587 * green + 114 * blue) / 1000;
             }
         }
         avgBritness /= 36;
         uBitmap.UnlockBitmap();
         // nUD_brightness threshold for brightness value ( "On" state)
         if (avgBritness > (float)nUD_brightness.Value)
         {
             if (check)
             {
                 if (sw.IsRunning)
                 {
                     if (sw.ElapsedMilliseconds > nUD_char.Value && sw.ElapsedMilliseconds <= nUD_word.Value)
                     {
                         Append_morse(" ");
                     }
                     else if (sw.ElapsedMilliseconds > nUD_word.Value)
                     {
                         Append_morse("/");
                     }
                     Append_logging("Off Time : " + Convert.ToString(sw.ElapsedMilliseconds) + "ms\n");
                     sw.Reset();
                     sw.Start();
                 }
                 else
                 {
                     sw.Reset();
                     sw.Start();
                 }
                 check = false;
             }
         }
         //"off" state
         else
         {
             if (!check)
             {
                 if (sw.IsRunning)
                 {
                     if (sw.ElapsedMilliseconds < nUD_dot.Value)
                     {
                         Append_morse(".");
                     }
                     else
                     {
                         Append_morse("-");
                     }
                     Append_logging("On Time : " + Convert.ToString(sw.ElapsedMilliseconds) + " ms\n");
                     sw.Reset();
                     sw.Start();
                 }
                 check = true;
             }
         }
     }
     else
     {
         MessageBox.Show("Please click the pictureBox again and set the place where from the morse code is captured.");
     }
 }
        protected void PaintOnGraphicsBitmap(IGraphics g, int width, int height)
        {
            if (backBuffer == null || scatterPlot == null)
            {
                return;
            }
            UnsafeBitmap copyBackBuffer = new UnsafeBitmap(backBuffer);

            copyBackBuffer.LockBitmap();
            // selected data-points
            foreach (int s in scatterPlot.Selection)
            {
                double[] w = scatterPlot.GetDataAt(s);
                if (w.Length > 0)
                {
                    double           x  = w[0];
                    double           y  = w[1];
                    SymbolProperties gx = GetPointProperties != null?GetPointProperties(s) : defaultSymbol;

                    SymbolType symbolType = SymbolType.allSymbols[gx.Type];
                    int        symbolSize = gx.Size;
                    if (symbolSize > 0)
                    {
                        int[] pathX;
                        int[] pathY;
                        symbolType.GetPath(symbolSize, out pathX, out pathY);
                        copyBackBuffer.DrawPath(SelectionColor, ModelToViewX(x, width), ModelToViewY(y, height), pathX, pathY);
                    }
                }
            }
            copyBackBuffer.UnlockBitmap();
            // labels
            ScatterPlotLabelMode labelMode = scatterPlot.GetLabelMode();
            bool cutLabels = scatterPlot.CutLabels;

            if (labelMode == ScatterPlotLabelMode.All && scatterPlot.HasLabels)
            {
                Font font = new Font("Arial", scatterPlot.FontSize, scatterPlot.FontStyle);
                for (;;)
                {
                    double[] x;
                    double[] y;
                    double[] z;
                    string[] labels;
                    int      index;
                    try{
                        scatterPlot.GetData(out x, out y, out z, out labels, out index);
                    } catch (IndexOutOfRangeException) {
                        break;
                    }
                    if (x == null)
                    {
                        break;
                    }
                    SymbolProperties gx = GetPointProperties != null?GetPointProperties(index) : defaultSymbol;

                    for (int i = 0; i < x.Length; i++)
                    {
                        if (labelMode == ScatterPlotLabelMode.All || scatterPlot.IsSelected(i))
                        {
                            int   ix = ModelToViewX(x[i], width);
                            int   iy = ModelToViewY(y[i], height);
                            Color c;
                            if (z != null && colorScale != null)
                            {
                                c = colorScale.GetColor(z[i]);
                            }
                            else
                            {
                                c = gx.Color;
                            }
                            Brush b = new SolidBrush(c);
                            if (ix >= 0 && iy >= 0 && ix < width && iy < height)
                            {
                                if (labels[i] != null)
                                {
                                    string s = labels[i];
                                    if (cutLabels)
                                    {
                                        if (s.Contains(";"))
                                        {
                                            s = s.Substring(0, s.IndexOf(';'));
                                        }
                                    }
                                    copyBackBuffer.DrawString(s, font, b, ix, iy);
                                }
                            }
                        }
                    }
                }
                scatterPlot.Reset();
            }
            if (labelMode == ScatterPlotLabelMode.Selected && scatterPlot.HasLabels)
            {
                Brush br   = new SolidBrush(SelectionColor);
                Font  font = new Font("Arial", scatterPlot.FontSize, scatterPlot.FontStyle);
                foreach (int s in scatterPlot.Selection)
                {
                    double[] w     = scatterPlot.GetDataAt(s);
                    string   label = scatterPlot.GetLabelAt(s);
                    double   x     = w[0];
                    double   y     = w[1];
                    int      ix    = ModelToViewX(x, width);
                    int      iy    = ModelToViewY(y, height);
                    if (ix >= 0 && iy >= 0 && ix < width && iy < height)
                    {
                        if (label != null)
                        {
                            if (cutLabels)
                            {
                                if (label.Contains(";"))
                                {
                                    label = label.Substring(0, label.IndexOf(';'));
                                }
                            }
                            copyBackBuffer.DrawString(label, font, br, ix, iy);
                        }
                    }
                }
            }
            // draw the image
            g.DrawImageUnscaled(copyBackBuffer.Bitmap, 0, 0);
            copyBackBuffer.Dispose();
            g.SmoothingMode = SmoothingMode.AntiAlias;
            DrawPolygons(g, width, height);
            if (drawFunctions != null)
            {
                drawFunctions(g, width, height, ModelToViewX, ModelToViewY, ViewToModelX, ViewToModelY);
            }
            g.SmoothingMode = SmoothingMode.Default;
        }
        protected internal override void OnPaint(IGraphics g, int width, int height)
        {
            if (width <= 0 || height <= 0)
            {
                return;
            }
            if (!Visible)
            {
                return;
            }
            Brush foreBrush = new SolidBrush(ForeColor);

            if (paintBackground && IsInitialized() && !IsDragging())
            {
                g.DrawString("Loading...", Font, foreBrush, width / 2 - 20, height / 2 - 10);
            }
            if (scatterPlot == null)
            {
                return;
            }
            if (width != prevWidth || height != prevHeight)
            {
                InvalidateData();
            }
            prevHeight = height;
            prevWidth  = width;
            if (ValuesNeedRecalc())
            {
                if (!IsDragging())
                {
                    RecalcValues(width, height);
                }
                return;
            }
            if (backBuffer == null)
            {
                lockBackBuffer = true;
                backBuffer     = new UnsafeBitmap(width, height);
                backBuffer.LockBitmap();
                PaintOnBackBuffer(width, height);
                backBuffer.UnlockBitmap();
                lockBackBuffer = false;
            }
            vectorGraphics = !(g is CGraphics);
            if (vectorGraphics)
            {
                PaintOnGraphicsVector(g, width, height);
            }
            else
            {
                PaintOnGraphicsBitmap(g, width, height);
            }
            if (indicatorX1 != -1 && indicatorX2 != -1 && indicatorY1 != -1 && indicatorY2 != -1)
            {
                g.SmoothingMode = SmoothingMode.AntiAlias;
                Pen indicatorPen = new Pen(Color.Black)
                {
                    DashStyle = DashStyle.Dot
                };
                switch (MouseMode)
                {
                case ScatterPlotMouseMode.Select:
                case ScatterPlotMouseMode.Zoom: {
                    g.DrawRectangle(indicatorPen, MinIndicatorX, MinIndicatorY, DeltaIndicatorX, DeltaIndicatorY);
                }
                break;
                }
                g.SmoothingMode = SmoothingMode.Default;
            }
        }
示例#10
0
        static void Main(string[] args)
        {
            int w = 84;
            int h = 48;

            // use form to test on desktop
            //ILcd lcd = new TestFormLCD(w, h);

            ILcd lcd = new PCD8544Lcd(w, h);


            lcd.Connect();

            Console.WriteLine("Turning on led");
            lcd.SetLed(true);


            Random       rnd  = new Random();
            Bitmap       bmp  = new Bitmap(84, 48, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
            UnsafeBitmap ubmp = new UnsafeBitmap(bmp);
            Graphics     g    = Graphics.FromImage(ubmp.Bitmap);

            List <Ball> balls = new List <Ball>();

            for (int i = 0; i < 10; i++)
            {
                Ball b = new Ball()
                {
                    Size      = new Size(10, 10),
                    Direction = new PointF((float)rnd.NextDouble() * 4 - 2, (float)rnd.NextDouble() * 4 - 2)
                };
                balls.Add(b);
            }

            while (true)
            {
                g.Clear(Color.White);

                using (System.Drawing.Drawing2D.LinearGradientBrush b = new System.Drawing.Drawing2D.LinearGradientBrush(new Point(0, 0), new Point(84, 48), Color.White, Color.Black))
                {
                    g.FillRectangle(b, new Rectangle(0, 0, w, h));
                }
                foreach (var b in balls)
                {
                    DrawBall(g, b);
                    UpdateBallPosition(lcd, b);
                }

                using (Font f = new Font(SystemFonts.DefaultFont.FontFamily, 20))
                {
                    g.DrawString("Test", f, Brushes.Black, new PointF(0, 0));
                }

                ubmp.LockBitmap();
                lcd.DrawBitmap(ubmp);
                ubmp.UnlockBitmap();

                lcd.Refresh();
                System.Threading.Thread.Sleep(25);
            }

            lcd.SetLed(false);


            lcd.Dispose();
        }