示例#1
0
        private void AnalyzeAndDisplayImage(string filename)
        {
            this.Dispatcher.BeginInvoke(delegate()
            {

                using (IsolatedStorageFile isStore = IsolatedStorageFile.GetUserStoreForApplication())
                using (IsolatedStorageFileStream sourceStream = isStore.OpenFile(filename, FileMode.Open))
                {
                    sourceStream.Seek(0, SeekOrigin.Begin);
                    wb.LoadJpeg(sourceStream);
                    wb.Invalidate();
                }

                Analyzer analyzer = new Analyzer();
                List<AnalyzedObject> analyzedObjects = analyzer.analyzeImage(wb.Pixels,
                                (int)cam.Resolution.Width, (int)cam.Resolution.Height);

                GenerateListofRectangles(analyzedObjects);

                AnalyzedState state_o = analyzer.decide(analyzedObjects);
                var uri = string.Format("Assets/{0}.mp3", state_o.ToString());
                MyMedia.Source = new Uri(uri, UriKind.RelativeOrAbsolute);
                MyMedia.Play();

            });
        }
示例#2
0
        private AnalyzedState runAnalyzer(string imagePath)
        {
            Uri uri = new Uri(imagePath, UriKind.RelativeOrAbsolute);
            Analyzer analyzer = new Analyzer();

            System.Drawing.Bitmap image = new System.Drawing.Bitmap(imagePath);

            //// Loop through the image
            int[] map = new int[(int)image.Width * (int)image.Height];

            for (int x = 0; x < image.Width; x++)
            {
                for (int y = 0; y < image.Height; y++)
                {
                    System.Drawing.Color pixelColor = image.GetPixel(x, y);
                    map[y*image.Width + x] = pixelColor.ToArgb();
                    pixelColor.GetHue();
                }
            }

            List<AnalyzedObject> objectList = analyzer.analyzeImage(map, image.Width, image.Height);
            return analyzer.decide(objectList);
            //foreach (AnalyzedObject o in objectList)
            //    if (o.decision == true)
            //    {
            //        if (o.color.Equal(Color.green)) return AnalyzedState.Green;
            //        else if (o.color.Equal(Color.red)) return AnalyzedState.Red;
            //        else return AnalyzedState.Unknown;
            //    }
            //return AnalyzedState.Unknown;
        }
示例#3
0
文件: Form1.cs 项目: kfirt/BlindPhone
        private void button2_Click(object sender, EventArgs e)
        {
            textBox1.Text = "Analyzing...";
            System.Drawing.Bitmap image = new System.Drawing.Bitmap(path);

            // Loop through the image
            int[] map = new int[(int)image.Width * (int)image.Height];
            for (int y = 0; y < image.Height; y++)
            {
                for (int x = 0; x < image.Width; x++)
                {
                    System.Drawing.Color pixelColor = image.GetPixel(x, y);
                    map[y * image.Width + x] = pixelColor.ToArgb();
                }
            }

            System.Diagnostics.Stopwatch st = new System.Diagnostics.Stopwatch();
            st.Start();
            Analyzer analyzer = new Analyzer();
            analyzedObjects = analyzer.analyzeImage(map, image.Width, image.Height);
            this.rects.Clear();

            foreach (var analyzedObject in analyzedObjects)
            {
                int x1 = analyzedObject.bBox.topLeft.x;
                int y1 = analyzedObject.bBox.topLeft.y;
                int x2 = analyzedObject.bBox.bottomRight.x;
                int y2 = analyzedObject.bBox.bottomRight.y;

                double scaleX = (double)pictureBox1.Width / (double)image.Width;
                double scaleY = (double)pictureBox1.Height / (double)image.Height;

                int scalex1 = Convert.ToInt32(x1 * scaleX);
                int scalex2 = Convert.ToInt32(x2 * scaleX);

                int scaley1 = Convert.ToInt32(y1 * scaleY);
                int scaley2 = Convert.ToInt32(y2 * scaleY);

                System.Drawing.Color color;
                if (analyzedObject.decision)
                {
                    color = System.Drawing.Color.Yellow;
                }
                else
                {
                    color = convertColor(analyzedObject.color);
                }

                //A circle with Red Color and 2 Pixel wide line
                rects.Add(new RectWithColor
                {
                    Rectangle = new Rectangle(scalex1, scaley1, scalex2 - scalex1, scaley2 - scaley1),
                    Pen = new Pen(color, 2)
                });
            }
            st.Stop();
            pictureBox1.Invalidate();
            textBox1.Text = string.Format("Analyze took {0} ms. Found {1} objects ({2} traffic lights)",
                st.ElapsedMilliseconds, analyzedObjects.Count, analyzedObjects.Where(x => x.decision == true).Count());
        }