private void checkChanges(ScreenImage img) { if (Settings.UseImageFinder) { if (_lastImageMat.empty()) { _lastImageMat = Image.createMat(img.getImage()); return; } ImageFinder f = new ImageFinder(_lastImageMat); f.setMinChanges(_minChanges); org.opencv.core.Mat current = Image.createMat(img.getImage()); if (f.hasChanges(current)) { // TODO implement ChangeObserver: processing changes Debug.log(3, "ChangeObserver: processing changes"); } _lastImageMat = current; } else { if (_lastImgMat == null) { _lastImgMat = Image.convertBufferedImageToMat(img.getImage()); return; } FindInput fin = new FindInput(); fin.setSource(_lastImgMat); Mat target = Image.convertBufferedImageToMat(img.getImage()); fin.setTarget(target); fin.setSimilarity(_minChanges); FindResults results = Vision.findChanges(fin); try { callChangeObserver(results); } catch (AWTException e) { Debug.error("EventMgr: checkChanges: ", e.getMessage()); } _lastImgMat = target; } }
/** * interactive region create with given message: lets the user draw the rectangle using the mouse * * @return the region */ public Region selectRegion(final String msg) { ScreenImage sim = userCapture(msg); if (sim == null) { return null; } Rectangle r = sim.getROI(); return Region.create((int) r.getX(), (int) r.getY(), (int) r.getWidth(), (int) r.getHeight()); }
// draws an image of the current map public void exportToPNG() { JFileChooser saveFileChooser = new JFileChooser(); int returnVal = saveFileChooser.showSaveDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = saveFileChooser.getSelectedFile(); String filename = file.getName(); if (!filename.contains(".")) filename = file.getPath() + ".png"; else filename = file.getPath(); try { JFrame frame = new JFrame(); mxGraphComponent graphCpnt = new mxGraphComponent(panGraph); frame.setContentPane(graphCpnt); BufferedImage bi = ScreenImage.createImage(graphCpnt); ScreenImage.writeImage(bi, filename); } catch (IOException ex) { Logger.getLogger(RelationMapPanel.class.getName()).log(Level.SEVERE, null, ex); } } }
@Override public ScreenImage capture(Rectangle rect) { Debug.log(5, "capture: " + rect); BufferedImage ret = new BufferedImage(rect.width, rect.height, BufferedImage.TYPE_INT_RGB); Graphics2D g2d = ret.createGraphics(); for (int i = 0; i < Screen.getNumberScreens(); i++) { Rectangle scrBound = Screen.getBounds(i); if (scrBound.intersects(rect)) { Rectangle inter = scrBound.intersection(rect); Debug.log(5, "scrBound: " + scrBound + ", inter: " + inter); int ix = inter.x, iy = inter.y; inter.x -= scrBound.x; inter.y -= scrBound.y; ScreenImage img = robots[i].captureScreen(inter); g2d.drawImage(img.getImage(), ix - rect.x, iy - rect.y, null); } } g2d.dispose(); return new ScreenImage(rect, ret); }