Example #1
0
        private void btnAddFileSave_Click(object sender, RoutedEventArgs e)
        {
            if (String.IsNullOrEmpty(addPicFileName))
            {
                // should not be here.
                MessageBox.Show("请先选择一张图片.", "温馨提醒");
                return;
            }
            Cloth cloth = new Cloth();

            // whether use the key cloth.
            bool useKeyPic = (null != keyCloth && keyCloth.Path == addPicFileName);

            cloth.Path = addPicFileName;

            if (!String.IsNullOrEmpty(txtAddPattern.Text))
            {
                cloth.Pattern = txtAddPattern.Text;
            }
            cloth.Name = useKeyPic && keyCloth.Name != null ? keyCloth.Name : ClothUtil.ExtractPattern(addPicFileName);

            ColorEnum colors = ColorEnum.NONE;

            foreach (ColorItem ci in colorItems)
            {
                if (ci.Selected)
                {
                    colors |= ci.Value;
                }
            }
            cloth.Colors = colors;

            ShapeEnum shapes = ShapeEnum.NONE;

            foreach (ShapeItem si in shapeItems)
            {
                if (si.Selected)
                {
                    shapes |= si.Value;
                }
            }
            cloth.Shapes = shapes;

            // feature vectors
            //cloth.RGBSeparateColorVector = (useKeyPic && keyCloth.RGBSeparateColorVector != null)
            //    ? keyCloth.RGBSeparateColorVector : ClothUtil.ImageMatcherInst.ExtractRGBSeparateColorVector(cloth.Path, 8, SearchConstants.IgnoreColors);
            cloth.RGBColorVector = (useKeyPic && keyCloth.RGBColorVector != null)
                ? keyCloth.RGBColorVector : ClothUtil.ImageMatcherInst.ExtractRGBColorVector(cloth.Path, 3, SearchConstants.IgnoreColors);
            cloth.HSVAynsColorVector = (useKeyPic && keyCloth.HSVAynsColorVector != null)
                ? keyCloth.HSVAynsColorVector : ClothUtil.ImageMatcherInst.ExtractHSVAynsColorVector(cloth.Path, 0, SearchConstants.IgnoreColors);
            cloth.HSVColorVector = (useKeyPic && keyCloth.HSVColorVector != null)
                ? keyCloth.HSVColorVector : ClothUtil.ImageMatcherInst.ExtractHSVColorVector(cloth.Path, 3, SearchConstants.IgnoreColors);
            if (cloth.HSVColorVector != null)
            {
                cloth.ColorNum = ClothUtil.getColorNumber(cloth.HSVColorVector, 0.07f);
            }

            cloth.DaubechiesWaveletVector = (useKeyPic && keyCloth.DaubechiesWaveletVector != null)
                ? keyCloth.DaubechiesWaveletVector : ClothUtil.ImageMatcherInst.ExtractDaubechiesWaveletVector(cloth.Path);
            //cloth.GaborVector = (useKeyPic && keyCloth.GaborVector != null)
            //    ? keyCloth.GaborVector : ClothUtil.ImageMatcherInst.ExtractGaborVector(cloth.Path);
            //cloth.CooccurrenceVector = (useKeyPic && keyCloth.CooccurrenceVector != null)
            //    ? keyCloth.CooccurrenceVector : ClothUtil.ImageMatcherInst.ExtractCooccurrenceVector(cloth.Path);

            clothLibService.Insert(cloth);

            // close the window.
            this.Close();
        }
Example #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);
        }