コード例 #1
0
        /// <summary>
        /// 指定した file-directory 内の画像をこの ImageDirectory に登録します。
        /// </summary>
        /// <param name="dirpath">登録する画像を含んでいるディレクトリへの path を指定します。</param>
        public void AddFilesFromDirectory(string dirpath)
        {
            if (!System.IO.Directory.Exists(dirpath))
            {
                return;
            }

            System.IO.DirectoryInfo dir       = new System.IO.DirectoryInfo(dirpath);
            Gen::List <string>      filepaths = new Gen::List <string>();

            foreach (System.IO.FileInfo file in dir.GetFiles())
            {
                if (!exts.Contains(file.Extension.ToLower()))
                {
                    continue;
                }
                filepaths.Add(file.FullName);
            }
            if (filepaths.Count == 0)
            {
                return;
            }

            afh.Forms.ProgressDialog progress = new afh.Forms.ProgressDialog();
            progress.Title       = "画像を読込中 ...";
            progress.ProgressMax = filepaths.Count;
            progress.Show();
            // 読込
            foreach (string path in filepaths)
            {
                try{
                    progress.Description = "画像 " + path + " を読み込んでいます...";
                    this.AddFile(path);
                    progress.Progress++;
                    if (progress.IsCanceled)
                    {
                        break;
                    }
                }catch (System.Exception e) {
                    afh.File.__dll__.log.WriteError(e, path + " の読込に失敗しました。");
                }
            }
            progress.Close();
        }
コード例 #2
0
ファイル: Utility.cs プロジェクト: akinomyoga/ImageArrange
        public static void SearchNearImage(ThumbsFile file)
        {
            ImageDirectory overlap = new ImageDirectory("<重複検索>", file);

            afh.Collections.SortedArrayP <Thumb>    images = file.thumbs.SortedThumbs;
            Gen::Dictionary <Image, ImageDirectory> groups = new Gen::Dictionary <Image, ImageDirectory>();

            afh.Forms.ProgressDialog progress = new afh.Forms.ProgressDialog();
            progress.Title       = "重複比較中 ...";
            progress.ProgressMax = images.Count;

            progress.Show();
            for (int i = 0; i < images.Count; i++)
            {
                Image img1 = new Image(file, images[i]);

                if (i % 50 == 0)
                {
                    progress.Description = "画像 '" + img1.thm.filepath + "' の類似画像を探索中 ...";
                    if (progress.IsCanceled)
                    {
                        return;
                    }
                }

                for (int j = i + 1; j < images.Count; j++)
                {
                    Image img2 = new Image(file, images[j]);
                    if (!Image.EqualAspect(img1, img2))
                    {
                        break;
                    }

                    if (Image.Resembles(img1, img2))
                    {
                        ImageDirectory group1 = null;
                        ImageDirectory group2 = null;
                        bool           b1     = groups.TryGetValue(img1, out group1);
                        bool           b2     = groups.TryGetValue(img2, out group2);
                        switch ((b1?1:0) | (b2?2:0))
                        {
                        case 3:                                 // 両方
                            if (group1 == group2)
                            {
                                break;
                            }
                            // 両グループの併合
                            overlap.dirs.Remove(group2);
                            foreach (Image img in group2.EnumImages())
                            {
                                group1.Add(img);
                                groups[img] = group1;
                            }
                            break;

                        case 1:                                 // group1 だけ
                            group1.Add(img2);
                            groups.Add(img2, group1);
                            break;

                        case 2:                                 // group2 だけ
                            group2.Add(img1);
                            groups.Add(img1, group2);
                            break;

                        case 0:                                 // 両者未登録
                            ImageDirectory group = new ImageDirectory("Group " + overlap.dirs.Count.ToString(), file);
                            group.Add(img1);
                            group.Add(img2);
                            groups.Add(img1, group);
                            groups.Add(img2, group);
                            overlap.Add(group);
                            break;

                        default:
                            throw new System.InvalidProgramException();
                        }
                        //System.Console.WriteLine("次の画像は似ています\r\n    {0}\r\n    {1}",thm1.filepath,thm2.filepath);
                    }
                }
                if (i % 10 == 0)
                {
                    progress.Progress = i;
                }
            }
            progress.Close();

            file.dirs.Add(overlap);
        }