/// <summary> /// To get metadata of image /// </summary> /// <param name="imagePath"></param> /// <param name="appStartPath"></param> /// <returns>DataLayer.EntityModel.Image</returns> public DataLayer.EntityModel.Image GetImageMetadata(string imagePath, string appStartPath) { int height = 0, width = 0, RedPercentage = 0, BluePercentage = 0, GreenPercentage = 0; long length = 0; DataLayer.EntityModel.Image imageObj = new DataLayer.EntityModel.Image(); //to get checksum string checksume = GetChecksumMD5(imagePath); //to get no of faces from image int noOfFaces = _faceDetection.GetNoOfFacesFromImage(appStartPath, imagePath); //to get metadata _imgGrabber.GetImageMetadata(imagePath, ref height, ref width, ref length, ref RedPercentage, ref BluePercentage, ref GreenPercentage); //to check image contains text or not string imageContent = _imgGrabber.ExtractTextFromImage(imagePath); imageContent = string.IsNullOrEmpty(imageContent) ? imageContent : imageContent.Replace("\r\n", ""); imageObj.RedPercentage = RedPercentage; imageObj.GreenPercentage = GreenPercentage; imageObj.BluePercentage = BluePercentage; imageObj.Checksum = checksume; imageObj.Height = height; imageObj.Width = width; imageObj.ImagePath = imagePath; imageObj.IsImageContainsFace = noOfFaces > 0 ? true : false; imageObj.IsImageContainsText = imageContent.Length > 0 ? true : false; imageObj.Length = length; imageObj.Name = imagePath.Contains("\\") ? imagePath.Split('\\')[imagePath.Split('\\').Count() - 1] : imagePath; imageObj.FaceCount = noOfFaces; imageObj.CreatedDatetime = DateTime.Now; imageObj.IsDeleted = false; imageObj.Description = imageContent; return(imageObj); }
/// <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> /// To get metadata of image /// </summary> /// <param name="imagePath"></param> /// <param name="appStartPath"></param> /// <returns>DataLayer.EntityModel.Image</returns> public DataLayer.EntityModel.Image GetImageMetadata(string imagePath, string appStartPath) { int height = 0, width = 0, RedPercentage = 0, BluePercentage = 0, GreenPercentage = 0; long length = 0; DataLayer.EntityModel.Image imageObj = new DataLayer.EntityModel.Image(); //to get checksum string checksume = GetChecksumMD5(imagePath); //to get no of faces from image int noOfFaces = _faceDetection.GetNoOfFacesFromImage(appStartPath, imagePath); //to get metadata _imgGrabber.GetImageMetadata(imagePath, ref height, ref width, ref length, ref RedPercentage, ref BluePercentage, ref GreenPercentage); //to check image contains text or not string imageContent = _imgGrabber.ExtractTextFromImage(imagePath); imageContent = string.IsNullOrEmpty(imageContent) ? imageContent : imageContent.Replace("\r\n", ""); imageObj.RedPercentage = RedPercentage; imageObj.GreenPercentage = GreenPercentage; imageObj.BluePercentage = BluePercentage; imageObj.Checksum = checksume; imageObj.Height = height; imageObj.Width = width; imageObj.ImagePath = imagePath; imageObj.IsImageContainsFace = noOfFaces > 0 ? true : false; imageObj.IsImageContainsText = imageContent.Length > 0 ? true : false; imageObj.Length = length; imageObj.Name = imagePath.Contains("\\") ? imagePath.Split('\\')[imagePath.Split('\\').Count() - 1] : imagePath; imageObj.FaceCount = noOfFaces; imageObj.CreatedDatetime = DateTime.Now; imageObj.IsDeleted = false; imageObj.Description = imageContent; return imageObj; }