Inheritance: SQLiteDB
Example #1
0
        private void cmdGetMore_KeyPress(object sender, KeyPressEventArgs e)
        {
            //I think this only makes sence to use in Decades mode.
            if (radioYears.Checked)
            {
                return;
            }

            if (!radioDates.Checked)
            {
                return;
            }


            if (groupBoxImages.Controls.Count == 0)
            {
                return;
            }

            int numberKeyed;


            if (!int.TryParse(e.KeyChar.ToString(), out numberKeyed))
            {
                if (e.KeyChar.ToString() == ".")
                {
                    numberKeyed = -1;
                }
                else
                {
                    return;
                }
            }

            int date;

            if (listBoxWorkingLabel.SelectedItem.ToString() == "No Label")
            {
                date = numberKeyed * 10;
            }
            else
            {
                int selectedDate;
                int.TryParse(listBoxWorkingLabel.SelectedItem.ToString(), out selectedDate);
                date = selectedDate + numberKeyed;
            }

            if (numberKeyed == -1)
            {
                date = 0;
            }

            PictureBox pictureBox = (PictureBox)groupBoxImages.Controls[0];
            int        imageID;
            String     tag = pictureBox.Tag.ToString();

            int.TryParse(tag.Substring(tag.Length - 12, 8), out imageID);
            groupBoxImages.Controls.Remove(pictureBox);
            ImagesDB.UpdateDate(imageID, date);
        }
Example #2
0
        public frmMain()
        {
            InitializeComponent();
            _spManager = new SerialPortManager();
            _spManager.NewSerialDataRecieved += new EventHandler <SerialDataEventArgs>(_spManager_NewSerialDataRecieved);

            var di           = new DirectoryInfo("F:/OpenCV/Raw/");
            var lastFileName = di.GetFiles()
                               .OrderByDescending(f => f.Name)
                               .First();

            IRSensorCount = ImagesDB.GetImageIDFromFileName(lastFileName.Name);
        }
Example #3
0
        private void ImageRefresh(bool newimageIDs)
        {
            int date = GetDateFromLabel(listBoxWorkingLabel.SelectedItem.ToString());

            if (newimageIDs)
            {
                images = ImagesDB.GetDateImages(date, chkLabeled.Checked, radioDecades.Checked);
            }



            groupBoxImages.Controls.Clear();
            int imageSize = 64;

            for (int y = 0; y < 800; y = y + imageSize + 10)
            {
                for (int x = 0; x < 800; x = x + imageSize + 10)
                {
                    if (images.Count == 0)
                    {
                        return;
                    }
                    int    imageID  = images.Keys.First();
                    double angle    = images.Values.First();
                    String fileName = "F:/OpenCV/Crops/good/" + imageID + ".jpg";
                    images.Remove(imageID);
                    PictureBox pictureBox = new PictureBox();
                    pictureBox.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
                    pictureBox.Tag = fileName;
                    Bitmap    rotated  = CloneImage(fileName, angle);
                    Rectangle cropRect = new Rectangle(307, 250, imageSize, imageSize);
                    rotated = rotated.Clone(cropRect, rotated.PixelFormat);
                    pictureBox.BackgroundImage = rotated;
                    pictureBox.Height          = imageSize;
                    pictureBox.Width           = imageSize;
                    pictureBox.Left            = x;
                    pictureBox.Top             = y + 10;
                    pictureBox.Click          += new EventHandler(pictureBox_Click);
                    pictureBox.Paint          += new PaintEventHandler((sender, e) =>
                    {
                        e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
                        e.Graphics.DrawString(imageID.ToString(), Font, Brushes.Blue, 3, 3);
                    });
                    groupBoxImages.Controls.Add(pictureBox);
                }
            }
        }
