主目录:https://www.v2know.com/MainPage/Category/CSharp
前言:
这个方法对单一色图片的识别效果其实并不好,准确地说,就是黑白不分。
这是一个相对简单的识别,准确率不高,但可以满足部分需求,然后就是一部分代码是有问题的。
ImageSimilarity.cs:
public class ImageSimilarity
{
public Bitmap Resize(string imageFile, string newImageFile)
{
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 int[] GetHisogram(Bitmap img)
{
BitmapData data = img.LockBits(new System.Drawing.Rectangle(0, 0, img.Width, img.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
int[] histogram &#