Example usage for org.opencv.core Point Point

List of usage examples for org.opencv.core Point Point

Introduction

In this page you can find the example usage for org.opencv.core Point Point.

Prototype

public Point(double x, double y) 

Source Link

Usage

From source file:com.shootoff.camera.autocalibration.AutoCalibrationManager.java

License:Open Source License

private Point findChessBoardSquareCenter(Mat corners, int row, int col) {
    if (row >= PATTERN_HEIGHT - 1 || col >= PATTERN_WIDTH - 1) {
        logger.warn("findChessBoardSquareColor invalid row or col {} {}", row, col);
        return null;
    }/*from   w ww  .j ava 2s  . co  m*/

    final Point topLeft = new Point(corners.get((row * PATTERN_WIDTH - 1) + col, 0)[0],
            corners.get((row * PATTERN_WIDTH - 1) + col, 0)[1]);
    final Point bottomRight = new Point(corners.get(((row + 1) * PATTERN_WIDTH - 1) + col + 1, 0)[0],
            corners.get(((row + 1) * PATTERN_WIDTH - 1) + col + 1, 0)[1]);

    final Point result = new Point((topLeft.x + bottomRight.x) / 2, (topLeft.y + bottomRight.y) / 2);

    if (logger.isTraceEnabled()) {
        logger.trace("findChessBoardSquareColor {}", corners.size());

        logger.trace("findChessBoardSquareColor {} {}", (row * PATTERN_WIDTH - 1) + col,
                ((row + 1) * PATTERN_WIDTH - 1) + col + 1);
        logger.trace("findChessBoardSquareColor {} {} {}", topLeft, bottomRight, result);
    }

    return result;
}

From source file:com.shootoff.camera.autocalibration.AutoCalibrationManager.java

License:Open Source License

private Point[] matOfPoint2fToPoints(MatOfPoint2f mat) {
    final Point[] points = new Point[4];
    points[0] = new Point(mat.get(0, 0)[0], mat.get(0, 0)[1]);
    points[1] = new Point(mat.get(1, 0)[0], mat.get(1, 0)[1]);
    points[2] = new Point(mat.get(2, 0)[0], mat.get(2, 0)[1]);
    points[3] = new Point(mat.get(3, 0)[0], mat.get(3, 0)[1]);

    return points;
}

From source file:com.superbool.easylpr.model.Transformation.java

public List<Point> transformSmallPointsToBigImage(List<Point> points) {
    List<Point> bigPoints = new ArrayList<>();
    for (int i = 0; i < points.size(); i++) {
        double bigX = (points.get(i).x * (regionInBigImage.width / smallImage.cols()));
        double bigY = (points.get(i).y * (regionInBigImage.height / smallImage.rows()));

        bigX = bigX + regionInBigImage.x;
        bigY = bigY + regionInBigImage.y;

        bigPoints.add(new Point(bigX, bigY));
    }/* w ww. j a  v a 2  s .c o m*/

    return bigPoints;
}

From source file:com.trandi.opentld.tld.BoundingBox.java

License:Apache License

Point[] points() {
    final List<Point> result = new ArrayList<Point>();
    final int stepx = (int) Math.ceil((width - 2 * POINTS_MARGIN_H) / POINTS_MAX_COUNT);
    final int stepy = (int) Math.ceil((height - 2 * POINTS_MARGIN_V) / POINTS_MAX_COUNT);
    for (int j = y + POINTS_MARGIN_V; j < y + height - POINTS_MARGIN_V; j += stepy) {
        for (int i = x + POINTS_MARGIN_H; i < x + width - POINTS_MARGIN_H; i += stepx) {
            result.add(new Point(i, j));
        }//from ww  w  .  ja v a 2 s.co m
    }
    Log.i(Util.TAG,
            "Points in BB: " + this + " stepx=" + stepx + " stepy=" + stepy + " RES size=" + result.size());
    return result.toArray(new Point[result.size()]);
}

From source file:com.trandi.opentld.tld.PatchGenerator.java

License:Apache License

