Beispiel #1
0
        private void FindImage(string file)
        {
            if (_lastUri != _currentUri)
            {
                // ドラッグされた画像を表示
                GC.Collect();
                try
                {
                    using (Bitmap queryImage = new Bitmap(file))
                    {
                        if (_bmpCache != null)
                        {
                            _bmpCache.Dispose();
                        }
                        // queryImageのファイルをロックしないように
                        // メモリ上に複製&32bitフォーマット化
                        _bmpCache = new Bitmap(queryImage);
                        this.pictureBox1.Image = _bmpCache;
                        _lastUri = _currentFile;
                    }
                }
                catch
                {
                    _lastUri = "";
                    this.pictureBox1.Image = new Bitmap(1, 1);
                }
            }

            Stopwatch watch = new Stopwatch();

            watch.Start();
            ulong vec = _iv.GetVector(file);

            this.richTextBox1.Text = string.Format("検索画像: {0}{1}", _currentFile, Environment.NewLine);

            List <string> data = new List <string>();

            ImageInfo[][] log = _iv.GetSimilarImage(vec, (int)this.comboBox1.SelectedItem);
            watch.Stop();
            this.richTextBox1.Text += string.Format("検索時間: {0} ms{1}{1}", watch.ElapsedMilliseconds, Environment.NewLine);

            if (log.Length == 0)
            {
                this.richTextBox1.Text += "見つかりませんでした。" + Environment.NewLine;
                return;
            }

            for (int i = 0; i < log.Length; i++)
            {
                var scene     = log[i];
                int titleId   = scene[0].TitleId;
                int episodeId = scene[0].EpisodeId;

                var storyInfo = _story.First(c => c.TitleId == titleId && c.EpisodeId == episodeId);

                string title  = storyInfo.Title;
                int    second = (int)(1.0 * scene[0].Frame / storyInfo.FrameRate);
                string time   = string.Format("{0}:{1:00}", (int)(second / 60), (second % 60));
                data.Add(title + time + "付近");

                // ニコニコ動画の頭出し付きリンクを生成
                second -= 6; // 6秒手前から(動画のキーフレームの位置によりずれる)
                second  = second < 0 ? 0 : second;
                string url = storyInfo.Url + "?from=" + second;
                data.Add(url);
                if (i == 0)
                {
                    if (this.checkBox1.Checked)
                    {
                        OpenUrl(url);
                    }
                }
            }

            this.richTextBox1.Text += string.Join(Environment.NewLine, data.ToArray());
        }
Beispiel #2
0
        private void FindImage(string file)
        {
            if (file == "")
            {
                return;
            }
            if (_lastUri != _currentUri)
            {
                // ドラッグされた画像を表示
                GC.Collect();
                try
                {
                    using (Bitmap queryImage = new Bitmap(file))
                    {
                        if (_bmpCache != null)
                        {
                            _bmpCache.Dispose();
                        }
                        // queryImageのファイルをロックしないように
                        // メモリ上に複製&32bitフォーマット化
                        _bmpCache = new Bitmap(queryImage);
                        this.pictureBox1.Image = _bmpCache;
                        _lastUri = _currentFile;
                    }
                }
                catch
                {
                    _lastUri = "";
                    this.pictureBox1.Image = new Bitmap(1, 1);
                }
            }

            Stopwatch watch = new Stopwatch();

            watch.Start();
            ulong  vec    = _iv.GetVector(file);
            string target = _currentFile == _tempBrowserImage ? _currentUri : _currentFile;

            this.richTextBox1.Text = string.Format("検索画像: {0}{1}", target, Environment.NewLine);

            List <string> data  = new List <string>();
            int           level = Properties.Settings.Default.SearchLevel;

            ImageInfo[][] log = _iv.GetSimilarImage(vec, level);
            watch.Stop();
            this.richTextBox1.Text += string.Format("検索時間: {0} ms{1}{1}", watch.ElapsedMilliseconds, Environment.NewLine);

            if (log.Length == 0)
            {
                this.richTextBox1.Text += "見つかりませんでした。" + Environment.NewLine;
                return;
            }

            for (int i = 0; i < log.Length; i++)
            {
                var scene     = log[i];
                int titleId   = scene[0].TitleId;
                int episodeId = scene[0].EpisodeId;

                var storyInfo = _navigator.Stories.First(c => c.TitleId == titleId && c.EpisodeId == episodeId);

                string title = _navigator.GetTitleWithSubtitle(storyInfo, scene[0].Frame);
                string time  = _navigator.GetTimeString(storyInfo, scene[0].Frame, 0, "<m>:<ss>");
                data.Add($"{title} {time} 付近");

                string url = _navigator.GetSeekUrl(storyInfo, scene[0].Frame);
                data.Add(url);
                if (i == 0)
                {
                    if (this.AutoPlayToolStripMenuItem.Checked)
                    {
                        OpenUrl(url);
                    }
                }
            }

            this.richTextBox1.Text += string.Join(Environment.NewLine, data.ToArray());
        }