import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.core.Size;
import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.imgproc.Imgproc;
public class bianyuanjiance {
public static void main(String[] args) {
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
// Mat img = Highgui.imread("E:\\face7.jpg");//读图像
Mat image = Imgcodecs.imread("D:\\tup\\62.jpg");
Mat new_img = doCanny(image);
Imgcodecs.imwrite("D:\\tup\\622.jpg", new_img);// 写图像
}
private static Mat doCanny(Mat frame) {
// init
Mat grayImage = new Mat();
Mat detectedEdges = new Mat();
double threshold = 10;
// 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, threshold * 3);
// using Canny's output as a mask, display the result
Mat dest = new Mat();
frame.copyTo(dest, detectedEdges);
return dest;
}
}
import org.opencv.core.Mat;
import org.opencv.core.Size;
import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.imgproc.Imgproc;
public class bianyuanjiance {
public static void main(String[] args) {
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
// Mat img = Highgui.imread("E:\\face7.jpg");//读图像
Mat image = Imgcodecs.imread("D:\\tup\\62.jpg");
Mat new_img = doCanny(image);
Imgcodecs.imwrite("D:\\tup\\622.jpg", new_img);// 写图像
}
private static Mat doCanny(Mat frame) {
// init
Mat grayImage = new Mat();
Mat detectedEdges = new Mat();
double threshold = 10;
// 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, threshold * 3);
// using Canny's output as a mask, display the result
Mat dest = new Mat();
frame.copyTo(dest, detectedEdges);
return dest;
}
}