我有不同的軟件在多個文件夾中生成多個標籤。標籤的大小是相同的,但它們的透明度標籤是不同的。理想上它們是相同的,但是當我使用我的內部應用程序比較時,它會引發錯誤,說它們不匹配。將圖像與透明度級別的變化進行比較並比較其中的文本
我知道類似的問題,但他們並不完全符合我的問題。我需要用c#實現相關的算法。
我正在探索一些API的AForge.Net,ImageMagick。
直到現在我比較字節
filename1 = Path.Combine(directory.ToString(), new1[i].ToString());
filename2 = Path.Combine(directory1.ToString(), new2[i].ToString());
using (Bitmap bm1 = new Bitmap(filename1))
{
using (Bitmap bm2 = new Bitmap(filename2))
{
// Make a difference image.
int wid = Math.Min(bm1.Width, bm2.Width);
int hgt = Math.Min(bm1.Height, bm2.Height);
Bitmap bm3 = new Bitmap(wid, hgt);
// Create the difference image.
bool are_identical = true;
Color eq_color = Color.White;
Color ne_color = Color.Red;
for (int x = 0; x < wid; x++)
{
for (int y = 0; y < hgt; y++)
{
//if (bm1.GetPixel(x, y).Equals(bm2.GetPixel(x, y)))
if (bm1.GetPixel(x, y) != (bm2.GetPixel(x, y)))
{
//bm3.SetPixel(x, y, eq_color);
bm3.SetPixel(x, y, ne_color);
are_identical = false;
}
else
{
//bm3.SetPixel(x, y, ne_color);
//are_identical = false;
}
}
//I kept the code here before
}
if (!are_identical)
{
bm3.Save(@"C:\Users\XPS Files\DiffrenceofImages" + new1[i]);
}
// Display the result.
//picResult.Image = bm3;
//bm3.Save(@"C:\Users\XPS Files\DiffrenceofImages\" + new1[i]);
this.Cursor = Cursors.Default;
if ((bm1.Width != bm2.Width) || (bm1.Height != bm2.Height)) are_identical = false;
if (are_identical)
{
//richTextBox1.Text = string.Format("Images are identical", "\r\n");
sb.AppendLine("Image Name=" + new1[i] + " are identical at both folder");
}
else
{
//richTextBox1.Text = string.Format("Images are NOT MATCHING", "\r\n");
sb.AppendLine("Image Name=" + new1[i] + " are Not Matching at both folder");
}
//sb.AppendLine(f1.Name + ": " + (equal ? "Images are equal" : "Images are NOT equal"));
}
}
result.Add(sb.ToString());
看來你的代碼有問題。但是,除非我們有[可以重現問題的代碼或信息](http://stackoverflow.com/help/mcve),否則我們無法提供幫助。否則,我們只是盲目猜測。 – gunr2171
請提供一些你已經做了什麼的代碼,以及你的代碼失敗了。這聽起來像你只需要忽略alpha通道,但這只是第一個想法。 – Nitram
爲什麼是負面的?我的代碼爲emgucv圖片位圖=新圖片(@「D:\ red3.bmp」); 圖片 bitmap1 =新圖片(@「D:\ red3.bmp」); Hsv lowerLimit = new Hsv(0,0,200); Hsv upperLimit = new Hsv(5,255,255); var imageHSVDest = bitmap.InRange(lowerLimit,upperLimit); CvInvoke.cvShowImage(「imageHSVDest」,imageHSVDest); bitmap.AbsDiff(bitmap1); –