void generate(final Mat image, Point pt, Mat patch, Size patchSize, final RNG rng) {
    final Mat T = new MatOfDouble();

    // TODO why is inverse not specified in the original C++ code
    generateRandomTransform(pt, new Point((patchSize.width - 1) * 0.5, (patchSize.height - 1) * 0.5), T, false);

    generate(image, T, patch, patchSize, rng);
}

From source file:com.trandi.opentld.tld.Tld.java

License:Apache License

/**
 * Generate Positive data // www  . ja v a 2s . c  om
 * Inputs: 
 * - good_boxes 
 * - best_box 
 * - bbhull
 * Outputs: 
 * - Positive fern features (pFerns) 
 * - Positive NN examples (pExample)
 */
void generatePositiveData(final Mat frame, final int numWarps, final Grid aGrid) {
    resizeZeroMeanStdev(frame.submat(aGrid.getBestBox()), _pExample, _params.patch_size);
    //Get Fern features on warped patches
    final Mat img = new Mat();
    Imgproc.GaussianBlur(frame, img, new Size(9, 9), 1.5);
    final BoundingBox bbhull = aGrid.getBBhull();
    final Mat warped = img.submat(bbhull);
    // centre of the hull
    final Point pt = new Point(bbhull.x + (bbhull.width - 1) * 0.5f, bbhull.y + (bbhull.height - 1) * 0.5f);

    _pFerns.clear();
    _pPatterns.clear();

    for (int i = 0; i < numWarps; i++) {
        if (i > 0) {
            // this is important as it introduces the necessary noise / fuziness in the initial examples such that the Fern classifier recognises similar shapes not only Exact ones ! 
            // warped is a reference to a subset of the img data, so this will affect the img object
            _patchGenerator.generate(frame, pt, warped, bbhull.size(), _rng);
        }

        final BoundingBox[] goodBoxes = aGrid.getGoodBoxes();
        for (BoundingBox goodBox : goodBoxes) {
            final Mat patch = img.submat(goodBox);
            final int[] allFernsHashCodes = _classifierFern.getAllFernsHashCodes(patch, goodBox.scaleIdx);
            _pFerns.add(new Pair<int[], Boolean>(allFernsHashCodes, true));

            //            // this will be used for display only
            //            final Mat tempPattern = new Mat();
            //            Imgproc.resize(patch, tempPattern, new Size(_params.patch_size, _params.patch_size));
            //            _pPatterns.add(tempPattern);
        }
    }

    Log.i(Util.TAG, "Positive examples generated( ferns: " + _pFerns.size() + " NN: 1/n )");
}

From source file:com.trandi.opentld.TLDView.java

License:Apache License

public TLDView(Context context, AttributeSet attrs) {
    super(context, attrs);
    _holder = getHolder();//from w ww  .j  a  v a  2s  .co  m

    // Init the PROPERTIES
    InputStream propsIS = null;
    try {
        propsIS = context.getResources().openRawResource(R.raw.parameters);
        _tldProperties = new Properties();
        _tldProperties.load(propsIS);
    } catch (IOException e) {
        Log.e(Util.TAG, "Can't load properties", e);
    } finally {
        if (propsIS != null) {
            try {
                propsIS.close();
            } catch (IOException e) {
                Log.e(Util.TAG, "Can't close props", e);
            }
        }
    }

    // listens to its own events
    setCvCameraViewListener(this);

    // DEBUG
    //_trackedBox = new BoundingBox(165,93,51,54, 0, 0);

    // LISTEN for touches of the screen, to define the BOX to be tracked
    final AtomicReference<Point> trackedBox1stCorner = new AtomicReference<Point>();
    final Paint rectPaint = new Paint();
    rectPaint.setColor(Color.rgb(0, 255, 0));
    rectPaint.setStrokeWidth(5);
    rectPaint.setStyle(Style.STROKE);

    setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            // re-init
            _errMessage = null;
            _tld = null;

            final Point corner = new Point(event.getX() - _canvasImgXOffset, event.getY() - _canvasImgYOffset);
            switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                trackedBox1stCorner.set(corner);
                Log.i(Util.TAG, "1st corner: " + corner);
                break;
            case MotionEvent.ACTION_UP:
                _trackedBox = new Rect(trackedBox1stCorner.get(), corner);
                Log.i(Util.TAG, "Tracked box DEFINED: " + _trackedBox);
                break;
            case MotionEvent.ACTION_MOVE:
                final android.graphics.Rect rect = new android.graphics.Rect(
                        (int) trackedBox1stCorner.get().x + _canvasImgXOffset,
                        (int) trackedBox1stCorner.get().y + _canvasImgYOffset,
                        (int) corner.x + _canvasImgXOffset, (int) corner.y + _canvasImgYOffset);
                final Canvas canvas = _holder.lockCanvas(rect);
                canvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR); // remove old rectangle
                canvas.drawRect(rect, rectPaint);
                _holder.unlockCanvasAndPost(canvas);
                break;
            }

            return true;
        }
    });
}

