当前位置: 首页>>代码示例>>Java>>正文


Java Imgproc.Canny方法代码示例

本文整理汇总了Java中org.opencv.imgproc.Imgproc.Canny方法的典型用法代码示例。如果您正苦于以下问题:Java Imgproc.Canny方法的具体用法?Java Imgproc.Canny怎么用?Java Imgproc.Canny使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.opencv.imgproc.Imgproc的用法示例。


在下文中一共展示了Imgproc.Canny方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: doCanny

import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
/**
 * Apply Canny
 *
 * @param frame the current frame
 * @return an image elaborated with Canny
 */
private Mat doCanny(Mat frame) {
    // init
    Mat grayImage = new Mat();
    Mat detectedEdges = new Mat();

    // convert to grayscale
    Imgproc.cvtColor(frame, grayImage, Imgproc.COLOR_BGR2GRAY);

    // reduce noise with a 3x3 kernel
    Imgproc.blur(grayImage, detectedEdges, new Size(3, 3));

    // canny detector, with ratio of lower:upper threshold of 3:1
    Imgproc.Canny(detectedEdges, detectedEdges, threshold.getValue(), threshold.getValue() * 3);

    // using Canny's output as a mask, display the result
    Mat dest = new Mat();
    frame.copyTo(dest, detectedEdges);

    return dest;
}
 
开发者ID:Evegen55,项目名称:main_carauto_board,代码行数:27,代码来源:MagicTabController.java

示例2: HoughLines

import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
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);

    }
 
开发者ID:johnhany,项目名称:MOAAP,代码行数:39,代码来源:MainActivity.java

示例3: Contours

import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
void Contours() {
    Mat grayMat = new Mat();
    Mat cannyEdges = new Mat();
    Mat hierarchy = new Mat();

    List<MatOfPoint> contourList = new ArrayList<MatOfPoint>(); //A list to store all the contours

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

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

    //finding contours
    Imgproc.findContours(cannyEdges, contourList, hierarchy, Imgproc.RETR_LIST, Imgproc.CHAIN_APPROX_SIMPLE);

    //Drawing contours on a new image
    Mat contours = new Mat();
    contours.create(cannyEdges.rows(), cannyEdges.cols(), CvType.CV_8UC3);
    Random r = new Random();
    for (int i = 0; i < contourList.size(); i++) {
        Imgproc.drawContours(contours, contourList, i, new Scalar(r.nextInt(255), r.nextInt(255), r.nextInt(255)), -1);
    }
    //Converting Mat back to Bitmap
    Utils.matToBitmap(contours, currentBitmap);
    imageView.setImageBitmap(currentBitmap);
}
 
开发者ID:johnhany,项目名称:MOAAP,代码行数:27,代码来源:MainActivity.java

示例4: canny

import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
public static void canny(String oriImg, String dstImg, int threshold) {
	System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
	final Mat img = Imgcodecs.imread(oriImg);
	Imgproc.cvtColor(img, img, Imgproc.COLOR_BGR2GRAY);
	//
	Imgproc.Canny(img, img, threshold, threshold * 3, 3, true);
	//
	Imgcodecs.imwrite(dstImg, img);
}
 
开发者ID:zylo117,项目名称:SpotSpotter,代码行数:10,代码来源:CannyEdgeDetector.java

示例5: getCanny

import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
protected Mat getCanny(Mat gray) {
  Mat threshold = new Mat();
  Mat canny = new Mat();
  // last paramter 8 is using OTSU algorithm
  double high_threshold = Imgproc.threshold(gray, threshold, 0, 255, 8);
  double low_threshold = high_threshold * 0.5;
  Imgproc.Canny(gray, canny, low_threshold, high_threshold);
  return canny;
}
 
开发者ID:beast,项目名称:react-native-scan-doc,代码行数:10,代码来源:RNScanDocModule.java

示例6: apply_filters

import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
public Mat apply_filters(Mat input_mat) {
    Mat blurred = new Mat();
    Mat edges = new Mat();
    Mat structure = new Mat();
    Imgproc.GaussianBlur(input_mat,blurred,new Size(3,3),1); //Jack-ify the image
    Imgproc.bilateralFilter(blurred,blurred,11,17,17);
    Imgproc.Canny(blurred,edges,20,50);
    structure = Imgproc.getStructuringElement(Imgproc.MORPH_RECT,new Size(45,45));
    Imgproc.morphologyEx(edges,edges,Imgproc.MORPH_CLOSE,structure);
    return edges;
}
 
开发者ID:SCHS-Robotics,项目名称:Team9261-2017-2018,代码行数:12,代码来源:GlyphDetector.java

示例7: Canny

import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
void Canny() {
    Mat grayMat = new Mat();
    Mat cannyEdges = new Mat();
    //Converting the image to grayscale
    Imgproc.cvtColor(originalMat, grayMat, Imgproc.COLOR_BGR2GRAY);

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

    //Converting Mat back to Bitmap
    Utils.matToBitmap(cannyEdges, currentBitmap);
    imageView.setImageBitmap(currentBitmap);
}
 
开发者ID:johnhany,项目名称:MOAAP,代码行数:13,代码来源:MainActivity.java

示例8: HoughCircles

import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
void HoughCircles() {
    Mat grayMat = new Mat();
    Mat cannyEdges = new Mat();
    Mat circles = new Mat();

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

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

    Imgproc.HoughCircles(cannyEdges, circles, Imgproc.CV_HOUGH_GRADIENT, 1, cannyEdges.rows() / 15);//, grayMat.rows() / 8);

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

    //Drawing lines on the image
    for (int i = 0; i < circles.cols(); i++) {
        double[] parameters = circles.get(0, i);
        double x, y;
        int r;

        x = parameters[0];
        y = parameters[1];
        r = (int) parameters[2];

        Point center = new Point(x, y);

        //Drawing circles on an image
        Imgproc.circle(houghCircles, center, r, new Scalar(255, 0, 0), 1);
    }

    //Converting Mat back to Bitmap
    Utils.matToBitmap(houghCircles, currentBitmap);
    imageView.setImageBitmap(currentBitmap);
}
 
开发者ID:johnhany,项目名称:MOAAP,代码行数:36,代码来源:MainActivity.java

示例9: HoughLines

import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
public Mat HoughLines(Mat image) {
    Mat grayMat = new Mat();
    Mat cannyEdges = new Mat();
    Mat lines = new Mat();

    Imgproc.cvtColor(image, grayMat, Imgproc.COLOR_RGB2GRAY);

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

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

    return lines;

}
 
开发者ID:jocstech,项目名称:AndroidCameraSudokuSolver,代码行数:15,代码来源:GridRecognizer.java


注:本文中的org.opencv.imgproc.Imgproc.Canny方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。