Reputation: 3
Following is the code to detect blob/moles in colored skin image using Java and OpenCV 3.0
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;
}
If I comment the line blobDetector.read(temp.getPath());
then the attached skin image is being marked with circles around some moles (may be using some default property values of featuredetector), but If I didn't, nothing get marked on the image.
Upvotes: 0
Views: 311
Reputation: 41765
You need to specify all properties in your file, or the detector will be loaded incorrectly.
Your file should look like this (default values):
%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
Upvotes: 1