gpt4 book ai didi

java - OpenCV FeatureDetector 从文件读取后似乎没有设置各种属性

转载 作者:行者123 更新时间:2023-12-01 10:46:49 28 4
gpt4 key购买 nike

以下是使用 Java 和 OpenCV 3.0 检测彩色皮肤图像中的 Blob /痣的代码

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()); ,则附加的皮肤图像将在一些痣周围用圆圈标记(可能正在使用 featureDetector 的某些默认属性值) ,但如果我不这样做,图像上就不会标记任何内容。

enter image description here

最佳答案

您需要指定文件中的所有属性,否则检测器将无法正确加载。

您的文件应如下所示(默认值):

%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 FeatureDetector 从文件读取后似乎没有设置各种属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34131806/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com