Ask Your Question
0

Count drops of blood

asked 2015-10-01 22:39:15 -0600

fabiano moreira gravatar image

updated 2015-10-06 00:31:20 -0600

berak gravatar image

Hi, I need to develop a java program openCV to run on Android. The program will capture an image of a skin and make the score drops of blood that is enclosed within a square of 2.5 cm. I'm currently using the blob detection, but the program is not functioning well. Still unable to delineate the count within the area of 2.5 cm. I would like some help from you. Thank you.

Photo 1: https://drive.google.com/file/d/0B-HZ...

Photo 2: https://drive.google.com/file/d/0B-HZ...

Edit:

I wrote the code to Java and it's not working . Could someone help me?

int count=0;
        Mat orig = Highgui.imread("E:\\photo.jpg",Highgui.CV_LOAD_IMAGE_GRAYSCALE);
        Imgproc.adaptiveThreshold(orig, orig, 255, Imgproc.ADAPTIVE_THRESH_MEAN_C, Imgproc.THRESH_BINARY , 15, 5);
        Imgproc.dilate(orig, orig, Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(2, 2)));
        ArrayList <MatOfPoint> contours =  new  ArrayList < MatOfPoint >(); 
        contours.clear();
        Imgproc.findContours ( orig , contours ,  new  Mat (),  Imgproc . RETR_LIST ,  Imgproc.CHAIN_APPROX_SIMPLE );
        for(int a=0;a<contours.size();a++)  
        {
             if(Imgproc.contourArea(contours.get(a)) > 20 & Imgproc.contourArea(contours.get(a)) < 150 )
             {
                 Rect rect = Imgproc.boundingRect(contours.get(a));
                 Core.rectangle(orig,new Point(rect.x,rect.y),new Point(rect.x+rect.width,rect.y+rect.height),new Scalar(0, 255, 0));
                 count++;
             }
        }
         Highgui.imwrite("e:\\photoout.jpg", orig);
edit retag flag offensive close merge delete

Comments

hi fabiano, please don't write answers, when you have another question. instead, rather go and edit your original question.

berak gravatar imageberak ( 2015-10-06 00:32:22 -0600 )edit

I'd say the first problem is with your input image, it has really poor quality - I don't even know where those blood drops are

LorenaGdL gravatar imageLorenaGdL ( 2015-10-06 04:18:08 -0600 )edit

Is it this method you have try?

LBerger gravatar imageLBerger ( 2015-10-06 04:23:43 -0600 )edit

Exactly LBerger and LorenaGdl. Even using a picture with paint circles in the program is not working. You have any suggestions . Thank you.

fabiano moreira gravatar imagefabiano moreira ( 2015-10-06 20:30:52 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2015-10-06 05:14:12 -0600

LBerger gravatar image

I have used this image

image description

I'm sorry I know nothing in java so my answer in C++ is

int main( int argc, char** argv )
{
Mat m = imread( "c:/Users/Laurent.PC-LAURENT-VISI/Downloads/testindex.png", CV_LOAD_IMAGE_GRAYSCALE );
Mat mThresh;

Mat mBlur;

GaussianBlur(m, mBlur, Size(21,21),10.0,10.0);
Mat mFil=mBlur-m;


threshold(mFil,mThresh,5,255,THRESH_BINARY);
findContours(mThresh,contours,hierarchy, cv::RETR_CCOMP, cv::CHAIN_APPROX_NONE, cv::Point(0,0));
Mat mCtr = Mat::zeros(m.size(),CV_8UC1);
drawContours(mCtr,contours,-1,255,-1);
imshow("Threshold",mThresh);
imshow("Ctr",mCtr);
Mat labels;
Mat stats,centroids;

connectedComponentsWithStats(mCtr,labels,stats,centroids);

double mSize=0,sSize=0;
for (int i = 1; i < centroids.rows; i++)
{
        cout << stats.at<int>(i, cv::CC_STAT_AREA) << "\t"<< stats.at<int>(i, CC_STAT_WIDTH) << "\t"<< stats.at<int>(i,CC_STAT_HEIGHT) << "\n";
    mSize+=stats.at<int>(i, cv::CC_STAT_AREA);
    sSize+=stats.at<int>(i, cv::CC_STAT_AREA)*stats.at<int>(i, cv::CC_STAT_AREA);
}
mSize /= (centroids.rows-1);
sSize  /= (centroids.rows-1);
sSize = sqrt(sSize - mSize*mSize);
int nb=0;
for (int i = 1; i < centroids.rows; i++)
{
    if (stats.at<int>(i, cv::CC_STAT_AREA)>mSize - (sSize/2))
    {
        cout << stats.at<int>(i, cv::CC_STAT_AREA) << "\t"<< stats.at<int>(i, CC_STAT_WIDTH) << "\t"<< stats.at<int>(i,CC_STAT_HEIGHT) << "\n";
        nb++;
    }
}

cout << "Drops of blood " << nb << " ("<<centroids.rows<<")\n";
waitKey();
return(0);
}
edit flag offensive delete link more

Comments

Great Lberger . Two questions: You use Eclipse for C ++ ? It is possible to run this code in C ++ on android ?

fabiano moreira gravatar imagefabiano moreira ( 2015-10-06 21:27:22 -0600 )edit

I use visual C++ but it does not matter it works wit gnu gcc too.Unfortunately I don't work with java. but all functions used are opencv function. You can put this in java compiler and may be it will works (excepted cout).

LBerger gravatar imageLBerger ( 2015-10-07 01:35:42 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2015-10-01 22:39:15 -0600

Seen: 643 times

Last updated: Oct 06 '15