maven version.
<properties>
<webapp.libs>${project.basedir}/src/main/java/com/packagename/external</webapp.libs>
</properties>
<dependency>
<groupId>org.opencv</groupId>
<artifactId>external</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${webapp.libs}/opencv/opencv-3413.jar</systemPath>
</dependency>
대충 위치.
private void compareFeature(String fileName1, String fileName2){
int retValue = 0;
String dllName = System.getProperty("user.dir").concat(File.separatorChar + "butterfly-ui")
.concat(File.separatorChar + "src").concat(File.separatorChar + "main").concat(File.separatorChar + "java").concat(File.separatorChar + "com")
.concat(File.separatorChar + "packagename").concat(File.separatorChar + "external").concat(File.separatorChar + "opencv").concat(File.separatorChar + "opencv_java3413.dll");
System.load(dllName);
Mat img1 = Imgcodecs.imread(fileName1, Imgcodecs.IMREAD_GRAYSCALE);
Mat img2 = Imgcodecs.imread(fileName2, Imgcodecs.IMREAD_GRAYSCALE);
MatOfKeyPoint point1 = new MatOfKeyPoint();
MatOfKeyPoint point2 = new MatOfKeyPoint();
Mat descriptors1 = new Mat();
Mat descriptors2 = new Mat();
ORB orb = ORB.create(ORB.FAST_SCORE);
orb.compute(img1, point1, descriptors1);
orb.compute(img2, point2, descriptors2);
FeatureDetector detector = FeatureDetector.create(FeatureDetector.ORB);
detector.detect(img1, point1);
detector.detect(img2, point2);
DescriptorExtractor extractor = DescriptorExtractor.create(DescriptorExtractor.ORB);
extractor.compute(img1, point1, descriptors1);
extractor.compute(img2, point2, descriptors2);
if(descriptors1.cols() == descriptors2.cols()){
DescriptorMatcher matcher = DescriptorMatcher.create(DescriptorMatcher.BRUTEFORCE_HAMMING);
MatOfDMatch matches = new MatOfDMatch();
matcher.match(descriptors1, descriptors2, matches);
DMatch[] matchArray = matches.toArray();
double maxDist = 0;
double minDist = 100;
for(int i = 0; i < descriptors1.rows(); i++){
double dist = matchArray[i].distance;
if(dist < minDist){
minDist = dist;
}
if(dist > maxDist){
maxDist = dist;
}
}
for(int i = 0; i < descriptors1.rows(); i++) {
if(matchArray[i].distance <= 30) {
retValue++;
}
logInfo("count={}", matchArray[i].distance);
}
logInfo("max_dist={}, min_dist={} ", maxDist, minDist);
logInfo("matching count={} ", retValue);
}
}
인식율이 안 좋아서 결국 구글 2종 + aws 1종을 복합적으로 분석을 만들었지만...
잠시 동안의 OCR을 위한 opencv 사용을 위한 dll 사용법.
'Java' 카테고리의 다른 글
자바 Log Class (0) | 2021.02.22 |
---|---|
자바 Aspect, Annotation으로 Log 만들기 (0) | 2021.02.22 |
자바 Async3 (0) | 2020.11.08 |
자바 Async2 (0) | 2020.11.08 |
자바 Async1 (0) | 2020.11.08 |