From 660ce1dd46f0f032d6d7f135017a23a1652fcfe4 Mon Sep 17 00:00:00 2001 From: koki Date: Mon, 4 Jul 2016 14:52:28 +0900 Subject: [PATCH] =?UTF-8?q?=E3=83=9E=E3=83=83=E3=83=81=E3=83=B3=E3=82=B0?= =?UTF-8?q?=E3=81=AB=E4=BD=BF=E7=94=A8=E3=81=97=E3=81=9F=E7=89=B9=E5=BE=B4?= =?UTF-8?q?=E7=82=B9=E3=82=92=E5=BE=8C=E3=81=A7=E7=A2=BA=E8=AA=8D=E3=81=A7?= =?UTF-8?q?=E3=81=8D=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB=E3=81=99=E3=82=8B?= =?UTF-8?q?=E3=81=9F=E3=82=81=E3=81=AB=E5=85=83=E7=94=BB=E5=83=8F=E3=81=A8?= =?UTF-8?q?=E7=99=BD=E9=BB=92=E7=94=BB=E5=83=8F=E3=80=81=E7=89=B9=E5=BE=B4?= =?UTF-8?q?=E7=82=B9=E3=83=87=E3=83=BC=E3=82=BF=E3=82=82=E3=83=87=E3=83=BC?= =?UTF-8?q?=E3=82=BF=E3=81=A8=E3=81=97=E3=81=A6=E4=BF=9D=E6=8C=81=E3=81=99?= =?UTF-8?q?=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB=E4=BF=AE=E6=AD=A3=E3=81=97?= =?UTF-8?q?=E3=81=9F=E3=80=82=20see=20#24?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/imgrecognition/Feature.java | 17 +++++++++++++++++ .../java/imgrecognition/FeatureExtractor.java | 4 ++-- .../java/imgrecognition/ImageRecognizer.java | 9 ++++----- 3 files changed, 23 insertions(+), 7 deletions(-) create mode 100644 webapps/Recognition-Tester/src/main/java/imgrecognition/Feature.java diff --git a/webapps/Recognition-Tester/src/main/java/imgrecognition/Feature.java b/webapps/Recognition-Tester/src/main/java/imgrecognition/Feature.java new file mode 100644 index 00000000..76d8ea46 --- /dev/null +++ b/webapps/Recognition-Tester/src/main/java/imgrecognition/Feature.java @@ -0,0 +1,17 @@ +package imgrecognition; +import org.opencv.core.Mat; +import org.opencv.core.MatOfKeyPoint; + +public class Feature { + public final Mat srcImage; + public final Mat grayImage; + public final Mat descriptors; + MatOfKeyPoint keyPoints = new MatOfKeyPoint(); + + public Feature(Mat srcImage, Mat grayImage, MatOfKeyPoint keyPoints, Mat descriptors) { + this.srcImage = srcImage; + this.grayImage = grayImage; + this.keyPoints = keyPoints; + this.descriptors = descriptors; + } +} diff --git a/webapps/Recognition-Tester/src/main/java/imgrecognition/FeatureExtractor.java b/webapps/Recognition-Tester/src/main/java/imgrecognition/FeatureExtractor.java index b2fe9819..08631814 100755 --- a/webapps/Recognition-Tester/src/main/java/imgrecognition/FeatureExtractor.java +++ b/webapps/Recognition-Tester/src/main/java/imgrecognition/FeatureExtractor.java @@ -24,7 +24,7 @@ public FeatureExtractor() { // descriptorExtractor.read(configPath);//configは後で検討 } - public Mat extract(Path imagePath) { + public Feature extract(Path imagePath) { // 画像データの読み込み Mat image = Imgcodecs.imread(imagePath.toString()); @@ -39,6 +39,6 @@ public Mat extract(Path imagePath) { // 特徴量記述 Mat descriptors = new Mat(); descriptorExtractor.compute(grayImage, keyPoints, descriptors); - return descriptors; + return new Feature(image,grayImage,keyPoints,descriptors); } } diff --git a/webapps/Recognition-Tester/src/main/java/imgrecognition/ImageRecognizer.java b/webapps/Recognition-Tester/src/main/java/imgrecognition/ImageRecognizer.java index cc623bce..a711fb1e 100644 --- a/webapps/Recognition-Tester/src/main/java/imgrecognition/ImageRecognizer.java +++ b/webapps/Recognition-Tester/src/main/java/imgrecognition/ImageRecognizer.java @@ -7,7 +7,6 @@ import java.util.List; import org.opencv.core.Core; -import org.opencv.core.Mat; public class ImageRecognizer { private final FeatureExtractor featureExtractor = new FeatureExtractor(); @@ -23,8 +22,8 @@ public ImageRecognizer(Path trainImageRoot) throws IOException { } public List recognize(Path queryImagePath) { - Mat queryFeatures = featureExtractor.extract(queryImagePath); - return voter.vote(queryFeatures, trainData); + Feature queryFeatures = featureExtractor.extract(queryImagePath); + return voter.vote(queryFeatures.descriptors, trainData); } // 登録された訓練画像を読み込み、特徴量を抽出する @@ -37,8 +36,8 @@ private List loadTrainData(Path trainImageRoot) throws IOException { String label = labelDir.getFileName().toString(); for (Path imagePath : Files.newDirectoryStream(labelDir)) { try { - Mat features = featureExtractor.extract(imagePath); - trainData.add(new TrainData(label, features)); + Feature features = featureExtractor.extract(imagePath); + trainData.add(new TrainData(label, features.descriptors)); } catch(org.opencv.core.CvException e) { System.out.println(e); continue;