IplImage residual = images[3]; IplImage mask = images[4]; int width = roi.width(); int height = roi.height(); int channels = residual.nChannels(); relativeResidual = IplImage.createIfNotCompatible(relativeResidual, mask); 255, 255*settings.thresholdLow/settings.thresholdHigh, 255); int roiX = roi.x(), roiY = roi.y(); cvSetImageROI(binaryImage, roi);
projectorBufferRing.position(0); ProjectorBuffer pb0 = projectorBufferRing.get(); pb0.roi.x(0).y(0).width(pb0.image.width()).height(pb0.image.height()); realityAugmentor.update(pb0.image, pb0.roi, -1, -1, false, parameters); realityAugmentor.getUpdateRect(); pb.roi.x(0).y(0).width(pb.image.width()).height(pb.image.height()); cvResetImageROI(pb.image); cvCopy(pb0.image, pb.image);
if (virtualSettings == null) { cvSet(projectorImage, CvScalar.WHITE); maxroi.x(0).y(0).width(pw).height(ph); return null; roi.x(0).y(0).width(projectorImage.width()).height(projectorImage.height()); maxroi.x (Math.min(prevroi.x(), roi.x())); maxroi.y (Math.min(prevroi.y(), roi.y())); maxroi.width (Math.max(prevroi.x()+prevroi.width(), roi.x()+roi.width()) - maxroi.x()); maxroi.height(Math.max(prevroi.y()+prevroi.height(), roi.y()+roi.height()) - maxroi.y()); prevroi.x(roi.x()).y(roi.y()).width(roi.width()).height(roi.height()); cvResize(frameImage, projectorImage); maxroi.x(0).y(0).width(pw).height(ph);
temproi.x(0).y(0).width(width).height(height); int padX = (int)Math.round(settings.displacementMax*width); int padY = (int)Math.round(settings.displacementMax*height); IplROI ir = target[i-1].roi(); if (ir != null) { temproi.x(ir.xOffset()/2); temproi.width (ir.width() /2); temproi.y(ir.yOffset()/2); temproi.height(ir.height()/2); cvSetImageROI(target[i], temproi); } else {
if (ir != null) { int align = 1<<(maxLevel+1); roi.x(Math.max(0, (int)Math.floor((double)ir.xOffset()/align)*align)); roi.y(Math.max(0, (int)Math.floor((double)ir.yOffset()/align)*align)); roi.width (Math.min(projectorImage0.width(), (int)Math.ceil((double)ir.width() /align)*align)); roi.height(Math.min(projectorImage0.height(), (int)Math.ceil((double)ir.height()/align)*align)); cvSetImageROI(projectorImage0, roi); cvSetImageROI(projectorImage[minLevel], roi); roi.x(ir.xOffset()/2); roi.width (ir.width() /2); roi.y(ir.yOffset()/2); roi.height(ir.height()/2); cvSetImageROI(projectorImage[i], roi); } else {
System.out.println("retreived roi: " + roi.x() + " " + roi.y() + " " + roi.width() + " " + roi.height()); long startTime = System.currentTimeMillis(); settings.detector.detectAndCompute(cvarrToMat(image), roi.x(0); roi.y(0); roi.width(image.width()); roi.height(image.height()); cvSetImageROI(image, defaultRoi); return null; roi.x(0); roi.y(0); roi.width(image.width()); roi.height(image.height()); cvSetImageROI(image, defaultRoi); return null; System.out.println("Updated roi: " + roi.x() + " " + roi.y()); return dstCorners;
protected GNImageAligner(ImageTransformer transformer, Parameters initialParameters) { this.n = initialParameters.size(); this.srcRoiPts = CvMat.create(4, 1, CV_64F, 2); this.dstRoiPts = CvMat.create(4, 1, CV_64F, 2); this.dstRoiPtsArray = new CvPoint(4); this.roi = new CvRect(); this.temproi = new CvRect(); this.transformer = transformer; this.parameters = initialParameters.clone(); this.parametersArray = new Parameters[] { parameters }; this.tempParameters = new Parameters[n]; for (int i = 0; i < tempParameters.length; i++) { this.tempParameters[i] = initialParameters.clone(); } subspaceParameters = parameters.getSubspace(); if (subspaceParameters != null) { tempSubspaceParameters = new double[Parallel.getNumThreads()][]; for (int i = 0; i < tempSubspaceParameters.length; i++) { tempSubspaceParameters[i] = subspaceParameters.clone(); } // for (double d : subspaceParameters) { // System.out.print(d + " "); // } // System.out.println(); } }
/** * Similar to cvBoundingRect(), but can also pad the output with some extra * pixels, useful to use as ROI for operations with interpolation. Further * aligns the region to specified boundaries, for easier vectorization and * subsampling, and also uses on input the rect argument as a maximum boundary. */ public static CvRect boundingRect(double[] contour, CvRect rect, int padX, int padY, int alignX, int alignY) { double minX = contour[0]; double minY = contour[1]; double maxX = contour[0]; double maxY = contour[1]; for (int i = 1; i < contour.length/2; i++) { double x = contour[2*i ]; double y = contour[2*i+1]; minX = Math.min(minX, x); minY = Math.min(minY, y); maxX = Math.max(maxX, x); maxY = Math.max(maxY, y); } int x = (int)Math.floor(Math.max(rect.x(), minX-padX)/alignX)*alignX; int y = (int)Math.floor(Math.max(rect.y(), minY-padY)/alignY)*alignY; int width = (int)Math.ceil(Math.min(rect.width(), maxX+padX)/alignX)*alignX - x; int height = (int)Math.ceil(Math.min(rect.height(), maxY+padY)/alignY)*alignY - y; return rect.x(x).y(y).width(Math.max(0, width)).height(Math.max(0, height)); }
@Override protected void addContent(PLayer layer) { for (CvRect blob : blobs){ PPath rect = PPath.createRectangle(blob.x(),blob.y(),blob.width(),blob.height()); Random numGen = new Random(); Color randomColor = new Color(numGen.nextInt(256), numGen.nextInt(256), numGen.nextInt(256)); //rect.setStrokePaint(randomColor); rect.setStrokePaint(Color.cyan); rect.setStroke(new BasicStroke(5)); rect.setPaint(null); layer.addChild(rect); PText sizeText = new PText("" + blob.width() + "x" + blob.height()); sizeText.setOffset(blob.x(),blob.y()); sizeText.setHorizontalAlignment(0f); sizeText.setPaint(Color.black); sizeText.setTextPaint(Color.white); layer.addChild(sizeText); } } }
@Override protected List<ScreenRegion> getUnorderedMatches(ScreenRegion screenRegion) { BufferedImage image = screenRegion.capture(); IplImage foregroundMask = VisionUtils.computeForegroundMaskOf(IplImage.createFrom(image)); List<CvRect> blobs = VisionUtils.detectBlobs(foregroundMask); List<ScreenRegion> results = Lists.newArrayList(); for (CvRect b : blobs){ System.out.println(String.format("%d,%d,%d,%d",b.x(),b.y(),b.width(),b.height())); ScreenRegion r = screenRegion.getRelativeScreenRegion(b.x(), b.y(), b.width(), b.height()); results.add(r); } return results; }
protected void doRoi() { transformer.transform(srcRoiPts, dstRoiPts, parameters, false); double[] pts = dstRoiPts.get(); for (int i = 0; i < pts.length; i++) { pts[i] /= (1<<pyramidLevel); } roi.x(0).y(0).width(mask[pyramidLevel].width()).height(mask[pyramidLevel].height()); // Add +3 all around because cvWarpPerspective() needs it for interpolation, // and there seems to be something funny with memory alignment and // ROIs, so let's align our ROI to a 16 byte boundary just in case.. JavaCV.boundingRect(pts, roi, 3, 3, 16, 1); //System.out.println(roi); cvSetZero(mask[pyramidLevel]); dstRoiPtsArray.put((byte)16, pts); cvFillConvexPoly(mask[pyramidLevel], dstRoiPtsArray, 4, CvScalar.WHITE, 8, 16); }
public boolean isSteady() { if (tipX >= 0 && tipY >= 0 && prevTipX >= 0 && prevTipY >= 0) { double dx = tipX - prevTipX; double dy = tipY - prevTipY; int imageSize = (roi.width() + roi.height())/2; double steadySize = settings.clickSteadySize*imageSize; return dx*dx + dy*dy < steadySize*steadySize; } return false; } public boolean isClick() {
@Override protected List<ScreenRegion> getUnorderedMatches(ScreenRegion screenRegion) { BufferedImage image = screenRegion.capture(); IplImage foregroundMask = VisionUtils.computeForegroundMaskOf(IplImage.createFrom(image)); List<CvRect> blobs = VisionUtils.detectBlobs(foregroundMask); List<ScreenRegion> results = Lists.newArrayList(); for (CvRect b : blobs){ System.out.println(String.format("%d,%d,%d,%d",b.x(),b.y(),b.width(),b.height())); ScreenRegion r = screenRegion.getRelativeScreenRegion(b.x(), b.y(), b.width(), b.height()); results.add(r); } return results; }