Java Code Examples for org.opencv.imgproc.Imgproc#line()
The following examples show how to use
org.opencv.imgproc.Imgproc#line() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OpenCVoperation.java From Human-hair-detection with Apache License 2.0 | 6 votes |
public void predict_hair_color() { Mat hsv_input = matrix9_finalOutput.clone(); List<Mat> channels= new ArrayList<>(); Mat hsv_histogram = new Mat(); MatOfFloat ranges = new MatOfFloat(0,180); MatOfInt histSize = new MatOfInt(255); Imgproc.cvtColor(hsv_input, hsv_input, Imgproc.COLOR_BGR2HSV); Core.split(hsv_input, channels); Imgproc.calcHist(channels.subList(0,1), new MatOfInt(0), new Mat(), hsv_histogram, histSize, ranges); int hist_w =256; int hist_h = 150; int bin_w =(int)Math.round(hist_w/histSize.get(0,0)[0]); Mat histImage= new Mat(hist_h,hist_w,CvType.CV_8UC3,new Scalar(0,0,0)); for(int i=1;i < histSize.get(0,0)[0];i++) { Imgproc.line(histImage, new Point(bin_w * (i - 1), hist_h - Math.round(hsv_histogram.get(i - 1, 0)[0])), new Point(bin_w * (i), hist_h - Math.round(hsv_histogram.get(i, 0)[0])), new Scalar(255,0,0),2); } Imgcodecs.imwrite(resultDirectory+"histogram_image.png",histImage); }
Example 2
Source File: PaintUtils.java From super-cloudops with Apache License 2.0 | 5 votes |
/** * 画矩形 * * @param src * @param r * @param scalar * @return */ public static Mat paintRect(Mat src, Rect r, Scalar scalar) { Point pt1 = new Point(r.x, r.y); Point pt2 = new Point(r.x + r.width, r.y); Point pt3 = new Point(r.x + r.width, r.y + r.height); Point pt4 = new Point(r.x, r.y + r.height); Imgproc.line(src, pt1, pt2, scalar, 5); Imgproc.line(src, pt2, pt3, scalar, 5); Imgproc.line(src, pt3, pt4, scalar, 5); Imgproc.line(src, pt4, pt1, scalar, 5); return src; }
Example 3
Source File: MainActivity.java From MOAAP with MIT License | 5 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 4
Source File: StepByStepTestActivity.java From CVScanner with GNU General Public License v3.0 | 5 votes |
void drawRect(Mat img, Point[] points) { if (img == null || points == null || points.length != 4) return; Point[] sorted = CVProcessor.sortPoints(points); Imgproc.line(img, sorted[0], sorted[1], new Scalar(250, 0, 0), 2); Imgproc.line(img, sorted[0], sorted[3], new Scalar(250, 0, 0), 2); Imgproc.line(img, sorted[1], sorted[2], new Scalar(250, 0, 0), 2); Imgproc.line(img, sorted[3], sorted[2], new Scalar(250, 0, 0), 2); }
Example 5
Source File: ProcessHelper.java From OpenCV-android with Apache License 2.0 | 4 votes |
/** * 直线检测 * * @param origin 原始bitmap * @param callback 回调 */ public void hough(Bitmap origin, ProcessCallback callback) { if (origin == null) { return; } try { Bitmap bitmap = Bitmap.createBitmap(origin.getWidth(), origin.getHeight(), Bitmap.Config.RGB_565); Utils.bitmapToMat(origin, rgbMat); Imgproc.cvtColor(rgbMat, grayMat, Imgproc.COLOR_RGB2GRAY); Mat edges = new Mat(); Mat src = new Mat(origin.getHeight(), origin.getWidth(), CvType.CV_8UC4); Mat lines = new Mat(); // 拷贝 Mat origination = new Mat(src.size(), CvType.CV_8UC1); src.copyTo(origination); // 通过Canny得到边缘图 Imgproc.cvtColor(origination, grayMat, Imgproc.COLOR_BGR2GRAY); Imgproc.Canny(grayMat, edges, 50, 200); // 获取直线图 Imgproc.HoughLinesP(edges, lines, 1, Math.PI / 180, 10, 0, 10); Mat houghLines = new Mat(); houghLines.create(edges.rows(), edges.cols(), CvType.CV_8UC1); // 绘制直线 for (int i = 0; i < lines.rows(); i++) { double[] points = lines.get(i, 0); if (null != points) { 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); Imgproc.line(houghLines, pt1, pt2, new Scalar(55, 100, 195), 3); } } Utils.matToBitmap(houghLines, bitmap); callback.onSuccess(bitmap); } catch (Exception e) { callback.onFailed(e.getMessage()); } }
Example 6
Source File: MainActivity.java From MOAAP with MIT License | 4 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 7
Source File: Drawing.java From FTCVision with MIT License | 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 8
Source File: Puzzle15Processor.java From OpenCV-AndroidSamples with MIT License | 4 votes |
private void drawGrid(int cols, int rows, Mat drawMat) { for (int i = 1; i < GRID_SIZE; i++) { Imgproc.line(drawMat, new Point(0, i * rows / GRID_SIZE), new Point(cols, i * rows / GRID_SIZE), new Scalar(0, 255, 0, 255), 3); Imgproc.line(drawMat, new Point(i * cols / GRID_SIZE, 0), new Point(i * cols / GRID_SIZE, rows), new Scalar(0, 255, 0, 255), 3); } }