Java Code Examples for org.opencv.imgproc.Imgproc.line()

The following are Jave code examples for showing how to use line() of the org.opencv.imgproc.Imgproc class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: MOAAP   File: MainActivity.java   Source Code and License Vote up 11 votes
public Mat onCameraFrame(CvCameraViewFrame inputFrame) {
        final int viewMode = mViewMode;
        switch (viewMode) {
            case VIEW_MODE_OPTICAL_FLOW:
                mGray = inputFrame.gray();
                if(features.toArray().length==0){
                    int rowStep = 50, colStep = 100;
                    int nRows = mGray.rows()/rowStep, nCols = mGray.cols()/colStep;

//                    Log.d(TAG, "\nRows: "+nRows+"\nCols: "+nCols+"\n");

                    Point points[] = new Point[nRows*nCols];
                    for(int i=0; i<nRows; i++){
                        for(int j=0; j<nCols; j++){
                            points[i*nCols+j]=new Point(j*colStep, i*rowStep);
//                            Log.d(TAG, "\nRow: "+i*rowStep+"\nCol: "+j*colStep+"\n: ");
                        }
                    }

                    features.fromArray(points);

                    prevFeatures.fromList(features.toList());
                    mPrevGray = mGray.clone();
                    break;
                }

                nextFeatures.fromArray(prevFeatures.toArray());
                Video.calcOpticalFlowPyrLK(mPrevGray, mGray, prevFeatures, nextFeatures, status, err);

                List<Point> prevList=features.toList(), nextList=nextFeatures.toList();
                Scalar color = new Scalar(255);

                for(int i = 0; i<prevList.size(); i++){
//                    Core.circle(mGray, prevList.get(i), 5, color);
                    Imgproc.line(mGray, prevList.get(i), nextList.get(i), color);
                }

                mPrevGray = mGray.clone();
                break;
            case VIEW_MODE_KLT_TRACKER:
                mGray = inputFrame.gray();

                if(features.toArray().length==0){
                    Imgproc.goodFeaturesToTrack(mGray, features, 10, 0.01, 10);
                    Log.d(TAG, features.toList().size()+"");
                    prevFeatures.fromList(features.toList());
                    mPrevGray = mGray.clone();
//                    prevFeatures.fromList(nextFeatures.toList());
                    break;
                }

//                OpticalFlow(mPrevGray.getNativeObjAddr(), mGray.getNativeObjAddr(), prevFeatures.getNativeObjAddr(), nextFeatures.getNativeObjAddr());
                Video.calcOpticalFlowPyrLK(mPrevGray, mGray, prevFeatures, nextFeatures, status, err);
                List<Point> drawFeature = nextFeatures.toList();
//                Log.d(TAG, drawFeature.size()+"");
                for(int i = 0; i<drawFeature.size(); i++){
                    Point p = drawFeature.get(i);
                    Imgproc.circle(mGray, p, 5, new Scalar(255));
                }
                mPrevGray = mGray.clone();
                prevFeatures.fromList(nextFeatures.toList());
                break;
            default: mViewMode = VIEW_MODE_KLT_TRACKER;
        }

        return mGray;
    }
 
Example 2
Project: MOAAP   File: MainActivity.java   Source Code and License Vote up 8 votes
void HoughLines() {

        Mat grayMat = new Mat();
        Mat cannyEdges = new Mat();
        Mat lines = new Mat();

        //Converting the image to grayscale
        Imgproc.cvtColor(originalMat, grayMat, Imgproc.COLOR_BGR2GRAY);

        Imgproc.Canny(grayMat, cannyEdges, 10, 100);

        Imgproc.HoughLinesP(cannyEdges, lines, 1, Math.PI / 180, 50, 20, 20);

        Mat houghLines = new Mat();
        houghLines.create(cannyEdges.rows(), cannyEdges.cols(), CvType.CV_8UC1);

        //Drawing lines on the image
        for (int i = 0; i < lines.cols(); i++) {
            double[] points = lines.get(0, i);
            double x1, y1, x2, y2;

            x1 = points[0];
            y1 = points[1];
            x2 = points[2];
            y2 = points[3];

            Point pt1 = new Point(x1, y1);
            Point pt2 = new Point(x2, y2);

            //Drawing lines on an image
            Imgproc.line(houghLines, pt1, pt2, new Scalar(255, 0, 0), 1);
        }

        //Converting Mat back to Bitmap
        Utils.matToBitmap(houghLines, currentBitmap);
        imageView.setImageBitmap(currentBitmap);

    }
 
Example 3
Project: Paper-Melody   File: Util.java   Source Code and License Vote up 5 votes
public static void drawContourByPoints(Mat im, List<List<Point>> contours, Scalar color) {
    for (List<Point> contour : contours) {
        int len = contour.size();
        for (int i = 0; i < len; ++i) {
            int next_i = (i + 1) % len;
            Imgproc.line(im, contour.get(i), contour.get(next_i), color, 2);
        }
    }
}
 
Example 4
Project: Paper-Melody   File: Util.java   Source Code and License Vote up 5 votes
public static void fillContour(Mat im, List<Point> contour, Point seed) {
    Mat mask = Mat.zeros(new Size(im.width() + 2, im.height() + 2), CvType.CV_8UC1);

    int len = contour.size();
    for (int i = 0; i < len; ++i) {
        int next_i = (i + 1) % len;
        Imgproc.line(im, contour.get(i), contour.get(next_i), Util.SCALAR_WHITE, 2);
    }
    Imgproc.floodFill(im, mask, seed, Util.SCALAR_WHITE);
}
 
Example 5
Project: FlashLib   File: CvProcessing.java   Source Code and License Vote up 5 votes
/**
 * Draws an array of analysis objects unto a mat.
 * 
 * @param feed mat to draw on
 * @param color color to draw with
 * @param an array of analysis to draw
 * @see Imgproc#circle(Mat, Point, int, Scalar)
 */
public static void drawPostProcessing(Mat feed, Scalar color, Analysis... an){
	for (int i = 0; i < an.length; i++) {
		Analysis analysis = an[i];
		Imgproc.circle(feed, 
				new Point(analysis.getDouble(Analysis.PROP_CENTER_X), analysis.getDouble(Analysis.PROP_CENTER_Y)), 
				3, color, 2);
	}
	Imgproc.line(feed, new Point(feed.width()/2, 0), new Point(feed.width()/2, feed.height()), new Scalar(0, 51, 255));
}
 
Example 6
Project: FTC2016   File: Drawing.java   Source Code and License Vote up 4 votes
public static void drawLine(Mat img, Point point1, Point point2, Color color, int thickness) {
    Imgproc.line(img, point1, point2, color.getScalarRGBA(), thickness);
}
 
Example 7
Project: SpotSpotter   File: Draw.java   Source Code and License Vote up 4 votes
public static void line_P2P(Mat inputmat, Point startP, Point endP) {
	Imgproc.line(inputmat, startP, endP, new Scalar(128, 200, 255), 8);
}
 
Example 8
Project: RobotIGS   File: Drawing.java   Source Code and License Vote up 4 votes
public static void drawLine(Mat img, Point point1, Point point2, Color color, int thickness) {
    Imgproc.line(img, point1, point2, color.getScalarRGBA(), thickness);
}