private void importClothPicThread(Object obj) { ImportThreadArgus argus = (ImportThreadArgus)obj; List <Cloth> clothes = new List <Cloth>(argus.Step); while (!argus.StopImport()) { String picName = dequeuePicName(argus.PicNameQueue); if (picName == null) { break; } Cloth cloth = ClothUtil.GenerateClothObject(picName, argus.isGabor); clothes.Add(cloth); if (clothes.Count % argus.Step == 0) { InsertAll(clothes); argus.StepDel(clothes.Count); clothes.Clear(); } } if (clothes.Count > 0) { InsertAll(clothes); argus.StepDel(clothes.Count); } }
public List <Cloth> SearchTest4(Cloth keyCloth) { ClothUtil.ExtractFeaturesNecessary(keyCloth, false); return(new HLSColorSearcher(new PicParam(keyCloth.HLSColorVector, keyCloth.ColorNum), float.MaxValue, ClothUtil.CalcManhattanDistance, clothDao, 100).Search()); //return new DaubechiesWaveletSearcher(new PicParam(keyCloth.DaubechiesWaveletVector, keyCloth.ColorNum), float.MaxValue, ClothUtil.CalcManhattanDistance, // new HLSColorSearcher(new PicParam(keyCloth.HLSColorVector, keyCloth.ColorNum), float.MaxValue, ClothUtil.CalcManhattanDistance, clothDao, 100), 200).Search(); }
/// <summary> /// Show a picture in the <code>imgAdded</code> Image control with the file <code>fileName</code>. /// </summary> /// <param name="fileName"></param> private void showAddPicInfo(String fileName) { if (!String.IsNullOrEmpty(fileName)) { string pattern = ClothUtil.ExtractPattern(fileName); // use pattern as name currently. showAddPicInfo(fileName, pattern); } }
private List <Cloth> searchByCombine() { List <List <Cloth> > clothLists = new List <List <Cloth> >(); List <Cloth> clothesByText = searchByText(); if (clothesByText == null || clothesByText.Count == 0) { return(new List <Cloth>()); } clothLists.Add(clothesByText); clothLists.Add(searchByPic()); return(ClothUtil.IntersectClothLists(clothLists)); }
private void btnOpenKeyPic_Click(object sender, RoutedEventArgs e) { if (dlgOpenKeyPic.ShowDialog() == true) { BitmapImage bi = ViewHelper.NewBitmapImage(dlgOpenKeyPic.FileName); if (bi == null) { MessageBox.Show("您选择的文件无法识别, 可能不是图片文件.", "显示关键图..."); return; } imgKeyPic.Source = bi; keyCloth = new Cloth(); keyCloth.Path = dlgOpenKeyPic.FileName; keyCloth.Pattern = ClothUtil.ExtractPattern(keyCloth.Path); keyCloth.Name = keyCloth.Pattern; //keyCloth.ColorVector = imageMatcher.ExtractRGBSeparateColorVector(keyCloth.Path, SearchConstants.IgnoreColors); //keyCloth.TextureVector = imageMatcher.ExtractDaubechiesWaveletVector(keyCloth.Path); //keyCloth.GaborVector = imageMatcher.ExtractGaborVector(keyCloth.Path); //keyCloth.CooccurrenceVector = imageMatcher.ExtractCooccurrenceVector(keyCloth.Path); /*keyClothOpened = true; * if (keyClothThread != null && keyClothThread.IsAlive) * { * keyClothThread.Abort(); * } * ParameterizedThreadStart threadDelegate = new ParameterizedThreadStart(fillKeyCloth); * keyClothThread = new Thread(threadDelegate); * keyClothThread.IsBackground = true; * keyClothThread.Start(dlgOpenKeyPic.FileName); */ /*lock (keyClothLock) * { * FillKeyCloth fkc = new FillKeyCloth(fillKeyCloth); * fkc.BeginInvoke(dlgOpenKeyPic.FileName, ++curKeyClothOperId, null, null); * }*/ //ViewHelper.ExtractFeatures(keyCloth); //keyCloth.ColorVector = imageMatcher.ExtractRGBSeparateColorVector(keyCloth.Path, ViewConstants.IgnoreColors); //keyCloth.TextureVector = imageMatcher.ExtractDaubechiesWaveletVector(keyCloth.Path); //keyCloth.GaborVector = imageMatcher.ExtractGaborVector(keyCloth.Path); //keyCloth.CooccurrenceVector = imageMatcher.ExtractCooccurrenceVector(keyCloth.Path); updateSearchButton(); } }
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(); }
/* * 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); }
public override List <Cloth> Search() { List <Cloth> clothes = null; if (clothDao != null) { clothes = clothDao.FindAll(); } if (null == clothes) { throw new NullReferenceException("ClothDao are null, or some error happened."); } TextParam tp = (TextParam)param; string words = tp.Words; ColorEnum colors = tp.Colors; ShapeEnum shapes = tp.Shapes; List <List <Cloth> > clothLists = new List <List <Cloth> >(); if (colors != ColorEnum.NONE) { List <Cloth> clothesByColor = clothDao.FindAllByColors(colors); if (clothesByColor.Count > 0) { clothLists.Add(clothesByColor); } else { // empty list return(clothesByColor); } } if (shapes != ShapeEnum.NONE) { List <Cloth> clothesByShape = clothDao.FindAllByShapes(shapes); if (clothesByShape.Count > 0) { clothLists.Add(clothesByShape); } else { // empty list return(clothesByShape); } } if (!String.IsNullOrEmpty(words)) { string[] patterns = words.Split(new char[] { ',', ' ', '\t' }); List <List <Cloth> > clothListsByWords = new List <List <Cloth> >(); foreach (string pattern in patterns) { if (!string.IsNullOrEmpty(pattern)) { List <Cloth> clothesByPattern = clothDao.FindAllByPattern(pattern); if (clothesByPattern.Count > 0) { clothListsByWords.Add(clothesByPattern); } } } if (clothListsByWords.Count > 0) { clothLists.Add(ClothUtil.UnionClothLists(clothListsByWords)); } else { // empty list return(new List <Cloth>()); } } return(ClothUtil.IntersectClothLists(clothLists)); }