王兵 2 years ago
parent 8db1ea7b3e
commit 1968b3bb27

Binary file not shown.

After

Width:  |  Height:  |  Size: 310 KiB

@ -0,0 +1,89 @@
package base;
import org.opencv.core.Mat;
import org.opencv.core.Point;
import org.opencv.core.Scalar;
import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.imgproc.Imgproc;
import java.io.File;
/**
*
*/
public class ImageCorrect extends DllLoad {
public static void main(String[] args) {
File file = new File("imgs/5.png");
Mat src = Imgcodecs.imread(file.getAbsolutePath());
// {
// Mat gray = new Mat();
// Imgproc.cvtColor(src, gray, Imgproc.COLOR_BGR2GRAY);
// show(gray);
//
// Mat dst = new Mat();
// Imgproc.Canny(gray, dst, 10, 100, 3);
// show(dst);
//
// Mat lines = new Mat();
// // threshold阔值越高检测精度越高
// Imgproc.HoughLinesP(dst, lines, 1, Math.PI / 180, 50, 20, 100);
//
// Mat houghLines = new Mat();
// houghLines.create(dst.rows(), dst.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(src, pt1, pt2, new Scalar(255, 0, 0), 1);
// }
//
// show(src);
// }
{
Mat grayMat = new Mat();
Mat cannyEdges = new Mat();
Mat lines = new Mat();
Imgproc.cvtColor(src, grayMat, Imgproc.COLOR_RGB2GRAY);
Imgproc.Canny(grayMat, cannyEdges, 10, 100);
Imgproc.HoughLinesP(cannyEdges, lines, 1, Math.PI / 180, 50, 20, 20);
//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(src, pt1, pt2, new Scalar(255, 0, 0), 1);
}
show(src);
}
System.exit(0);
}
}
Loading…
Cancel
Save

Powered by TurnKey Linux.