Ask Your Question
0

Divide Object In Blob. [closed]

asked 2016-05-18 12:47:57 -0600

Stuart gravatar image

updated 2016-05-20 13:23:40 -0600

Somebody can help me to solve this problem. I try this for showing in frame. Its blob detection but in Java android ?

image description

 Core.putText(mRgba, ":" +(
                "((" + mBlobColorRgba.val[0] + ", " + mBlobColorRgba.val[1] +
            ", " + mBlobColorRgba.val[2] + ", " + mBlobColorRgba.val[3] + ")"), new org.opencv.core.Point(0, 160),
                Core.FONT_HERSHEY_SIMPLEX, 2.6d, new Scalar(255, 255, 0));

        Core.putText(mRgba, "Count number : " +
            contours.size(), new org.opencv.core.Point(0, 300),
            Core.FONT_HERSHEY_SIMPLEX, 2.6f, new Scalar(255, 255, 0));
edit retag flag offensive reopen merge delete

Closed for the following reason duplicate question by Stuart
close date 2016-05-25 14:59:40.487446

Comments

maybe this will help. or if your blob objects are nearly same size you can check area of blobs.

sturkmen gravatar imagesturkmen ( 2016-05-18 12:59:44 -0600 )edit

Thanks for answer sir, but how when try in android sir ? in my project just detect for HSV color sir, how when from size of object sir ?

Stuart gravatar imageStuart ( 2016-05-18 13:04:29 -0600 )edit

could you post your whole source code if possible.

sturkmen gravatar imagesturkmen ( 2016-05-18 13:36:05 -0600 )edit

but its so many sir, no problem ? or i send to your email ?

Stuart gravatar imageStuart ( 2016-05-18 13:39:49 -0600 )edit

you can send by e-mail but sorry i am not familiar with java.if you can convert it i can try to implement a c++ code.

sturkmen gravatar imagesturkmen ( 2016-05-18 13:43:24 -0600 )edit

your email sir ? maybe i'll try sir.

Stuart gravatar imageStuart ( 2016-05-18 13:44:43 -0600 )edit

my username @hotmail.com

sturkmen gravatar imagesturkmen ( 2016-05-18 13:47:51 -0600 )edit

alright sir, maybe if not familiar in java you can suggest me which part i must modification ,i've done send to your email sir.

Stuart gravatar imageStuart ( 2016-05-18 13:51:40 -0600 )edit

2 answers

Sort by ยป oldest newest most voted
1

answered 2016-05-22 10:25:19 -0600

essamzaky gravatar image

You can try watershed segmentation in the following link Watershed segmentation

this method will help you to count both the connected objects and the isolated objects .

edit flag offensive delete link more

Comments

Can i know your email sir ? Yes, but how when real time sir ?

Stuart gravatar imageStuart ( 2016-05-22 11:09:33 -0600 )edit

my email is my name at hotmail what do you mean by real time ? , you mean you have a video

essamzaky gravatar imageessamzaky ( 2016-05-22 11:39:31 -0600 )edit

I'm not java developer , but here it's a sample , which can define callback function and receive frame and convert it to image link text

also read this question link text also read video capture tutorial link text

essamzaky gravatar imageessamzaky ( 2016-05-23 05:25:31 -0600 )edit
0

answered 2016-05-18 16:04:14 -0600

take a look at the code below.

i used this way : firstly i found the smallest blob's area (minimum_area)

and later used contourArea / minimum_areafor each blob to increase total blobs count.

(it is not perfect but just to show a way you can improve this approach for better results)

#include <opencv2/highgui.hpp>
#include <opencv2/imgproc.hpp>

using namespace cv;
using namespace std;

int main( int argc, const char** argv )
{
    Mat img = imread(argv[1]);
    if(img.empty())
    {
        return -1;
    }

    vector<vector<Point> > contours;

    Mat bw,bgr[3];
    split( img,bgr );

    int red_blobs_count = 0;

    cvtColor(bgr[1],bw,COLOR_GRAY2BGR);
    bw = img-bw;
    cvtColor(bw,bw,COLOR_BGR2GRAY);

    bw = bw > 10;

    findContours( bw, contours, RETR_EXTERNAL, CHAIN_APPROX_SIMPLE );

    int minimum_area = img.cols * img.rows;
    for( size_t i = 0; i< contours.size(); i++ )
    {
        int _contourArea = contourArea(contours[i]);
        if( _contourArea > 10 & minimum_area > _contourArea )
        {
            minimum_area = _contourArea ;
        }
    }

    for( size_t i = 0; i< contours.size(); i++ )
    {
        int _contourArea = contourArea(contours[i]);
        if( _contourArea > 10 )
        {
            Rect minRect = boundingRect( Mat(contours[i]) );
            rectangle(img,minRect,Scalar(0,255,0));
            red_blobs_count += _contourArea / minimum_area;
            putText(img, format("%.02f",(float)_contourArea / minimum_area), minRect.tl(),FONT_HERSHEY_SIMPLEX, 0.5, Scalar(255,255,0), 2);
            putText(img, format("%d",red_blobs_count), minRect.br(),FONT_HERSHEY_SIMPLEX, 0.5, Scalar(0,127,255), 2);
        }
    }
    putText(img, format("red_blobs_count = %d",red_blobs_count), Point(50, 30),FONT_HERSHEY_SIMPLEX, 0.8, Scalar(0,255,0), 2);

    imshow( "red_blobs_count", img );
    waitKey(0);

    return 0;
}

image description

you can check results of this image. you can see some groups not calculated right but you can improve calculation algorithm. image description

edit flag offensive delete link more

Comments

so, its possible to show the real sir ? i mean although in frame show 3 the result number can be 3 too ?

Stuart gravatar imageStuart ( 2016-05-18 21:09:51 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2016-05-18 12:47:57 -0600

Seen: 709 times

Last updated: May 22 '16