public void InspectAndUpdatePhoto(Photo photo, string categoryName)
        {
            //Fetch Exif Information
            photo.PhotoDetails.AddRange(ExifInspector.GetInfo(photo.SourceFilePath));

            try
            {
                string mosModel = Properties.Settings.Default.MOSModel;
                PhotoResult photoQualityResult = this.PhotoQualityInspector.AnalyzePhoto(photo.SourceFilePath, categoryName, Properties.Settings.Default.MOSModel, false);
                if (photoQualityResult != null)
                {
                    //Fetch the  photo details
                    foreach (VQHelper.Parameter parameter in photoQualityResult.PhotoDetails)
                    {
                        PhotoDetail photoDetail = new PhotoDetail();
                        photoDetail.ParameterName = parameter.ParameterName;
                        photoDetail.Value = parameter.Value < 0 ? Double.NaN: Math.Round(parameter.Value, 2);
                        photoDetail.ValueString = Properties.Resources.NA;
                        photoDetail.DisplayPreference = parameter.DisplayPreference;
                        photo.PhotoDetails.Add(photoDetail);
                    }

                    //Fetch visualization images
                    foreach (VQHelper.VisualizationImage parameter in photoQualityResult.VisualizationImages)
                    {
                        VisualizationImage visualizationImage = new VisualizationImage();
                        visualizationImage.Visualization = parameter.Visualization;
                        visualizationImage.FilePath = parameter.FilePath;
                        photo.VisualizationImages.Add(visualizationImage);
                    }
                }
            }
            catch (Exception exception)
            {
                MessageBox.Show(Properties.Resources.ExceptionDetails + " " + exception.ToString(), Properties.Resources.PhotoProcessingError);
            }
        }
