コード例 #1
0
        static void testCalcHsvAsynNumber()
        {
            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_hsvasyn_number.txt";

            StreamWriter sw = File.CreateText(retest);

            for (int i = 1; i <= 100; ++i)
            {
                string  picName = selectedPath + i + ext;
                float[] vhsv    = im.ExtractHSVAynsColorVector(picName, 0, new int[] { -1 });
                if (vhsv == null)
                {
                    Console.WriteLine("Error of {0}{1}", i, ext);
                    continue;
                }
                sw.WriteLine("{0}, {1}", cnByMan[i - 1], getColorNumber(vhsv, limit));
            }
            sw.Close();
        }
コード例 #2
0
        private static void testHSVAsynColorNumberSuccess()
        {
            Console.WriteLine("begin");
            ImageMatcher im = new ImageMatcher();

            String selectedPath = @"F:\jpgtest\";
            String ext          = ".jpg";

            string retest = @"E:\projects\ClothSearch\codes\trunk\data\RGBColor\retest_rate_hsv_aync2.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[] cnhsv = new int[100];
            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[] vhsv    = im.ExtractHSVAynsColorVector(picName, 0, new int[] { -1 });
                    if (vhsv == null)
                    {
                        Console.WriteLine("Error of {0}{1}", i + 1, ext);
                        continue;
                    }
                    cnhsv[i] = getColorNumber(vhsv, limit);
                    //sw.WriteLine("{0}, {1}, {2}", getColorNumber(vrgb, limit), getColorNumber(vhsv, limit), getColorNumber(vhls, limit));
                }
                float  avr    = 0.0f;
                float  avrR   = 0.0f;
                string format = "{0,-5}/{1,-5}/{2} , {3,-12}, {4,-14}, {5,-8}, {6,-12}, {7,-8}, {8,-7}";

                calcAvr(cnhsv, ref avr, ref avrR);
                sw.WriteLine(format, 176, limit, "hsva", avr - avrByMan, avrR - avrRByMan,
                             calcSucRate(cnByMan, cnhsv, 0.0f), calcSucRate(cnByMan, cnhsv, avr - avrByMan),
                             calcMaihadun(cnByMan, cnhsv), calEjilide(cnByMan, cnhsv));
            }

            sw.Close();
        }
コード例 #3
0
        static void testExtractRGBColor()
        {
            Console.WriteLine("begin");
            ImageMatcher im = new ImageMatcher();

            String selectedPath = @"F:\jpgtest";

            string[] jpgFiles = Directory.GetFiles(selectedPath, "*.jpg");
            string[] gifFiles = Directory.GetFiles(selectedPath, "*.gif");
            string[] pngFiles = Directory.GetFiles(selectedPath, "*.png");
            string[] bmpFiles = Directory.GetFiles(selectedPath, "*.bmp");
            int      nFiles   = jpgFiles.Length + gifFiles.Length + pngFiles.Length + bmpFiles.Length;

            if (nFiles == 0)
            {
                return;
            }

            List <String> picNames = new List <string>(nFiles);

            picNames.AddRange(jpgFiles);
            picNames.AddRange(gifFiles);
            picNames.AddRange(pngFiles);
            picNames.AddRange(bmpFiles);

            Console.WriteLine("begin extract");
            string pre = @"E:\projects\ClothSearch\codes\trunk\data\RGBColor\HSVAsynColor_float_11x4x4.txt";

            float[][] vs    = new float[picNames.Count][];
            int       count = 0;

            foreach (String picName in picNames)
            {
                vs[count++] = im.ExtractHSVAynsColorVector(picName, 0, new int[] { -1 });
            }

            //int index = picName.LastIndexOf('\\');
            //StreamWriter sw = File.CreateText(pre + picName.Substring(index + 1) + ".txt");
            StreamWriter sw = File.CreateText(pre);

            for (int j = 0; j < vs[0].Length; j++)
            {
                for (int i = 0; i < vs.Length; i++)
                {
                    sw.Write("{0},", vs[i][j]);
                }
                sw.WriteLine();
            }
            sw.Close();
        }
コード例 #4
0
ファイル: HomeWin.xaml.cs プロジェクト: silasxue/cloth-search
        /*
         * 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);
        }