Esempio n. 1
0
        /// <summary>
        /// Reason : To get Image details from uploaded image
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnProcess_Click(object sender, EventArgs e)
        {
            try
            {
                if (!IsMediaFile(txtFilePath.Text.ToString().Trim(), imageExtensions))
                {
                    MessageBox.Show("Please select valid Image file!!");
                    return;
                }

                DisposeControls();
                ShowLoader();
                pbImage.BringToFront();
                string imagePath    = txtFilePath.Text.ToString();
                string imageContent = new ImageVideoProcessing.ImageGrabber().ExtractTextFromImage(imagePath);
                txtResult.Text = string.IsNullOrEmpty(imageContent) ? "There is no text found in Image" : imageContent;
                txtColors.Text = "\tImage contains following major colors: " + ParseColorList(new ImageVideoProcessing.ImageGrabber().GetImageColors(imagePath));

                Cursor.Current = Cursors.AppStarting;
                HideLoader();
            }
            catch (Exception)
            {
            }
        }
        /// <summary>
        /// Get and save metadata of file
        /// </summary>
        /// <param name="filePath"></param>
        /// <param name="appStartPath"></param>
        public void SaveMetadataOfImage(string filePath, string appStartPath)
        {
            try
            {
                _blobWrapper   = new DataUpload();
                _faceDetection = new FaceDetection(appStartPath);
                _imgGrabber    = new ImageGrabber();
                List <DataLayer.EntityModel.Image> imageList = new List <DataLayer.EntityModel.Image>();
                String[] files = new string[1];
                files[0] = filePath;
                List <string> fileNameList = new List <string>();
                fileNameList = GetUniqueImages(files.ToList());

                foreach (var fileObj in fileNameList)
                {
                    //Get metadata of file and save it
                    imageList.Add(GetImageMetadata(fileObj, appStartPath));
                    //Upload file to file to azure blob
                    _blobWrapper.UploadFile(fileObj);
                }

                new DataLayer.ModelClasses.Image().SaveUpdateMetadata(imageList);
            }
            catch (Exception)
            {
                throw;
            }
        }
        /// <summary>
        /// Get and save metadata of all files from input folder
        /// </summary>
        /// <param name="folderPath"></param>
        /// <param name="appStartPath"></param>
        public void SaveMetadataOfAllImages(string folderPath, string appStartPath)
        {
            try
            {
                _blobWrapper   = new DataUpload();
                _faceDetection = new FaceDetection(appStartPath);
                _imgGrabber    = new ImageGrabber();
                DirectoryInfo directory = new DirectoryInfo(folderPath);
                List <DataLayer.EntityModel.Image> imageList = new List <DataLayer.EntityModel.Image>();
                String[]      files        = GetFilesFrom(folderPath, imageFilters, true);
                List <string> fileNameList = new List <string>();
                fileNameList = GetUniqueImages(files.ToList());

                foreach (var fileObj in fileNameList)
                {
                    //Get metadata of file and save it
                    imageList.Add(GetImageMetadata(fileObj, appStartPath));
                    //Upload file to file to azure blob
                    _blobWrapper.UploadFile(fileObj);
                }

                new DataLayer.ModelClasses.Image().SaveUpdateMetadata(imageList);
            }
            catch (Exception ex)
            {
                throw;
            }
        }
        /// <summary>
        /// Reason : To get Image details from uploaded image
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnProcess_Click(object sender, EventArgs e)
        {
            if (!IsMediaFile(txtFilePath.Text.ToString().Trim(), imageExtensions))
            {
                MessageBox.Show("Please select valid Image file!!");
                return;
            }

            DisposeControls();
            ShowLoader();
            pbImage.BringToFront();
            string imagePath = txtFilePath.Text.ToString();
            string imageContent = new ImageVideoProcessing.ImageGrabber().ExtractTextFromImage(imagePath);
            txtResult.Text = string.IsNullOrEmpty(imageContent) ? "There is no text found in Image" : imageContent;
            txtColors.Text = "\tImage contains following major colors: " + ParseColorList(new ImageVideoProcessing.ImageGrabber().GetImageColors(imagePath));

            Cursor.Current = Cursors.AppStarting;
            HideLoader();
        }
        /// <summary>
        /// Reason : To get all similar files from folder with percentage of similarity for selected file.
        /// compare files from folder which are having length of file +- 100000 of original file.
        /// </summary>
        /// <param name="inputFilePath">Input file path of image</param>
        /// <param name="length">Length of image file that varies to compare with another file</param>
        /// <param name="percentageString"> returns percentage of similarities of matched images in string seperated by comma(,)</param>
        public void GetAllSimilarImages(string inputFilePath, string appStartPath, double length, ref List <DuplicateImageDetails> duplicateImageList)
        {
            {
                try
                {
                    if (!File.Exists(inputFilePath))
                    {
                        return;
                    }

                    DuplicateImageDetails imgOriginalFile = new DuplicateImageDetails();
                    imgOriginalFile.FilePath   = inputFilePath;
                    imgOriginalFile.FileName   = inputFilePath.Contains("\\") ? inputFilePath.Split('\\')[inputFilePath.Split('\\').Count() - 1] : inputFilePath;
                    imgOriginalFile.Percentage = "Original Selected File";
                    duplicateImageList.Add(imgOriginalFile);

                    int      count    = 0;
                    FileInfo fileInfo = new FileInfo(inputFilePath);
                    DataLayer.EntityModel.Image metadataInputImgObj = new DataLayer.EntityModel.Image();
                    //Get metadata of input file
                    _faceDetection      = new FaceDetection(appStartPath);
                    _imgGrabber         = new ImageGrabber();
                    metadataInputImgObj = GetImageMetadata(inputFilePath, appStartPath);

                    var bestMatchImageList = new DataLayer.ModelClasses.Image().GetImagesByBestMatch(metadataInputImgObj);
                    // for Image similarity percentage need to compare both images
                    foreach (var infoObj in bestMatchImageList)
                    {
                        DuplicateImageDetails duplicateImageCheck = new DuplicateImageDetails();
                        duplicateImageCheck.FilePath   = infoObj.ImagePath;
                        duplicateImageCheck.FileName   = infoObj.ImagePath.Contains("\\") ? infoObj.ImagePath.Split('\\')[infoObj.ImagePath.Split('\\').Count() - 1] : infoObj.ImagePath;
                        duplicateImageCheck.Percentage = "";
                        duplicateImageList.Add(duplicateImageCheck);
                        count++;
                    }
                }
                catch (Exception)
                {
                }
            }
        }
        /// <summary>
        /// Reason : To get all similar files from folder with percentage of similarity for selected file.
        /// compare files from folder which are having length of file +- 100000 of original file.
        /// </summary>
        /// <param name="inputFilePath">Input file path of image</param>
        /// <param name="length">Length of image file that varies to compare with another file</param>
        /// <param name="percentageString"> returns percentage of similarities of matched images in string seperated by comma(,)</param>
        public void GetAllSimilarImages(string inputFilePath,string appStartPath, double length, ref List<DuplicateImageDetails> duplicateImageList)
        {
            {
                try
                {
                    DuplicateImageDetails imgOriginalFile = new DuplicateImageDetails();
                    imgOriginalFile.FilePath = inputFilePath;
                    imgOriginalFile.FileName = inputFilePath.Contains("\\") ? inputFilePath.Split('\\')[inputFilePath.Split('\\').Count() - 1] : inputFilePath;
                    imgOriginalFile.Percentage = "Original Selected File";
                    duplicateImageList.Add(imgOriginalFile);

                    int count = 0;
                    FileInfo fileInfo = new FileInfo(inputFilePath);
                    DataLayer.EntityModel.Image metadataInputImgObj = new DataLayer.EntityModel.Image();
                    //Get metadata of input file
                    _faceDetection = new FaceDetection(appStartPath);
                    _imgGrabber = new ImageGrabber();
                    metadataInputImgObj = GetImageMetadata(inputFilePath, appStartPath);

                    var bestMatchImageList = new DataLayer.ModelClasses.Image().GetImagesByBestMatch(metadataInputImgObj);
                    // for Image similarity percentage need to compare both images
                    foreach (var infoObj in bestMatchImageList)
                    {
                        DuplicateImageDetails duplicateImageCheck = new DuplicateImageDetails();
                        duplicateImageCheck.FilePath = infoObj.ImagePath;
                        duplicateImageCheck.FileName = infoObj.ImagePath.Contains("\\") ? infoObj.ImagePath.Split('\\')[infoObj.ImagePath.Split('\\').Count() - 1] : infoObj.ImagePath;
                        duplicateImageCheck.Percentage = "";
                        duplicateImageList.Add(duplicateImageCheck);
                        count++;
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
        }
        /// <summary>
        /// Get and save metadata of file
        /// </summary>
        /// <param name="filePath"></param>
        /// <param name="appStartPath"></param>
        public void SaveMetadataOfImage(string filePath, string appStartPath)
        {
            try
            {
                _blobWrapper = new DataUpload();
                _faceDetection = new FaceDetection(appStartPath);
                _imgGrabber = new ImageGrabber();
                List<DataLayer.EntityModel.Image> imageList = new List<DataLayer.EntityModel.Image>();
                String[] files = new string[1];
                files[0] = filePath;
                List<string> fileNameList = new List<string>();
                fileNameList = GetUniqueImages(files.ToList());

                foreach (var fileObj in fileNameList)
                {
                    //Get metadata of file and save it
                    imageList.Add(GetImageMetadata(fileObj, appStartPath));
                    //Upload file to file to azure blob
                    _blobWrapper.UploadFile(fileObj);
                }

                new DataLayer.ModelClasses.Image().SaveUpdateMetadata(imageList);
            }
            catch (Exception)
            {
                throw;
            }
        }
        /// <summary>
        /// Get and save metadata of all files from input folder
        /// </summary>
        /// <param name="folderPath"></param>
        /// <param name="appStartPath"></param>
        public void SaveMetadataOfAllImages(string folderPath, string appStartPath)
        {
            try
            {
                _blobWrapper = new DataUpload();
                _faceDetection = new FaceDetection(appStartPath);
                _imgGrabber = new ImageGrabber();
                DirectoryInfo directory = new DirectoryInfo(folderPath);
                List<DataLayer.EntityModel.Image> imageList = new List<DataLayer.EntityModel.Image>();
                String[] files =  GetFilesFrom(folderPath, imageFilters,true);
                List<string> fileNameList = new List<string>();
                fileNameList = GetUniqueImages(files.ToList());

                foreach (var fileObj in fileNameList)
                {
                    //Get metadata of file and save it
                    imageList.Add(GetImageMetadata(fileObj, appStartPath));
                    //Upload file to file to azure blob
                    _blobWrapper.UploadFile(fileObj);
                }

                new DataLayer.ModelClasses.Image().SaveUpdateMetadata(imageList);
            }
            catch (Exception ex)
            {
                throw;
            }
        }