Beispiel #1
0
        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();
        }
Beispiel #2
0
        /*
         * private void btnSearch_Click(object sender, RoutedEventArgs e)
         * {
         *  /*if (++count >= 1000)
         *  {
         *      MessageBox.Show("系统未注册, 请与供应商联系, 谢谢.");
         *      this.Close();
         *  }*
         *
         *  //inProgWin = new IndeterminateProgressWin("请等待", "正在查询中...");
         *  //inProgWin.Show();
         *
         *  int searchMark = 0;
         *  if (true == rbtnPic.IsChecked)
         *  {
         *      //if (null == keyCloth || string.IsNullOrEmpty(keyCloth.Path))
         *      if (!canSearchByPic())
         *      {
         *          MessageBox.Show("图片搜索必须先指定关键图.", "搜索图片...");
         *          return;
         *      }
         *      lblSearchResultInfo.Content = "正在通过图片内容搜索请稍候...";
         *      searchMark = 1;
         *      //searchedClothes = searchByPic();
         *  }
         *  else if (true == rbtnText.IsChecked)
         *  {
         *      lblSearchResultInfo.Content = "正在通过文字搜索请稍候...";
         *      searchMark = 2;
         *      //searchedClothes = searchByText();
         *  }
         *  else if (true == rbtnCombine.IsChecked)
         *  {
         *      if (!canSearchByPic())
         *      {
         *          MessageBox.Show("联合搜索必须先指定关键图.", "联合搜索图片...");
         *          return;
         *      }
         *      lblSearchResultInfo.Content = "正在进行联合搜索请稍候...";
         *      searchMark = 3;
         *      //searchedClothes = searchByCombine();
         *  }
         *
         *  updatePicResults();
         *
         *  //inProgWin.Close();
         * }
         */
        /// <summary>
        ///
        /// </summary>
        /// <returns>Result list. Null if no search executed.</returns>
        private List <Cloth> searchByPic()
        {
            if (null == keyCloth || string.IsNullOrEmpty(keyCloth.Path))
            {
                return(null);
            }

            List <Cloth> clothes = new List <Cloth>();
            int          index   = ViewHelper.RecallLevelToIndex(aDesc.RLevel);

            switch (aDesc.AType)
            {
            case AlgorithmType.Color1:
                if (null == keyCloth.DaubechiesWaveletVector)
                {
                    keyCloth.DaubechiesWaveletVector = imageMatcher.ExtractDaubechiesWaveletVector(keyCloth.Path);
                }
                if (null == keyCloth.HSVColorVector)
                {
                    keyCloth.HSVColorVector = imageMatcher.ExtractHSVColorVector(keyCloth.Path, 3, SearchConstants.IgnoreColors);
                    int colorNum = ClothUtil.getColorNumber(keyCloth.HSVColorVector, 0.07f);
                    if (colorNum > 8)
                    {
                        colorNum = 8;
                    }
                    keyCloth.ColorNum = colorNum;
                }

                //float[] textureVector = keyCloth.DaubechiesWaveletVector;
                if (null == keyCloth.DaubechiesWaveletVector || null == keyCloth.HSVColorVector)
                {
                    MessageBox.Show("您选择的文件无法识别, 可能不是图片文件.", "提取特征4...");
                    return(null);
                }

                /*if (clothSearchService.GetTextureMDLimit() != SearchConstants.TextureMDLimits[index])
                 * {
                 *  clothSearchService.SetTextureMDLimit(SearchConstants.TextureMDLimits[index]);
                 * }*/
                clothes = clothSearchService.SearchByPicDaubechiesWavelet(keyCloth);
                //clothes = clothSearchService.SearchTest3(keyCloth);
                break;

            case AlgorithmType.Texture1:
                if (null == keyCloth.RGBColorVector)
                {
                    keyCloth.RGBColorVector = imageMatcher.ExtractRGBColorVector(keyCloth.Path, 3, SearchConstants.IgnoreColors);
                }
                if (keyCloth.RGBColorVector == null)
                {
                    MessageBox.Show("无法识别指定图片文件, 请检查该文件是否正确.", "提取特征3...");
                    return(null);
                }

                clothes = clothSearchService.SearchByPicRGBColor(keyCloth);
                break;

            case AlgorithmType.Texture2:
                if (null == keyCloth.HSVAynsColorVector)
                {
                    keyCloth.HSVAynsColorVector = imageMatcher.ExtractHSVAynsColorVector(keyCloth.Path, 0, SearchConstants.IgnoreColors);
                }
                if (keyCloth.HSVAynsColorVector == null)
                {
                    MessageBox.Show("无法识别指定图片文件, 请检查该文件是否正确.", "提取特征2...");
                    return(null);
                }

                clothes = clothSearchService.SearchByPicHSVAynsColor(keyCloth);
                break;

            case AlgorithmType.Texture3:
            default:
                if (null == keyCloth.HSVColorVector)
                {
                    keyCloth.HSVColorVector = imageMatcher.ExtractHSVColorVector(keyCloth.Path, 3, SearchConstants.IgnoreColors);
                    int colorNum = ClothUtil.getColorNumber(keyCloth.HSVColorVector, 0.07f);
                    if (colorNum > 8)
                    {
                        colorNum = 8;
                    }
                    keyCloth.ColorNum = colorNum;
                }
                if (keyCloth.HSVColorVector == null)
                {
                    MessageBox.Show("无法识别指定图片文件, 请检查该文件是否正确.", "提取特征1...");
                    return(null);
                }

                clothes = clothSearchService.SearchByPicHSVColor(keyCloth);
                break;
            }

            return(clothes);
        }
Beispiel #3
0
        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();
        }