-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path模板匹配.java
23 lines (22 loc) · 849 Bytes
/
模板匹配.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
package test2;
import org.opencv.core.Point;
import org.opencv.core.Scalar;
import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.highgui.HighGui;
import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.imgproc.Imgproc;
public class 模板匹配 {
public static void main(String[] args) {
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
Mat img=Imgcodecs.imread("C:\\Users\\86175\\Desktop\\images\\cat.jpg");
Mat example=Imgcodecs.imread("C:\\Users\\86175\\Desktop\\images\\catface.jpg");
Mat result=new Mat();
Imgproc.matchTemplate(img, example, result, Imgproc.TM_CCOEFF);
Core.MinMaxLocResult mml=Core.minMaxLoc(result);
Point p=mml.maxLoc;
Imgproc.rectangle(img, p,new Point(p.x+example.cols(),p.y+example.rows()), new Scalar(255,0,0));
HighGui.imshow(null, img);
HighGui.waitKey(0);
}
}