Exemple #2
0
        public void AddPhoto(string filepath)
        {
            if (File.Exists(filepath))
            {
                //Copy file to data folder
                string fileName = Path.GetFileNameWithoutExtension(filepath);
                string fileExtension = Path.GetExtension(filepath);
                string localFilePath = null;
                int appendNumber = -1;
                do
                {
                    appendNumber++;
                    localFilePath = Path.Combine(this.photoDirectory, fileName + appendNumber + fileExtension);
                }
                while(File.Exists(localFilePath));
                File.Copy(filepath,localFilePath);

                //Add file to photoList
                Photo photo = new Photo();
                photo.Filename = fileName + fileExtension;
                photo.SourceFilePath = localFilePath;
                this.photoList.Add(photo);
            }
        }
 private PhotoListViewItem CreatePhotoListViewItem(Photo photo, bool enabled)
         {
             PhotoListViewItem photoListViewItem = new PhotoListViewItem();
             photoListViewItem.Photo = photo;
             photoListViewItem.Filename = photo.Filename;
             photoListViewItem.Thumbnail = FetchImage(photo.SourceFilePath, 100);
             photoListViewItem.Enabled = enabled;
             photoListViewItem.Spinning = ProgressRing.OFF;
             return photoListViewItem;
         }
        public async Task <bool> Analyze(ObservableCollection <CategoryListViewItem> categoryListViewItems, String deviceName, CancellationToken cancellationToken)
        {
            //Delete the Temp Folder
            Directory.Delete(Constants.TempDirectory, true);

            PhotoInspector photoInspector = new PhotoInspector();

            for (int categoryIndex = 0; categoryIndex < categoryListViewItems.Count; categoryIndex++)
            {
                if (cancellationToken.IsCancellationRequested)
                {
                    break;
                }
                Category category = new Category();
                category.Name = categoryListViewItems[categoryIndex].Name;

                //Expand the category
                CategoryListViewItem newItem = new CategoryListViewItem();
                newItem.Name = categoryListViewItems[categoryIndex].Name;
                newItem.PhotoListViewItems           = categoryListViewItems[categoryIndex].PhotoListViewItems;
                newItem.IsExpanded                   = true;
                categoryListViewItems[categoryIndex] = newItem;

                //Using for loop instead of foreach because we edit the listview
                for (int index = 0; index < categoryListViewItems[categoryIndex].PhotoListViewItems.Count; index++)
                {
                    MarkPhotoAsBusy(categoryListViewItems[categoryIndex], index);

                    Task analysisTask = new Task(() =>
                    {
                        Photo photo         = categoryListViewItems[categoryIndex].PhotoListViewItems[index].Photo;
                        string categoryName = categoryListViewItems[categoryIndex].Name;

                        //Check if the photo has been analyzed before
                        if (photo.PhotoDetails.Count == 0)
                        {
                            photoInspector.InspectAndUpdatePhoto(photo, categoryName);
                        }
                    });

                    analysisTask.Start();
                    await analysisTask;

                    MarkPhotoAsCompleted(categoryListViewItems[categoryIndex], index);

                    if (cancellationToken.IsCancellationRequested)
                    {
                        break;
                    }
                }

                //Collapse the category
                newItem      = new CategoryListViewItem();
                newItem.Name = categoryListViewItems[categoryIndex].Name;
                newItem.PhotoListViewItems           = categoryListViewItems[categoryIndex].PhotoListViewItems;
                newItem.IsExpanded                   = false;
                categoryListViewItems[categoryIndex] = newItem;

                if (cancellationToken.IsCancellationRequested)
                {
                    break;
                }
            }

            if (!cancellationToken.IsCancellationRequested)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
        private void AddPhotos_Click(object sender, RoutedEventArgs e)
        {
            Button buttonClicked = sender as Button;

            StackPanel parentStackPanel = buttonClicked.Parent as StackPanel;
            Grid parentGrid = parentStackPanel.Parent as Grid;
            TextBlock categoryName = parentGrid.FindName("CategoryName") as TextBlock;
            string inputCategoryName = categoryName.Text;

            //Display Open File Dialog
            OpenFileDialog openFileDialog = new OpenFileDialog();
            openFileDialog.Title = "Add a photo";
            openFileDialog.Filter = "Picture Files (*.jpg, *.bmp, *.png) |*.jpg;*.bmp;*.png |All Files (*.*)|*.*";
            openFileDialog.Multiselect = true;
            Nullable<bool> fileOpenResult = openFileDialog.ShowDialog();

            //Add Files to PhotoFetcher
            if (fileOpenResult == true)
            {
                string[] filenames = openFileDialog.FileNames;

                RemovePlaceHolders(inputCategoryName);

                for (int fileIndex = 0; fileIndex < filenames.Length; fileIndex++)
                {
                    Photo photo = new Photo();
                    photo.Filename = filenames.ElementAt(fileIndex);
                    photo.InputCategory = inputCategoryName;
                    photo.SourceFilePath = filenames[fileIndex];
                    photo.Filename = Path.GetFileName(filenames[fileIndex]);
                    if (photo.Filename.Equals("add_photo.png"))
                    {
                        photo.Name = "";
                    }
                    else
                    {
                        photo.Name = photo.Filename;
                    }
                    photo.OutputCategories = MethodologyProvider.Get().Methodology.InputCategories[inputCategoryName].outputCategories;

                    this.result.PhotoList.Add(photo);
                }
                AddAllPlaceHolders();
                UpdateDataContext();
            }
        }
 private void AddPlaceHolder(string inputCategoryName)
 {
     Photo photo = new Photo();
     photo.InputCategory = inputCategoryName;
     photo.SourceFilePath = placeHolderImagePath;
     photo.Filename = Path.GetFileName(placeHolderImagePath);
     if (photo.Filename.Equals("add_photo.png"))
     {
         photo.Name = "";
     }
     else
     {
         photo.Name = photo.Filename;
     }
     photo.OutputCategories = MethodologyProvider.Get().Methodology.InputCategories[inputCategoryName].outputCategories;//Get the list of outputCategories from the MethodologyProvider
     this.result.PhotoList.Add(photo);
 }