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


Java Imgproc.Sobel方法代码示例

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


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

示例1: doSobel

import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
/**
 * Apply Sobel
 *
 * @param frame the current frame
 * @return an image elaborated with Sobel derivation
 */
private Mat doSobel(Mat frame) {
    // init
    Mat grayImage = new Mat();
    Mat detectedEdges = new Mat();
    int scale = 1;
    int delta = 0;
    int ddepth = CvType.CV_16S;
    Mat grad_x = new Mat();
    Mat grad_y = new Mat();
    Mat abs_grad_x = new Mat();
    Mat abs_grad_y = new Mat();

    // reduce noise with a 3x3 kernel
    Imgproc.GaussianBlur(frame, frame, new Size(3, 3), 0, 0, Core.BORDER_DEFAULT);

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

    // Gradient X
    // Imgproc.Sobel(grayImage, grad_x, ddepth, 1, 0, 3, scale,
    // this.threshold.getValue(), Core.BORDER_DEFAULT );
    Imgproc.Sobel(grayImage, grad_x, ddepth, 1, 0);
    Core.convertScaleAbs(grad_x, abs_grad_x);

    // Gradient Y
    // Imgproc.Sobel(grayImage, grad_y, ddepth, 0, 1, 3, scale,
    // this.threshold.getValue(), Core.BORDER_DEFAULT );
    Imgproc.Sobel(grayImage, grad_y, ddepth, 0, 1);
    Core.convertScaleAbs(grad_y, abs_grad_y);

    // Total Gradient (approximate)
    Core.addWeighted(abs_grad_x, 0.5, abs_grad_y, 0.5, 0, detectedEdges);
    // Core.addWeighted(grad_x, 0.5, grad_y, 0.5, 0, detectedEdges);

    return detectedEdges;

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

示例2: Sobel

import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
void Sobel() {
    Mat grayMat = new Mat();
    Mat sobel = new Mat(); //Mat to store the final result

    //Matrices to store gradient and absolute gradient respectively
    Mat grad_x = new Mat();
    Mat abs_grad_x = new Mat();

    Mat grad_y = new Mat();
    Mat abs_grad_y = new Mat();

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

    //Calculating gradient in horizontal direction
    Imgproc.Sobel(grayMat, grad_x, CvType.CV_16S, 1, 0, 3, 1, 0);

    //Calculating gradient in vertical direction
    Imgproc.Sobel(grayMat, grad_y, CvType.CV_16S, 0, 1, 3, 1, 0);

    //Calculating absolute value of gradients in both the direction
    Core.convertScaleAbs(grad_x, abs_grad_x);
    Core.convertScaleAbs(grad_y, abs_grad_y);

    //Calculating the resultant gradient
    Core.addWeighted(abs_grad_x, 0.5, abs_grad_y, 0.5, 1, sobel);

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


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