示例#1
0
        private void button2_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog fbd = new FolderBrowserDialog();

            DialogResult result = fbd.ShowDialog();

            if (result != DialogResult.OK)
            {
                return;
            }

            DirectoryInfo d = new DirectoryInfo(fbd.SelectedPath);

            foreach (var file in d.GetFiles("*.jpg"))
            {
                Bitmap bmp = new Bitmap(file.FullName);

                //Make 32 bit ARGB bitmap
                Bitmap clone = new Bitmap(bmp.Width, bmp.Height,
                                          System.Drawing.Imaging.PixelFormat.Format32bppArgb);

                using (Graphics gr = Graphics.FromImage(clone))
                {
                    gr.DrawImage(bmp, new Rectangle(0, 0, clone.Width, clone.Height));
                }

                List <int> features         = FeatureDetector.featuresFromBitmap(clone);
                int        tempMatchingBins = 0;
                bool       compare_result   = FeatureDetector.compareFeatureVector(features.ToArray(), out tempMatchingBins);

                Console.WriteLine("RESULT: " + tempMatchingBins + " matching bins, compare == " + compare_result);


                if (tempMatchingBins < FeatureDetector.numberOfBinsCorrect)
                {
                    currentRecordCount++;
                    listOfFeatureVectors.Add(features);
                    clone.Save(currentRecordCount.ToString() + ".jpg");
                }



                bmp.Dispose();
                clone.Dispose();
            }

            System.IO.Directory.CreateDirectory(DiagnosticsFolderName);
            using (var feature_file = File.CreateText(DiagnosticsFolderName + "loading_eng_features.txt"))
            {
                feature_file.Write("private int[,] listOfFeatureVectorsEng = {\n");
                foreach (var list in listOfFeatureVectors)
                {
                    feature_file.Write("{");
                    feature_file.Write(string.Join(",", list));
                    feature_file.Write("},\n");
                }

                feature_file.Write("};\n");
            }
        }
示例#2
0
        private void DrawPreview()
        {
            ImageCaptureInfo copy = imageCaptureInfo;

            copy.captureSizeX = previewPictureBox.Width;
            copy.captureSizeY = previewPictureBox.Height;

            //Show something in the preview
            previewImage = CaptureImageFullPreview(ref copy);
            float crop_size_x = copy.actual_crop_size_x;
            float crop_size_y = copy.actual_crop_size_y;


            //Draw selection rectangle
            DrawCaptureRectangleBitmap();



            //Compute image crop coordinates according to selection rectangle

            //Get raw image size from imageCaptureInfo.actual_crop_size to compute scaling between raw and rectangle coordinates

            //Console.WriteLine("SIZE X: {0}, SIZE Y: {1}", imageCaptureInfo.actual_crop_size_x, imageCaptureInfo.actual_crop_size_y);

            imageCaptureInfo.crop_coordinate_left   = selectionRectanglePreviewBox.Left * (crop_size_x / previewPictureBox.Width);
            imageCaptureInfo.crop_coordinate_right  = selectionRectanglePreviewBox.Right * (crop_size_x / previewPictureBox.Width);
            imageCaptureInfo.crop_coordinate_top    = selectionRectanglePreviewBox.Top * (crop_size_y / previewPictureBox.Height);
            imageCaptureInfo.crop_coordinate_bottom = selectionRectanglePreviewBox.Bottom * (crop_size_y / previewPictureBox.Height);

            copy.crop_coordinate_left   = selectionRectanglePreviewBox.Left * (crop_size_x / previewPictureBox.Width);
            copy.crop_coordinate_right  = selectionRectanglePreviewBox.Right * (crop_size_x / previewPictureBox.Width);
            copy.crop_coordinate_top    = selectionRectanglePreviewBox.Top * (crop_size_y / previewPictureBox.Height);
            copy.crop_coordinate_bottom = selectionRectanglePreviewBox.Bottom * (crop_size_y / previewPictureBox.Height);



            croppedPreviewPictureBox.Image = CaptureImageFullPreview(ref copy, useCrop: true);


            copy.captureSizeX = captureSize.Width;
            copy.captureSizeY = captureSize.Height;

            //Show matching bins for preview
            var capture          = CaptureImage();
            var features         = FeatureDetector.featuresFromBitmap(capture);
            int tempMatchingBins = 0;
            var isLoading        = FeatureDetector.compareFeatureVector(features.ToArray(), out tempMatchingBins, false);

            matchDisplayLabel.Text = tempMatchingBins.ToString();
        }
示例#3
0
        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            DialogResult result = ofd.ShowDialog();

            if (result != DialogResult.OK)
            {
                return;
            }

            Bitmap bmp = new Bitmap(ofd.FileName);

            //Make 32 bit ARGB bitmap
            Bitmap clone = new Bitmap(bmp.Width, bmp.Height,
                                      System.Drawing.Imaging.PixelFormat.Format32bppArgb);

            using (Graphics gr = Graphics.FromImage(clone))
            {
                gr.DrawImage(bmp, new Rectangle(0, 0, clone.Width, clone.Height));
            }

            List <int> features = FeatureDetector.featuresFromBitmap(clone);

            bool compare_result = FeatureDetector.compareFeatureVector(features.ToArray(), out matchingBins);

            Console.WriteLine("RESULT: " + matchingBins + " matching bins, compare == " + compare_result);



            currentRecordCount++;
            listOfFeatureVectors.Add(features);

            System.IO.Directory.CreateDirectory(DiagnosticsFolderName);
            using (var file = File.CreateText(DiagnosticsFolderName + "loading_eng_features.txt"))
            {
                file.Write("private int[,] listOfFeatureVectorsEng = {\n");
                foreach (var list in listOfFeatureVectors)
                {
                    file.Write("{");
                    file.Write(string.Join(",", list));
                    file.Write("},\n");
                }

                file.Write("};\n");
            }

            bmp.Dispose();
            clone.Dispose();
        }