Example #4
0
        private void HandlePictureBoxLeftClick(PictureBox pictureBox, bool allShown, bool skipCommand)
        {
            int    imageID;
            String tag = pictureBox.Tag.ToString();

            int.TryParse(tag.Substring(tag.Length - 12, 8), out imageID);

            groupBoxImages.Controls.Remove(pictureBox);
            if (skipCommand)
            {
                return;
            }


            String selectedCommand;

            if (allShown)
            {
                selectedCommand = listBoxLabelAllShown.SelectedItem.ToString();
            }
            else
            {
                selectedCommand = listBoxClickList.SelectedItem.ToString();
            }

            if (selectedCommand == "Delete")
            {
                //File.Delete(label);
            }
            else
            {
                if (radioDates.Checked)
                {
                    int date;
                    int.TryParse(selectedCommand, out date);
                    if (radioDecades.Checked)
                    {
                        date = date - 1900;
                    }
                    if (selectedCommand == "No Label")
                    {
                        date = -1;
                    }
                    ImagesDB.UpdateDate(imageID, date);
                }
            }
        }
Example #5
0
        public void ClassifyFiles(String oldImageDirectory, String newImageDirectory, String modelDir, bool toClassify, bool addImagesToDataBase, bool moveImage, bool includeSubDir)
        {
            string[] files;
            if (includeSubDir)
            {
                files = Directory.GetFiles(oldImageDirectory, "*.jpg*", SearchOption.AllDirectories);
            }
            else
            {
                files = Directory.GetFiles(oldImageDirectory, "*.jpg*");
            }

            List <ImageResult>    imageResults = new List <ImageResult>();
            Dictionary <int, int> images       = new Dictionary <int, int>();

            foreach (string image_file in files)
            {
                int imageID = Convert.ToInt32(image_file.Substring(image_file.Length - 12, 8));

                if (toClassify)
                {
                    IntPtr ptr = ClassifyImage(modelDir, image_file);
                    //the output result should be a structure, it's hard coded for now:
                    double[] result = new double[8];
                    Marshal.Copy(ptr, result, 0, 8);
                    ReleaseMemory(ptr);
                    imageResults.Add(new ImageResult(imageID, result));

                    if (moveImage)
                    {
                        FileInfo fi = new FileInfo(image_file);
                        String   imageFileDestination = newImageDirectory + "/" + LabelsDB.GetLabel((int)result[0]) + "/" + fi.Name;
                        File.Move(image_file, imageFileDestination);
                    }
                }
            }
            if (addImagesToDataBase)
            {
                ImagesDB.AddImages(imageResults);
            }
        }
Example #6
0
        private void PictureBoxCoin_Click(object sender, EventArgs e)
        {
            MouseEventArgs clickArg = (MouseEventArgs)e;
            float          offsetX  = Convert.ToInt32(PictureBoxCoin.Width / 2);
            float          offsetY  = Convert.ToInt32(PictureBoxCoin.Height / 2);
            float          clickX   = clickArg.X - offsetX;
            float          clickY   = (PictureBoxCoin.Height - clickArg.Y) - offsetY;
            float          coinAngle;

            coinAngle = (Convert.ToSingle(Math.Atan2(clickY, clickX) / Math.PI) * 180);

            if (clickArg.Button == System.Windows.Forms.MouseButtons.Left)
            {
                dynamic distanceFromCenter = Math.Sqrt(clickX * clickX + clickY * clickY);
                coinAngle = coinAngle - 3;
            }

            Console.WriteLine("angle: " + coinAngle + "  Y:  " + clickY);

            coinAngle = coinAngle + 180;

            if (coinAngle > 360)
            {
                coinAngle = coinAngle - 360;
            }

            if (coinAngle < 0)
            {
                coinAngle = coinAngle + 360;
            }

            int imageID = Convert.ToInt32(CoinFileName.Substring(CoinFileName.Length - 12, 8));

            ImagesDB.UpdateAngle(imageID, coinAngle);
            LoadNextPicture();
        }
Example #7
0
 private void cmdCropDates_Click(object sender, EventArgs e)
 {
     ImagesDB.CropForDates(txtImageDirectory.Text, chkAugment.Checked);
 }
Example #8
0
 private void cmdAugment_Click(object sender, EventArgs e)
 {
     ImagesDB.AugmentImages(txtImageDirectory.Text, Int32.Parse(txtNumberOfRotations.Text));
 }