Ask Your Question
0

OpenCV - Blob detection Java with params

asked 2015-11-05 13:57:06 -0600

fabiano moreira gravatar image

I need a Java code with blob detection using parameters (example filterByCircularity). I found several examples in C ++ and Python, but none in Java with OpenCV. I have the code below and need to implement the parameters of blobs detection, (example filterByCircularity). Someone has already implemented this?

Mat orig = Highgui.imread("E:\\PhotoIn.jpg",Highgui.IMREAD_GRAYSCALE);

Mat MatOut= new Mat();

FeatureDetector blobDetector;

blobDetector = FeatureDetector.create(FeatureDetector.SIFT);

MatOfKeyPoint keypoints1 = new MatOfKeyPoint();

blobDetector.detect(orig,keypoints1); 

org.opencv.core.Scalar cores = new org.opencv.core.Scalar(0,0,255);

org.opencv.features2d.Features2d.drawKeypoints(orig,keypoints1,MatOut,cores,2);

Highgui.imwrite("e:\\PhotoOut.jpg", MatOut);
edit retag flag offensive close merge delete

Comments

didn't you want : FeatureDetector.create(FeatureDetector.SIMPLEBLOB); (not SIFT) ?

berak gravatar imageberak ( 2015-11-06 02:24:23 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2015-11-06 02:30:38 -0600

berak gravatar image

updated 2015-11-06 02:34:35 -0600

unfortunately, there's no straightforward way to do so, we need the backdoor (save/read xml):

// make a simpleblob detector:
FeatureDetector blobby = FeatureDetector.create(FeatureDetector.SIMPLEBLOB);
// save the original config:
// (or use the one below)    
blobby.write("/mnt/sdcard/blob.xml");


<?xml version="1.0"?>
<opencv_storage>
<thresholdStep>10.</thresholdStep>
<minThreshold>50.</minThreshold>
<maxThreshold>220.</maxThreshold>
<minRepeatability>2</minRepeatability>
<minDistBetweenBlobs>10.</minDistBetweenBlobs>
<filterByColor>1</filterByColor>
<blobColor>0</blobColor>
<filterByArea>1</filterByArea>
<minArea>25.</minArea>
<maxArea>5000.</maxArea>
<filterByCircularity>0</filterByCircularity>
<minCircularity>8.0000001192092896e-01</minCircularity>
<maxCircularity>3.4028234663852886e+38</maxCircularity>
<filterByInertia>1</filterByInertia>
<minInertiaRatio>1.0000000149011612e-01</minInertiaRatio>
<maxInertiaRatio>3.4028234663852886e+38</maxInertiaRatio>
<filterByConvexity>1</filterByConvexity>
<minConvexity>9.4999998807907104e-01</minConvexity>
<maxConvexity>3.4028234663852886e+38</maxConvexity>
</opencv_storage>


// now edit params as you like, and read it back in:
blobby.read("/mnt/sdcard/blob.xml"); // wherever you put it.
edit flag offensive delete link more

Comments

great berak. It worked perfect. thank you

fabiano moreira gravatar imagefabiano moreira ( 2015-11-06 21:06:48 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2015-11-05 13:57:06 -0600

Seen: 4,344 times

Last updated: Nov 06 '15