Exemple #1
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;
}
Exemple #2
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;
}