From source file:com.trandi.opentld.TLDView.java

License:Apache License

@Override
public Mat onCameraFrame(Mat originalFrame) {
    try {//ww  w .j a v  a  2  s.  c o m
        // Image is too big and this requires too much CPU for a phone, so scale everything down...
        Imgproc.resize(originalFrame, _workingFrame, WORKING_FRAME_SIZE);
        final Size workingRatio = new Size(originalFrame.width() / WORKING_FRAME_SIZE.width,
                originalFrame.height() / WORKING_FRAME_SIZE.height);
        // usefull to see what we're actually working with...
        _workingFrame.copyTo(originalFrame.submat(originalFrame.rows() - _workingFrame.rows(),
                originalFrame.rows(), 0, _workingFrame.cols()));

        if (_trackedBox != null) {
            if (_tld == null) { // run the 1st time only
                Imgproc.cvtColor(_workingFrame, _lastGray, Imgproc.COLOR_RGB2GRAY);
                _tld = new Tld(_tldProperties);
                final Rect scaledDownTrackedBox = scaleDown(_trackedBox, workingRatio);
                Log.i(Util.TAG, "Working Ration: " + workingRatio + " / Tracking Box: " + _trackedBox
                        + " / Scaled down to: " + scaledDownTrackedBox);
                try {
                    _tld.init(_lastGray, scaledDownTrackedBox);
                } catch (Exception eInit) {
                    // start from scratch, you have to select an init box again !
                    _trackedBox = null;
                    _tld = null;
                    throw eInit; // re-throw it as it will be dealt with later
                }
            } else {
                Imgproc.cvtColor(_workingFrame, _currentGray, Imgproc.COLOR_RGB2GRAY);

                _processFrameStruct = _tld.processFrame(_lastGray, _currentGray);
                drawPoints(originalFrame, _processFrameStruct.lastPoints, workingRatio, new Scalar(255, 0, 0));
                drawPoints(originalFrame, _processFrameStruct.currentPoints, workingRatio,
                        new Scalar(0, 255, 0));
                drawBox(originalFrame, scaleUp(_processFrameStruct.currentBBox, workingRatio),
                        new Scalar(0, 0, 255));

                _currentGray.copyTo(_lastGray);

                // overlay the current positive examples on the real image(needs converting at the same time !)
                //copyTo(_tld.getPPatterns(), originalFrame);
            }
        }
    } catch (Exception e) {
        _errMessage = e.getClass().getSimpleName() + " / " + e.getMessage();
        Log.e(Util.TAG, "TLDView PROBLEM", e);
    }

    if (_errMessage != null) {
        Imgproc.putText(originalFrame, _errMessage, new Point(0, 300), Core.FONT_HERSHEY_PLAIN, 1.3d,
                new Scalar(255, 0, 0), 2);
    }

    return originalFrame;
}

From source file:com.trandi.opentld.TLDView.java

License:Apache License

private static Point scaleUp(Point point, Size scale) {
    if (point == null || scale == null)
        return null;
    return new Point(point.x * scale.width, point.y * scale.height);
}

From source file:com.trandi.opentld.TLDView.java

License:Apache License

private static Point scaleDown(Point point, Size scale) {
    if (point == null || scale == null)
        return null;
    return new Point(point.x / scale.width, point.y / scale.height);
}