Beispiel #1
0
vector<FindResult> 
getFindResults(Mat screenImage, Pattern ptn, bool all, double similarity) {
   
   vector<FindResult> results;
   
   if (ptn.isText()){
      
      
      TextFinder f(screenImage);      
      f.find(ptn.getText(), similarity);
      
      if (all){
         while (f.hasNext()){
            results.push_back(f.next());
         }
      }
      else{
         if (f.hasNext())
            results.push_back(f.next());
      }
      
      
      
   }else{
      
      TemplateFinder f(screenImage);
	  //string str(ptn.getImageURL());
	  //char filename[] = "c:\\cygwin\\home\\tomyeh\\libsikuli\\examples\\images\\startpage.png";
	  //string name("examples\\images\\startpage.png"); 
      ScreenImage ptn_img = ptn.getScreenImage();
	   Mat image = ptn_img.getMat();
      //imread(ptn.getImageURL());

	  
	  //ptn.getImageURL());
	  
	/*namedWindow("Test");
	imshow("Test",image);
	waitKey();*/

      
      if (all){
         f.find_all(image, similarity);
         while (f.hasNext()){
            results.push_back(f.next());
         }
      }
      else{
         f.find(image, similarity);
         if (f.hasNext())
            results.push_back(f.next());
         
      }
   }
   return results;
}
Beispiel #2
0
vector<Match>
Region::doFind(Pattern target) {

 
   dout << "[Region::doFind] Searching in (" << xo+x << "," << yo+y << ")-(" << xo+x+w << "," << yo+y+h << ")" << endl; 
  
   ScreenImage simg = capture();

   FindInput* fi;
   
   if (target.isText())
      fi = new FindInput(simg.getMat(), TARGET_TYPE_TEXT, target.getText());
   else
      fi = new FindInput(simg.getMat(), TARGET_TYPE_IMAGE, target.getImageURL());   
      

   FindInput& input = *fi;   
   input.setFindAll(target.bAll());
   input.setLimit(target.getLimit());
   input.setSimilarity(target.getSimilarity());
   
   
  if (!target.bAll() && target.where() != ANYWHERE){
     input.setFindAll(true);
  }
   
   vector<FindResult> results = Vision::find(input);
   delete fi;
   
            
   if (target.getOrdering() == TOPDOWN){
      sort(results.begin(), results.end(), sort_by_y_asc);
   }else if (target.getOrdering() == BOTTOMUP){
      sort(results.begin(), results.end(), sort_by_y_dsc);
   }else if (target.getOrdering() == LEFTRIGHT){
      sort(results.begin(), results.end(), sort_by_x_asc);
   }else if (target.getOrdering() == RIGHTLEFT){
      sort(results.begin(), results.end(), sort_by_x_dsc);
   }
   
   if (!target.bAll() && target.where() != ANYWHERE){   
         if (!results.empty()){
            // Filter Results
            FindResult r = results[0];
            for (int i=1; i<results.size(); ++i){
               FindResult& ri = results[i];
               if ((target.where() == TOPMOST && ri.y < r.y) ||
                   (target.where() == BOTTOMMOST && ri.y > r.y) ||
                   (target.where() == LEFTMOST && ri.x < r.x) ||
                   (target.where() == RIGHTMOST && ri.x > r.x))
                  r = ri;
            }
            
            results.clear();
            results.push_back(r);
         }
   }   
   
   vector<Match> matches;
   int n = min((int)results.size(), (int)target.getLimit());
   for (int i=0; i< n; ++i){
      FindResult& r = results[i];
      Match match(inner(r.x,r.y,r.w,r.h),r.score); 
      matches.push_back(match);
   }
   
   
   if (!matches.empty()){
      SikuliUI::sikuliUI->handleMatchFound(*this, target, matches);

      setLastMatch(matches[0]);
      setLastMatches(matches);
   }
   
   // TODO: setTargetOffset 
   //match.setTargetOffset(ptn.getTargetOffset());
   return matches;
}