0
点赞
收藏
分享

微信扫一扫

Java-OpenCV Sobel

月白色的大狒 2022-09-08 阅读 236


/**
* Get the Sobel Mat of input image!
* @param image The input image.
* @return
public Mat getSobelMat(Mat image) {
if (image.empty()) {
System.out.println("Please check the input image!");
return image;
}

Mat gray = image.clone();
if (3 == gray.channels()) {
Imgproc.cvtColor(gray, gray, Imgproc.COLOR_BGR2GRAY);
}

Mat grad = new Mat();
Mat grad_x = new Mat();
Mat grad_y = new Mat();
Mat abs_grad_x = new Mat();
Mat abs_grad_y = new Mat();
final int scharr_scale = 1;
final int scharr_delta = 0;
final int scharr_ddpeth = CvType.CV_16S;
//Imgproc.Scharr(grayImg, grad_x, scharr_ddpeth, 1, 0, scharr_scale, scharr_delta, Core.BORDER_DEFAULT);
//Imgproc.Scharr(grayImg, grad_y, scharr_ddpeth, 0, 1, scharr_scale, scharr_delta, Core.BORDER_DEFAULT);
Imgproc.Sobel(gray, grad_x, scharr_ddpeth, 1, 0, 3, scharr_scale, scharr_delta, Core.BORDER_DEFAULT);
Imgproc.Sobel(gray, grad_y, scharr_ddpeth, 0, 1, 3,scharr_scale, scharr_delta, Core.BORDER_DEFAULT);
Core.convertScaleAbs(grad_x, abs_grad_x);
Core.convertScaleAbs(grad_y, abs_grad_y);
Core.addWeighted(abs_grad_x, 0.5, abs_grad_y, 0.5, 0, grad);
return


举报

相关推荐

0 条评论