forked from mesutpiskin/computer-vision-guide
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTemplateMatching.java
37 lines (26 loc) · 1.04 KB
/
TemplateMatching.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import org.opencv.core.Core;
import org.opencv.core.Core.MinMaxLocResult;
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;
public class TemplateMatching {
public static void main(String[] args) {
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
Mat source=null;
Mat template=null;
String filePath="Sample Image\\";
source=Imgcodecs.imread(filePath+"kapadokya.jpg");
template=Imgcodecs.imread(filePath+"balon.jpg");
Mat outputImage=new Mat();
int machMethod=Imgproc.TM_CCOEFF;
Imgproc.matchTemplate(source, template, outputImage, machMethod);
MinMaxLocResult mmr = Core.minMaxLoc(outputImage);
Point matchLoc=mmr.maxLoc;
Imgproc.rectangle(source, matchLoc, new Point(matchLoc.x + template.cols(),
matchLoc.y + template.rows()), new Scalar(255, 255, 255));
Imgcodecs.imwrite(filePath+"sonuc.jpg", source);
System.out.println("Ýþlem tamamlandý.");
}
}