从文件中读取后,OpenCV FeatureDetector 似乎没有设置各种属性
OpenCV FeatureDetector doesn't seem to set various properties after reading it from file
以下是使用 Java 和 OpenCV 3.0
在彩色皮肤图像中检测 blob/moles 的代码
private void initLibService(){
String opencvpath = System.getProperty("user.dir") + File.separator + "lib" + File.separator;
System.load(opencvpath + Core.NATIVE_LIBRARY_NAME + ".dll");
blobDetector = FeatureDetector.create(FeatureDetector.SIMPLEBLOB);
try {
File temp = File.createTempFile("tempFile",".tmp");
String settings="%YAML:1.0\nthresholdStep: " + Integer.parseInt(ResourceUtil.getProperty("MOLE_THRESHOLD_STEPS")) + "\nminThreshold: "+ Integer.parseInt(ResourceUtil.getProperty("MOLE_UPPER_INTENSITY_THRESOLD")) + "\n";
System.out.println("\nFeature detector setting data: " + settings + "\n\n");
FileWriter writer=new FileWriter(temp,false);
writer.write(settings);
writer.close();
blobDetector.read(temp.getPath());
temp.deleteOnExit();
}
catch ( IOException e) {
e.printStackTrace();
}
}
public static Mat detectBlob(String imagePath, FeatureDetector blobDetector) {
// Read image
Mat im = Imgcodecs.imread(imagePath);
MatOfKeyPoint keypoints = new MatOfKeyPoint();
blobDetector.detect(im, keypoints);
System.out.println("keypoints: " + keypoints.toList());
Mat im_with_keypoints = new Mat();
Features2d.drawKeypoints(im, keypoints, im_with_keypoints, new Scalar(0, 255, 0), Features2d.DRAW_RICH_KEYPOINTS);
return im_with_keypoints;
}
如果我评论 blobDetector.read(temp.getPath());
行,那么附加的皮肤图像将在一些痣周围用圆圈标记(可能使用特征检测器的一些默认 属性 值),但如果我没有, 图像上没有任何标记。
您需要在文件中指定所有属性,否则检测器将被错误加载。
您的文件应如下所示(默认值):
%YAML:1.0
thresholdStep: 10.
minThreshold: 50.
maxThreshold: 220.
minRepeatability: 2
minDistBetweenBlobs: 10.
filterByColor: 1
blobColor: 0
filterByArea: 1
minArea: 25.
maxArea: 5000.
filterByCircularity: 0
minCircularity: 8.0000001192092896e-001
maxCircularity: 3.4028234663852886e+038
filterByInertia: 1
minInertiaRatio: 1.0000000149011612e-001
maxInertiaRatio: 3.4028234663852886e+038
filterByConvexity: 1
minConvexity: 9.4999998807907104e-001
maxConvexity: 3.4028234663852886e+038
以下是使用 Java 和 OpenCV 3.0
在彩色皮肤图像中检测 blob/moles 的代码private void initLibService(){
String opencvpath = System.getProperty("user.dir") + File.separator + "lib" + File.separator;
System.load(opencvpath + Core.NATIVE_LIBRARY_NAME + ".dll");
blobDetector = FeatureDetector.create(FeatureDetector.SIMPLEBLOB);
try {
File temp = File.createTempFile("tempFile",".tmp");
String settings="%YAML:1.0\nthresholdStep: " + Integer.parseInt(ResourceUtil.getProperty("MOLE_THRESHOLD_STEPS")) + "\nminThreshold: "+ Integer.parseInt(ResourceUtil.getProperty("MOLE_UPPER_INTENSITY_THRESOLD")) + "\n";
System.out.println("\nFeature detector setting data: " + settings + "\n\n");
FileWriter writer=new FileWriter(temp,false);
writer.write(settings);
writer.close();
blobDetector.read(temp.getPath());
temp.deleteOnExit();
}
catch ( IOException e) {
e.printStackTrace();
}
}
public static Mat detectBlob(String imagePath, FeatureDetector blobDetector) {
// Read image
Mat im = Imgcodecs.imread(imagePath);
MatOfKeyPoint keypoints = new MatOfKeyPoint();
blobDetector.detect(im, keypoints);
System.out.println("keypoints: " + keypoints.toList());
Mat im_with_keypoints = new Mat();
Features2d.drawKeypoints(im, keypoints, im_with_keypoints, new Scalar(0, 255, 0), Features2d.DRAW_RICH_KEYPOINTS);
return im_with_keypoints;
}
如果我评论 blobDetector.read(temp.getPath());
行,那么附加的皮肤图像将在一些痣周围用圆圈标记(可能使用特征检测器的一些默认 属性 值),但如果我没有, 图像上没有任何标记。
您需要在文件中指定所有属性,否则检测器将被错误加载。
您的文件应如下所示(默认值):
%YAML:1.0
thresholdStep: 10.
minThreshold: 50.
maxThreshold: 220.
minRepeatability: 2
minDistBetweenBlobs: 10.
filterByColor: 1
blobColor: 0
filterByArea: 1
minArea: 25.
maxArea: 5000.
filterByCircularity: 0
minCircularity: 8.0000001192092896e-001
maxCircularity: 3.4028234663852886e+038
filterByInertia: 1
minInertiaRatio: 1.0000000149011612e-001
maxInertiaRatio: 3.4028234663852886e+038
filterByConvexity: 1
minConvexity: 9.4999998807907104e-001
maxConvexity: 3.4028234663852886e+038