static void testCalcColorNumber() { Console.WriteLine("begin"); ImageMatcher im = new ImageMatcher(); String selectedPath = @"F:\jpgtest\"; String ext = ".jpg"; float limit = 0.1f; int vecnum = 8; string retest = @"E:\projects\ClothSearch\codes\trunk\data\RGBColor\retest_8_0.1.txt"; StreamWriter sw = File.CreateText(retest); for (int i = 1; i <= 100; ++i) { string picName = selectedPath + i + ext; float[] vrgb = im.ExtractRGBColorVector(picName, vecnum, new int[] { -1 }); float[] vhsv = im.ExtractHSVColorVector(picName, vecnum, new int[] { -1 }); float[] vhls = im.ExtractHLSColorVector(picName, vecnum, new int[] { -1 }); if (vrgb == null || vhsv == null || vhls == null) { Console.WriteLine("Error of {0}{1}", i, ext); continue; } sw.WriteLine("{0}, {1}, {2}, {3}", cnByMan[i - 1], getColorNumber(vrgb, limit), getColorNumber(vhsv, limit), getColorNumber(vhls, limit)); } sw.Close(); }
private static void testColorNumberSuccess() { Console.WriteLine("begin"); ImageMatcher im = new ImageMatcher(); String selectedPath = @"F:\jpgtest\"; String ext = ".jpg"; string retest = @"E:\projects\ClothSearch\codes\trunk\data\RGBColor\retest_rate2.txt"; StreamWriter sw = File.CreateText(retest); sw.AutoFlush = true; float avrByMan = 0.0f; float avrRByMan = 0.0f; calcAvr(cnByMan, ref avrByMan, ref avrRByMan); sw.WriteLine("图片: {0}, 平均每张图片颜色数: {1}, 偏差: {2}", 100, avrByMan, avrRByMan); sw.WriteLine("vec /lim /Algo, avr-avrByMan, avrR-avrRByMan, suc_rate, mod_suc_rate, maihadun, ejilide"); // float limit = 0.05f; // int vecnum = 8; int[] cnrgb = new int[100]; int[] cnhsv = new int[100]; int[] cnhls = new int[100]; for (int vecnum = 2; vecnum <= 10; ++vecnum) { for (float limit = 0.05f; limit <= 0.1f; limit += 0.01f) { for (int i = 0; i < 100; ++i) { string picName = selectedPath + (i + 1) + ext; float[] vrgb = im.ExtractRGBColorVector(picName, vecnum, new int[] { -1 }); float[] vhsv = im.ExtractHSVColorVector(picName, vecnum, new int[] { -1 }); float[] vhls = im.ExtractHLSColorVector(picName, vecnum, new int[] { -1 }); if (vrgb == null || vhsv == null || vhls == null) { Console.WriteLine("Error of {0}{1}", i + 1, ext); continue; } cnrgb[i] = getColorNumber(vrgb, limit); cnhsv[i] = getColorNumber(vhsv, limit); cnhls[i] = getColorNumber(vhls, limit); //sw.WriteLine("{0}, {1}, {2}", getColorNumber(vrgb, limit), getColorNumber(vhsv, limit), getColorNumber(vhls, limit)); } float avr = 0.0f; float avrR = 0.0f; calcAvr(cnrgb, ref avr, ref avrR); string format = "{0,-5}/{1,-5}/{2} , {3,-12}, {4,-14}, {5,-8}, {6,-12}, {7,-8}, {8,-7}"; sw.WriteLine(format, vecnum, limit, "rgb", avr - avrByMan, avrR - avrRByMan, calcSucRate(cnByMan, cnrgb, 0.0f), calcSucRate(cnByMan, cnrgb, avr - avrByMan), calcMaihadun(cnByMan, cnrgb), calEjilide(cnByMan, cnrgb)); calcAvr(cnhsv, ref avr, ref avrR); sw.WriteLine(format, vecnum, limit, "hsv", avr - avrByMan, avrR - avrRByMan, calcSucRate(cnByMan, cnhsv, 0.0f), calcSucRate(cnByMan, cnhsv, avr - avrByMan), calcMaihadun(cnByMan, cnhsv), calEjilide(cnByMan, cnhsv)); calcAvr(cnhls, ref avr, ref avrR); sw.WriteLine(format, vecnum, limit, "hls", avr - avrByMan, avrR - avrRByMan, calcSucRate(cnByMan, cnhls, 0.0f), calcSucRate(cnByMan, cnhls, avr - avrByMan), calcMaihadun(cnByMan, cnhls), calEjilide(cnByMan, cnhls)); } } sw.Close(); }