Beispiel #1
0
        static void testExtractFeatures()
        {
            Console.WriteLine("hello");
            ImageMatcher im = new ImageMatcher();
            String       s  = @"F:\photos\cc\08-06-23写真\ 003.JPG";

            //string s = @"E:\pic_skindetect\img_lib\20081839149581.jpg";
            im.LuvInit(@"E:\projects\ClothSearch\codes\trunk\data\luv.dat");
            float[] v   = im.ExtractDaubechiesWaveletVector(s);
            float   sum = 0;

            foreach (float i in v)
            {
                Console.Write("{0} ", i);
                sum += i;
            }
            Console.WriteLine();
            Console.WriteLine("{0}", sum);

            /*            Console.WriteLine(ImageMatcher.testAdd(10, 20).ToString());
             *          ImageMatcher im = new ImageMatcher();
             *          Console.WriteLine(im.testAdd2("abcd", 20).ToString());
             *
             * /*            Type t = Type.GetTypeFromProgID("ZjuImage.ImageMatcher");
             *          object voice = Activator.CreateInstance(t);
             *          object[] args = new Object[2];
             *          args[0] = "Hello, World!";
             *          args[1] = 0;
             *          t.InvokeMember("Speak", BindingFlags.InvokeMethod, null, voice, args);
             *          im.extractColorVector("abcd");*/
        }
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
        static void testClothSearch()
        {
            Console.WriteLine("begin");
            ImageMatcher im = new ImageMatcher();

            im.LuvInit(@"E:\projects\ClothSearch\codes\trunk\data\luv.dat");

            String selectedPath = @"E:\pic_skindetect\img_lib";

            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");
            List <float[]> tcs = new List <float[]>();
            List <float[]> ccs = new List <float[]>();
            List <string>  fns = new List <string>();

            foreach (String picName in picNames)
            {
                ccs.Add(im.ExtractRGBSeparateColorVector(picName, 8, new int[] { -1 }));
                tcs.Add(im.ExtractDaubechiesWaveletVector(picName));
                fns.Add(picName);
            }

            Console.WriteLine("begin calculate color md");
            StreamWriter sw    = File.CreateText(@"E:\projects\ClothSearch\codes\trunk\data\testcolor.txt");
            List <float> ccsMd = new List <float>();

            for (int i = 0; i < ccs.Count; ++i)
            {
                for (int j = 0; j < ccs.Count; ++j)
                {
                    ccsMd.Add(calcManhattanDistance(ccs[i], ccs[j]));
                }
                ccsMd.Sort();
                sw.WriteLine(fns[i]);
                foreach (float md in ccsMd)
                {
                    sw.WriteLine(md);
                }
                ccsMd.Clear();
            }
            sw.Close();


            Console.WriteLine("begin calculate texture md");
            sw = File.CreateText(@"E:\projects\ClothSearch\codes\trunk\data\testtexture.txt");
            List <float> tcsMd = new List <float>();

            for (int i = 0; i < tcs.Count; ++i)
            {
                for (int j = 0; j < tcs.Count; ++j)
                {
                    tcsMd.Add(calcManhattanDistance(tcs[i], tcs[j]));
                }

                tcsMd.Sort();
                sw.WriteLine(fns[i]);
                foreach (float md in tcsMd)
                {
                    sw.WriteLine(md);
                }
                tcsMd.Clear();
            }

            sw.Close();
        }