|
@@ -27,15 +27,15 @@ public class CornerCheck {
|
|
|
try {
|
|
|
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
|
|
|
|
|
|
- final int maxCorners = 10000;
|
|
|
- int blockSize = 3;
|
|
|
+ final int maxCorners = 8;
|
|
|
+ int blockSize = 5;
|
|
|
final double qualityLevel = 0.01;
|
|
|
- double minDistance = 5.0;
|
|
|
- double k = 0.01;
|
|
|
+ double minDistance = 10;
|
|
|
+ double k = 0.06;
|
|
|
final boolean useHarrisDetector = false;
|
|
|
MatOfPoint corners = new MatOfPoint();
|
|
|
|
|
|
- Mat src = Imgcodecs.imread("D:\\data\\model\\src\\0.jpg");
|
|
|
+ Mat src = Imgcodecs.imread("D:\\data\\model\\src\\1.jpg");
|
|
|
if (src.empty()) {
|
|
|
throw new Exception("no file");
|
|
|
}
|
|
@@ -44,25 +44,8 @@ public class CornerCheck {
|
|
|
//灰度
|
|
|
Imgproc.cvtColor(src, gray, Imgproc.COLOR_RGB2GRAY);
|
|
|
Mat binary = new Mat();
|
|
|
- Mat getSrc = gray;
|
|
|
- Rect area = new Rect(324, 402, 218, 376);
|
|
|
+ Rect area = new Rect(324, 402, 218, 370);
|
|
|
Mat mask = new Mat(gray, area);
|
|
|
-// mask.setTo(new Scalar(0));
|
|
|
- for (int i = 0; i < 8; i++) {
|
|
|
- for (int j = 0; j < 8; j++) {
|
|
|
- System.out.print(mask.get(i, j)[0]);
|
|
|
- }
|
|
|
- System.out.println();
|
|
|
- }
|
|
|
-// System.out.println("+++++++++++++++++++");
|
|
|
-// mask = mask.setTo(new Scalar(0),getSrc);
|
|
|
-// for(int i=0;i<8;i++){
|
|
|
-// for(int j=0;j<8;j++){
|
|
|
-//// System.out.print(getSrc.get(i,j)[0]);
|
|
|
-// System.out.print(mask.get(i,j)[0]);
|
|
|
-// }
|
|
|
-// System.out.println();
|
|
|
-// }
|
|
|
//二值化mask
|
|
|
Imgproc.threshold(mask, binary, 1, 255, Imgproc.THRESH_TOZERO);
|
|
|
Imgcodecs.imwrite("D:\\data\\binary.jpg", binary);
|
|
@@ -70,26 +53,12 @@ public class CornerCheck {
|
|
|
, blockSize, useHarrisDetector, k);
|
|
|
Point[] pCorners = corners.toArray();
|
|
|
List<Point> pointList = new ArrayList<>();
|
|
|
- double maxX = 0d;
|
|
|
- double maxY = 0d;
|
|
|
- double minX = 10000d;
|
|
|
- double minY = 100000d;
|
|
|
for (int i = 0; i < pCorners.length; i++) {
|
|
|
Point p = new Point(pCorners[i].x + 324, pCorners[i].y + 402);
|
|
|
Imgproc.circle(dst, p, 2, new Scalar(0, 0, 0), Imgproc.FILLED);
|
|
|
}
|
|
|
Imgcodecs.imwrite("D:\\data\\allConers.jpg", dst);
|
|
|
List<Point> cornerPoints = new ArrayList<>();
|
|
|
- for (Point point : pointList) {
|
|
|
- double getX = point.x;
|
|
|
- double getY = point.y;
|
|
|
- if ((getY >= (minY + 20) && getY <= (maxY - 20))) {
|
|
|
- Imgproc.circle(dst, point, 4, new Scalar(255, 255, 255), Imgproc.FILLED);
|
|
|
- } else {
|
|
|
- cornerPoints.add(point);
|
|
|
- Imgproc.circle(dst, point, 4, new Scalar(0, 0, 0), Imgproc.FILLED);
|
|
|
- }
|
|
|
- }
|
|
|
// {139.0, 240.0} 左上 {144.0, 837.0} 左下
|
|
|
// {482.0, 238.0} 右上 {532.0, 825.0} 右下
|
|
|
Collections.sort(cornerPoints, new Comparator<Point>() {
|
|
@@ -99,8 +68,9 @@ public class CornerCheck {
|
|
|
}
|
|
|
});
|
|
|
Imgcodecs.imwrite("D:\\data\\coners.jpg", dst);
|
|
|
-// for (Point p : cornerPoints) {
|
|
|
-// }
|
|
|
+ for (Point p : cornerPoints) {
|
|
|
+
|
|
|
+ }
|
|
|
// result.put("leftTop", cornerPoints.get(0));
|
|
|
// result.put("rightBottom", cornerPoints.get(3));
|
|
|
// if (cornerPoints.get(2).y > cornerPoints.get(1).y) {
|