First time here? Check out the FAQ!

Ask Your Question
0

OpenCV - Blob detection Java with params

asked Nov 5 '15

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);
Preview: (hide)

Comments

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

berak gravatar imageberak (Nov 6 '15)edit

1 answer

Sort by » oldest newest most voted
1

answered Nov 6 '15

berak gravatar image

updated Nov 6 '15

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.
Preview: (hide)

Comments

great berak. It worked perfect. thank you

fabiano moreira gravatar imagefabiano moreira (Nov 7 '15)edit

Question Tools

1 follower

Stats

Asked: Nov 5 '15

Seen: 4,356 times

Last updated: Nov 06 '15