Esempio n. 1
0
static vector<FindResult> 
find_image(FindInput& input){
   
   vector<FindResult> results;
   Mat source = input.getSourceMat();
   Mat image = input.getTargetMat();
   if(!source.rows || !source.cols || !image.rows || !image.cols)
      return results;
      
   TemplateFinder f(source);
   
   if (input.isFindingAll()){
      f.find_all(image, input.getSimilarity());
      while (f.hasNext()){
         results.push_back(f.next());
      }
   }
   else{
      f.find(image, input.getSimilarity());
      if (f.hasNext())
         results.push_back(f.next());
      
   }
   return results;
}
Esempio n. 2
0
static vector<FindResult> 
find_image(FindInput& input){
   
   vector<FindResult> results;
   Mat source = input.getSourceMat();
   Mat image = input.getTargetMat();
   if(!source.rows || !source.cols || !image.rows || !image.cols)
      return results;
      
   TemplateFinder f(source);
   
   if (input.isFindingAll()){
      int maxReturn = Vision::getParameter("FindAllMaxReturn");
      f.find_all(image, input.getSimilarity());
      while (f.hasNext() && results.size() < maxReturn){
         results.push_back(f.next());
      }
   }
   else{
      f.find(image, input.getSimilarity());
      if (f.hasNext())
         results.push_back(f.next());
      
   }
   return results;
}
Esempio n. 3
0
vector<FindResult>
Vision::findChanges(FindInput input){
   vector<FindResult> results;
   Mat source = input.getSourceMat();
   Mat image = input.getTargetMat();
   ChangeFinder f(source);
   f.find(image);
   while (f.hasNext() && (results.size() < input.getLimit())){
      results.push_back(f.next());
   }
   vector<FindResult> final_results;
   int n = input.getLimit();
   if(n < results.size()){
      copy(results.begin(), results.begin()+n, final_results.begin());
      return final_results;
   }
   else return results;
}
Esempio n. 4
0
static vector<FindResult>
find_text(FindInput& input){

   vector<FindResult> results;

   Mat source = input.getSourceMat();
   if(!source.rows || !source.cols)
      return results;

   TextFinder f(source);
   if (input.isFindingAll()){

      int maxReturn = Vision::getParameter("FindAllMaxReturn");
      f.find_all(input.getTargetText().c_str(), input.getSimilarity());
      while (f.hasNext() && results.size() < maxReturn){
         results.push_back(f.next());
      }
   }
   else{
      f.find(input.getTargetText().c_str(), input.getSimilarity());
      if (f.hasNext())
         results.push_back(f.next());
   }


/*
   Mat result_image = source * 0.5;
   for (vector<FindResult>::iterator it = results.begin();
        it != results.end(); ++it){

      FindResult& r = *it;

      Point pt(r.x,r.y);
      putText(result_image, input.getTargetText(), pt,
              FONT_HERSHEY_SIMPLEX, 0.3, Color::RED);

   }
   VisualLogger::setEnabled(enable_visual_log);
   sualLogger::log("FindText-Result", result_image);
 */


   return results;
}
Esempio n. 5
0
static vector<FindResult> 
find_button(FindInput& input){
   
   vector<FindResult> results;
   
   Mat screen = input.getSourceMat();
   
   vector<Blob> blobs;
   cvgui::findBoxes(screen, blobs);
   
   
   VisualLogger::setEnabled(false);
   
   for (vector<Blob>::iterator it = blobs.begin();
        it != blobs.end(); ++it){
      Blob& blob = *it;
      
      
      if (blob.width < 10)
         continue;
      
      Util::growRect(blob, -3, 0, screen);
      
      Mat blob_image(screen, blob);
      
      FindResult result(blob.x,blob.y,blob.width,blob.height,1);      
      result.text = Vision::recognize(blob_image);
      
      if (result.text.empty())
         continue;
      
      
      string target_text = input.getTargetText();
      if (!target_text.empty()){
         
         int d;
         d = OCR::findEditDistance(target_text.c_str(),
                                            result.text.c_str(),
                                            3);
         
         if (d < 2){
            results.push_back(result);  
         }
      }else{
         results.push_back(result);
      }
      
      // if we only need to find one result, and we already have one result
      if (!input.isFindingAll() && !results.empty()){
         break;
      }
      
   }
   
   
   Mat result_image = screen * 0.5;
   for (vector<FindResult>::iterator it = results.begin();
        it != results.end(); ++it){
      
      FindResult& r = *it;
      
      Point pt(r.x,r.y);
      putText(result_image, r.text, pt,  
              FONT_HERSHEY_SIMPLEX, 0.3, Color::RED);
      
      
      
   }
   
   VisualLogger::setEnabled(enable_visual_log);
   VisualLogger::log("Buttons-OCR", result_image);
   
   return results;
}