Skip to content

Commit

Permalink
マッチングに使用した特徴点を後で確認できるようにするために元画像と白黒画像、特徴点データもデータとして保持するように修正した。 see #24
Browse files Browse the repository at this point in the history
  • Loading branch information
koki-h committed Jul 4, 2016
1 parent ecb7e98 commit 660ce1d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -23,8 +22,8 @@ public ImageRecognizer(Path trainImageRoot) throws IOException {
}

public List<Result> recognize(Path queryImagePath) {
Mat queryFeatures = featureExtractor.extract(queryImagePath);
return voter.vote(queryFeatures, trainData);
Feature queryFeatures = featureExtractor.extract(queryImagePath);
return voter.vote(queryFeatures.descriptors, trainData);
}

// 登録された訓練画像を読み込み、特徴量を抽出する
Expand All @@ -37,8 +36,8 @@ private List<TrainData> 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;
Expand Down

0 comments on commit 660ce1d

Please sign in to comment.