圖層金字塔與reSize
Pyramid中文金字塔,是以pyrDown和pyrUp函數也是十分形象的,
pyrDown和pyrUp都是先進行了5x5的高斯模糊,再進行了大小的改變。
pyrDown和pyrUp每調用一次,隻能縮小2倍或者放大2倍。如果就單純的圖檔尺寸的縮放來說,效率沒有reSize高。
resize就是純粹的根據比例改變長寬。
角點檢測
//轉換為單通道 Imgproc.cvtColor(drawing,drawing,COLOR_RGB2GRAY);
drawing.convertTo(drawing,CvType.CV_8UC1);
Imgproc.goodFeaturesToTrack(drawing,corners,4,0.1,30);
MatOfPoint2f point2f=new MatOfPoint2f();
corners.convertTo(point2f,CvType.CV_32FC2);
Point[] allpoint=point2f.toArray();
for (Point point:allpoint){
Imgproc.circle(drawing,point,50,new Scalar(255,0,255));
線段檢測
public static final Mat lineSegmentDetector(Mat srcmat) {
Mat line = new Mat();
LineSegmentDetector lsd = new Imgproc().createLineSegmentDetector();
lsd.detect(srcmat, line);
lsd.drawSegments(srcmat, line);
return
質心
.moments(drawing);
Point centerpoint = new Point(moments.get_m10() / moments.get_m00(), moments.get_m01() / moments.get_m00());
根據2點計算所在直線參數
private static double[] getLineParams(Point linepoint1, Point linepoint2){
// 兩點式公式為(y - y1)/(x - x1) = (y2 - y1)/ (x2 - x1)
// 化簡為一般式為(y2 - y1)x + (x1 - x2)y + (x2y1 - x1y2) = 0
// A = y2 - y1
// B = x1 - x2
// C = x2y1 - x1y2
double a = linepoint2.y - linepoint1.y;
double b = linepoint1.x - linepoint2.x;
double c = linepoint2.x * linepoint1.y - linepoint1.x * linepoint2.y;
double[] abc=new double[]{a,b,c};
return