示例#4
0
        private List <int> featuresAtScreenCenter()
        {
            try
            {
                Stopwatch stopwatch = Stopwatch.StartNew();
                Bitmap    bmp       = null;



                bmp = CaptureImage();

                List <int> features = FeatureDetector.featuresFromBitmap(bmp);


                lastFeatures = features;
                int  tempMatchingBins   = 0;
                bool matchingHistograms = FeatureDetector.compareFeatureVector(features.ToArray(), out tempMatchingBins, true);

                currentlyPaused = matchingHistograms;

                HistogramOfMatchingBins[tempMatchingBins]++;
                if (snapshotMilliseconds <= 0)
                {
                    snapshotMilliseconds = milliSecondsBetweenSnapshots;

                    snapshotFrameCount = frameCount;

                    segmentSnapshots.Add(bmp);
                    segmentMatchingBins.Add(tempMatchingBins);
                    segmentFeatureVectors.Add(features);
                    segmentFrameCounts.Add(frameCount);
                }


                stopwatch.Stop();

                msElapsed.Add(stopwatch.ElapsedMilliseconds);
                if (msElapsed.Count > 20)
                {
                    long sum = 0;

                    foreach (var ms in msElapsed)
                    {
                        sum += ms;
                    }
                    sum /= msElapsed.Count;
                    msElapsed.Clear();
                    Console.WriteLine("DetectMatch (avg): " + sum + "ms");
                }

                if (tempMatchingBins >= 250 && tempMatchingBins <= 420 && saveDiagnosticImages)
                {
                    System.IO.Directory.CreateDirectory(DiagnosticsFolderName + "imgs_features_interesting");

                    try
                    {
                        bmp.Save(DiagnosticsFolderName + "imgs_features_interesting/img_" + frameCount + "_" + tempMatchingBins + ".jpg", ImageFormat.Jpeg);
                    }
                    catch
                    {
                    }

                    saveFeatureVectorToTxt(features, "features_" + frameCount + "_" + tempMatchingBins + ".txt", DiagnosticsFolderName + "imgs_features_interesting");

                    //lastSaveFrame = frameCount;
                }


                if (currentlyPaused)
                {
                    //only save if we haven't saved for at least 10 frames, just for diagnostics to see if any false positives are in there.
                    //or if we haven't seen a paused frame for at least 30 frames.
                    if ((frameCount > (lastSaveFrame + 10) || (frameCount - lastPausedFrame) > 30) && saveDiagnosticImages && false)
                    {
                        System.IO.Directory.CreateDirectory(DiagnosticsFolderName + "imgs_stopped");

                        try
                        {
                            bmp.Save(DiagnosticsFolderName + "imgs_stopped/img_" + frameCount + "_" + tempMatchingBins + ".jpg", ImageFormat.Jpeg);
                        }
                        catch
                        {
                        }

                        saveFeatureVectorToTxt(features, "features_" + frameCount + "_" + tempMatchingBins + ".txt", DiagnosticsFolderName + "features_stopped");

                        lastSaveFrame = frameCount;
                    }

                    lastPausedFrame = frameCount;
                }
                else
                {
                    //save if we haven't seen a running frame for at least 30 frames (to detect false runs - e.g. aku covering "loading"
                    if ((frameCount - lastRunningFrame) > 10 && saveDiagnosticImages && false)
                    {
                        System.IO.Directory.CreateDirectory(DiagnosticsFolderName + "imgs_running");
                        try
                        {
                            bmp.Save(DiagnosticsFolderName + "imgs_running/img_" + frameCount + "_" + tempMatchingBins + ".jpg", ImageFormat.Jpeg);
                        }
                        catch
                        {
                        }

                        saveFeatureVectorToTxt(features, "features_" + frameCount + "_" + tempMatchingBins + ".txt", DiagnosticsFolderName + "features_running");

                        lastSaveFrame = frameCount;
                    }
                    lastRunningFrame = frameCount;
                }

                frameCount++;
                //histogramMatches.Add(matchingHistograms);
                try
                {
                    Invoke(new Action(() =>
                    {
                        try
                        {
                            imageDisplay.Image           = bmp;
                            imageDisplay.Size            = new Size(captureSize.Width, captureSize.Height);
                            imageDisplay.BackgroundImage = bmp;
                            imageDisplay.Refresh();
                            matchDisplayLabel.Text = tempMatchingBins.ToString();
                            //requiredMatchesTxt.Text = numberOfBinsCorrect.ToString();
                            if (matchingHistograms)
                            {
                                //paused
                                pausedDisplay.BackColor = Color.Red;
                            }
                            else
                            {
                                //running
                                pausedDisplay.BackColor = Color.Green;
                            }
                        }
                        catch
                        {
                        }
                    }));
                }
                catch
                {
                    //if the form is closing, we just do nothing.
                }
                matchingBins = tempMatchingBins;
                return(features);
            }
            catch (Exception ex)
            {
                Console.WriteLine("TESTESTESTEST");
                return(new List <int>());
            }
            //bmp.Dispose();
        }