資源簡介
在網上找的用灰度直方圖方法計算相似度的算法寫的小例子,經測試效果還可以

代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.ComponentModel;
using?System.Data;
using?System.Drawing;
using?System.Drawing.Imaging;
using?System.IO;
using?System.Linq;
using?System.Text;
using?System.Threading.Tasks;
using?System.Windows.Forms;
namespace?ImageMatch
{
????public?partial?class?Form1?:?Form
????{
????????public?Form1()
????????{
????????????InitializeComponent();
????????}
????????string?baseFileName?matchFileName;
????????string?tempFilePath?=?“C:\\MatchImage\\“;
????????Bitmap?baseBM?matchBM;
????????string?baseShortName?matchShortName;
????????private?void?btnbase_Click(object?sender?EventArgs?e)
????????{
????????????if?(openFileDialog1.ShowDialog()?==?DialogResult.OK)
????????????{
????????????????Image?fromImage?=?Image.FromFile(this.openFileDialog1.FileName);
????????????????baseFileName?=?this.openFileDialog1.FileName;
????????????????fromImage?=?fromImage.AdjImageToFitSize(pbMatch.Width?pbMatch.Height);?//350??l;
????????????????this.pbbase.Image?=?fromImage;
????????????????string[]?names?=?baseFileName.Split(‘\\‘);
????????????????baseShortName?=?names[names.Length?-?1];
????????????????baseBM?=?Resize(baseFileName?tempFilePath?+?“base_“?+?baseShortName);
????????????}
????????}
????????private?void?btnMatch_Click(object?sender?EventArgs?e)
????????{
????????????if?(openFileDialog2.ShowDialog()?==?DialogResult.OK)
????????????{
????????????????Image?fromImage?=?Image.FromFile(this.openFileDialog2.FileName);
????????????????matchFileName?=?this.openFileDialog2.FileName;
????????????????fromImage?=?fromImage.AdjImageToFitSize(pbMatch.Width?pbMatch.Height);?//350??
????????????????this.pbMatch.Image?=?fromImage;
????????????????string[]?names?=?matchFileName.Split(‘\\‘);
????????????????matchShortName?=?names[names.Length?-?1];
????????????????matchBM?=?Resize(matchFileName?tempFilePath?+?“match_“?+?matchShortName);
????????????}
????????}
????????public?Bitmap?Resize(string?imageFile?string?newImageFile)
????????{
????????????checkDir(tempFilePath);
????????????Image?img?=?Image.FromFile(imageFile);
????????????Bitmap?imgOutput?=?new?Bitmap(img?256?256);
????????????imgOutput.Save(newImageFile?System.Drawing.Imaging.ImageFormat.Jpeg);
????????????imgOutput.Dispose();
????????????return?(Bitmap)Image.FromFile(newImageFile);
????????}
????????///?
????????///?檢查指定目錄是否存在如不存在則創建
????????///?
????????///?
????????///?
????????public?static?bool?checkDir(string?url)
????????{
????????????try
????????????{
????????????????if?(!Directory.Exists(url))//如果不存在就創建file文件夾 ????????????? ??????????????
????????????????????Directory.CreateDirectory(url);//創建該文件夾 ????????????
????????????????return?true;
????????????}
????????????catch?(Exception?ex)
????????????{
????????????????return?false;
????????????}
????????}
????????public?int[]?GetHisogram(Bitma
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件????????187??2018-03-01?16:12??MatchImage\MatchImage\App.config
?????文件??????13312??2018-03-02?16:26??MatchImage\MatchImage\bin\Debug\MatchImage.exe
?????文件????????187??2018-03-01?16:12??MatchImage\MatchImage\bin\Debug\MatchImage.exe.config
?????文件??????30208??2018-03-02?16:26??MatchImage\MatchImage\bin\Debug\MatchImage.pdb
?????文件??????22984??2018-03-02?16:26??MatchImage\MatchImage\bin\Debug\MatchImage.vshost.exe
?????文件????????187??2018-03-01?16:12??MatchImage\MatchImage\bin\Debug\MatchImage.vshost.exe.config
?????文件????????490??2012-06-06?02:06??MatchImage\MatchImage\bin\Debug\MatchImage.vshost.exe.manifest
?????文件??????24982??2018-03-02?11:07??MatchImage\MatchImage\bin\Debug.rar
?????文件???????6720??2018-03-01?16:14??MatchImage\MatchImage\Form1.cs
?????文件???????7087??2018-03-01?16:14??MatchImage\MatchImage\Form1.Designer.cs
?????文件???????6225??2018-03-01?16:14??MatchImage\MatchImage\Form1.resx
?????文件???????3848??2018-03-02?16:26??MatchImage\MatchImage\MatchImage.csproj
?????文件???????1308??2018-03-02?10:45??MatchImage\MatchImage\obj\Debug\DesignTimeResolveAssemblyReferences.cache
?????文件???????6955??2018-03-02?16:26??MatchImage\MatchImage\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache
?????文件????????180??2018-03-02?16:26??MatchImage\MatchImage\obj\Debug\ImageMatch.Form1.resources
?????文件????????681??2018-03-02?16:26??MatchImage\MatchImage\obj\Debug\MatchImage.csproj.FileListAbsolute.txt
?????文件????????975??2018-03-02?11:07??MatchImage\MatchImage\obj\Debug\MatchImage.csproj.GenerateResource.Cache
?????文件???????2209??2018-03-02?16:26??MatchImage\MatchImage\obj\Debug\MatchImage.csprojResolveAssemblyReference.cache
?????文件??????13312??2018-03-02?16:26??MatchImage\MatchImage\obj\Debug\MatchImage.exe
?????文件??????30208??2018-03-02?16:26??MatchImage\MatchImage\obj\Debug\MatchImage.pdb
?????文件????????180??2018-03-02?16:26??MatchImage\MatchImage\obj\Debug\MatchImage.Properties.Resources.resources
?????文件??????????0??2018-03-01?16:12??MatchImage\MatchImage\obj\Debug\TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs
?????文件??????????0??2018-03-01?16:12??MatchImage\MatchImage\obj\Debug\TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs
?????文件??????????0??2018-03-01?16:12??MatchImage\MatchImage\obj\Debug\TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs
?????文件????????541??2018-03-01?16:18??MatchImage\MatchImage\Program.cs
?????文件???????1358??2018-03-01?16:12??MatchImage\MatchImage\Properties\AssemblyInfo.cs
?????文件???????2872??2018-03-01?16:12??MatchImage\MatchImage\Properties\Resources.Designer.cs
?????文件???????5612??2018-03-01?16:12??MatchImage\MatchImage\Properties\Resources.resx
?????文件???????1097??2018-03-01?16:12??MatchImage\MatchImage\Properties\Settings.Designer.cs
?????文件????????249??2018-03-01?16:12??MatchImage\MatchImage\Properties\Settings.settings
............此處省略13個文件信息
評論
共有 條評論