Package org.sikuli.core.search

Examples of org.sikuli.core.search.RegionMatch


      @Override
      protected void addContent(PLayer layer) {
        for (MatchHypothesis h : hypotheses){
          ModelPartMatch m1 = h.getTopLeft();
          ModelPartMatch m2 = h.getBottomRight();
          RegionMatch p1 = m1.getScoreMatch();
          RegionMatch p2 = m2.getScoreMatch();
          PPath line = PPath.createLine(p1.getX(),p1.getY(),p2.getX(),p2.getY());
          line.setStroke(new BasicStroke(2f));
          line.setStrokePaint(Color.red);
          layer.addChild(line);
         
         
          Point p = h.getExpectedBottomLeftPartModelLocation();
          PPath c = PPath.createRectangle(p.x,p.y,10,10);
          c.setStroke(new BasicStroke(2f));
          c.setStrokePaint(Color.green);
          layer.addChild(c);
         
          p = h.getExpectedTopRightPartModelLocation();
          c = PPath.createRectangle(p.x,p.y,10,10);
          c.setStroke(new BasicStroke(2f));
          c.setStrokePaint(Color.green);
          layer.addChild(c);
        }       
      }     
    };
    logger.step(hypothesesRenderer, "hypotheses");
         
    for (MatchHypothesis h1 : hypotheses){
           
      Point expectedLocation = h1.getExpectedTopRightPartModelLocation();
     
      // find if there is a matched part in the expected location
      // according to this hypothesis
     
      for (RegionMatch s2 : tms2){     
        Point seenLocation = s2.getLocation();
        boolean isMatchedPartSeenNearbyExpectedLocation = seenLocation.distance(expectedLocation.x,expectedLocation.y) < 5.0f;
        if (isMatchedPartSeenNearbyExpectedLocation){         
          h1.setTopRight(new ModelPartMatch(model.getTopRight(),s2));         
          break;
        }
      }
     
      expectedLocation = h1.getExpectedBottomLeftPartModelLocation();
       
      for (RegionMatch s4 : tms4){
        Point seenLocation = s4.getLocation();
        boolean isMatchedPartSeenNearbyExpectedLocation = seenLocation.distance(expectedLocation.x, expectedLocation.y) < 5.0f;
        if (isMatchedPartSeenNearbyExpectedLocation){         
          h1.setBottomLeft(new ModelPartMatch(model.getBottomLeft(),s4));         
          break;
        }
      }
    }   
   
    logger.step(new MatchHypotheseRenderer(testImage, hypotheses), "hypotheses + other matched parts");
    //hypotheses.add(newHypothesis);
   
    // keep good hypotheses
    List<MatchHypothesis> goodHypotheses = Lists.newArrayList();
    for (MatchHypothesis h1 : hypotheses){
      if (h1.getScore() == 4){
        goodHypotheses.add(h1);
      }
    }
   
    // sort hypotheses by increasing sizes
    Collections.sort(goodHypotheses, new Comparator<MatchHypothesis>(){
      public int compare(MatchHypothesis arg0, MatchHypothesis arg1) {
        return arg0.getBounds().width * arg0.getBounds().height -
        arg1.getBounds().width * arg1.getBounds().height;
      }
    });
   
   
    Map<RegionMatch,Integer> alreadyUsedMatch = Maps.newHashMap();
       
    // remove overlapping hypotheses
    List<MatchHypothesis> nonOverlappingGoodHypotheses = Lists.newArrayList();
    for (MatchHypothesis h1 : goodHypotheses){
     
      if (alreadyUsedMatch.containsKey(h1.getTopLeft().getScoreMatch()) ||
          alreadyUsedMatch.containsKey(h1.getBottomLeft().getScoreMatch()) ||
          alreadyUsedMatch.containsKey(h1.getTopRight().getScoreMatch()) ||
          alreadyUsedMatch.containsKey(h1.getBottomRight().getScoreMatch())){
       
        // ignore
               
      }else{
        nonOverlappingGoodHypotheses.add(h1);
        alreadyUsedMatch.put(h1.getTopLeft().getScoreMatch(), 1);
        alreadyUsedMatch.put(h1.getBottomLeft().getScoreMatch(), 1);
        alreadyUsedMatch.put(h1.getTopRight().getScoreMatch(), 1);
        alreadyUsedMatch.put(h1.getBottomRight().getScoreMatch(), 1);
      }
    }
    logger.step(new MatchHypotheseRenderer(testImage, nonOverlappingGoodHypotheses), "non-overlapping good hypotheses");
   
   
   
    // collect the list of ScoreRegionMatch objects to return
    List<RegionMatch> matches = Lists.newArrayList();
    for (MatchHypothesis h1 : nonOverlappingGoodHypotheses){
      RegionMatch regionMatch = new RegionMatch(h1.getBounds());
      matches.add(regionMatch);
    }   
    return matches;   
  }
View Full Code Here


    @Override
    protected void addContent(PLayer layer) {
      for (MatchHypothesis h : hypotheses){
        ModelPartMatch m1 = h.getTopLeft();
        ModelPartMatch m2 = h.getBottomRight();
        RegionMatch p1 = m1.getScoreMatch();
        RegionMatch p2 = m2.getScoreMatch();
       
        // draw diagonal line       
//        PPath line = PPath.createLine(p1.getX(),p1.getY(),p2.getX(),p2.getY());
//        line.setStroke(new BasicStroke(2f));
//        line.setStrokePaint(Color.red);
//        layer.addChild(line);
       
       
        Rectangle bs = h.getBounds();
        PPath rect = PPath.createRectangle(bs.x,bs.y,bs.width,bs.height);
        rect.setStroke(new BasicStroke(2f));
        rect.setStrokePaint(Color.red);
        rect.setPaint(null);
        layer.addChild(rect);   
       
        // draw score
//        int score = h.getScore();
//        PText text = new PText(""+score);
//        text.setOffset(rect.getBounds().getCenterX(), rect.getBounds().y - 20);
//        text.setHorizontalAlignment(0.5f);
//        layer.addChild(text);
       
        ModelPartMatch m3 = h.getTopRight();
        ModelPartMatch m4 = h.getBottomLeft();
       
        if (m3 != null){
          RegionMatch p3 = m3.getScoreMatch();
          PPath c = PPath.createRectangle(p3.getX(),p3.getY(),p3.getWidth(),p3.getHeight());
          c.setStroke(new BasicStroke(2f));
          c.setStrokePaint(Color.blue);
          c.setTransparency(0.5f);
          layer.addChild(c);
        }
       
        if (m4 != null){
          RegionMatch p4 = m4.getScoreMatch();
          PPath c = PPath.createRectangle(p4.getX(),p4.getY(),p4.getWidth(),p4.getHeight());
          c.setStroke(new BasicStroke(2f));
          c.setStrokePaint(Color.green);
          c.setTransparency(0.5f);
          layer.addChild(c);
        }
View Full Code Here

TOP

Related Classes of org.sikuli.core.search.RegionMatch

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.