Ask Your Question

Revision history [back]

Android-Opencv Color Blob Detection With Rectangle


I'm trying to make it can detect color blob more than one rectangle. But it just show me one rectangle. Can anybody tell me what's the problem?

public static void detectMultipleBlob(Mat src, Mat image, String text, Mat dst){ List<matofpoint> contours = new ArrayList<matofpoint>(); //vector<vector<point> > contours; Mat hierarchy = new Mat(); src.copyTo(dst);

Imgproc.findContours(image, contours, hierarchy, Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE);

int k = getBiggestContourIndex(contours); Rect boundRect = setContourRect(contours, k);

Point center = new Point(); getCenterPoint(boundRect.tl(), boundRect.br(), center); Core.rectangle(dst, boundRect.tl(), boundRect.br(), new Scalar(255, 255, 0), 2, 8, 0 );

Core.putText(dst, text, boundRect.tl(), 0/font/, 1, new Scalar(255, 0, 0, 255), 3); }

public static void getCenterPoint(Point tl, Point br, Point dst){ dst.x = (tl.x + br.x)/2; dst.y = (tl.y + br.y)/2; }

public static Rect setContourRect(List<matofpoint> contours,int k){ Rect boundRect = new Rect(); Iterator<matofpoint> each = contours.iterator(); int j = 0; while (each.hasNext()){ MatOfPoint wrapper = each.next(); if (j==k){ return Imgproc.boundingRect( wrapper ); } j++; } return boundRect; }

public static int getBiggestContourIndex(List<matofpoint> contours){ double maxArea = 0; Iterator<matofpoint> each = contours.iterator(); int j = 0; int k = -1; while (each.hasNext()) { MatOfPoint wrapper = each.next(); double area = Imgproc.contourArea(wrapper); if (area > maxArea){ maxArea = area; k = j; } j++; } return k; }

Android-Opencv Color Blob Detection With Rectangle


I'm trying to make it can detect color blob more than one rectangle. But it just show me one rectangle. Can anybody tell me what's the problem?

public static void detectMultipleBlob(Mat src, Mat image, String text, Mat dst){
List<matofpoint> List<MatOfPoint> contours = new ArrayList<matofpoint>(); //vector<vector<point> ArrayList<MatOfPoint>(); //vector<vector<Point> > contours;
Mat hierarchy = new Mat();
src.copyTo(dst);

src.copyTo(dst); Imgproc.findContours(image, contours, hierarchy, Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE);

Imgproc.CHAIN_APPROX_SIMPLE); int k = getBiggestContourIndex(contours); Rect boundRect = setContourRect(contours, k);

k); Point center = new Point(); getCenterPoint(boundRect.tl(), boundRect.br(), center); Core.rectangle(dst, boundRect.tl(), boundRect.br(), new Scalar(255, 255, 0), 2, 8, 0 );

); Core.putText(dst, text, boundRect.tl(), 0/font/, 0/*font*/, 1, new Scalar(255, 0, 0, 255), 3); }

} public static void getCenterPoint(Point tl, Point br, Point dst){ dst.x = (tl.x + br.x)/2; dst.y = (tl.y + br.y)/2; }

} public static Rect setContourRect(List<matofpoint> setContourRect(List<MatOfPoint> contours,int k){ Rect boundRect = new Rect(); Iterator<matofpoint> Iterator<MatOfPoint> each = contours.iterator(); int j = 0; while (each.hasNext()){ MatOfPoint wrapper = each.next(); if (j==k){ return Imgproc.boundingRect( wrapper ); } j++; } return boundRect; }

public static int getBiggestContourIndex(List<matofpoint> } public static int getBiggestContourIndex(List<MatOfPoint> contours){ double maxArea = 0; Iterator<matofpoint> Iterator<MatOfPoint> each = contours.iterator(); int j = 0; int k = -1; while (each.hasNext()) { MatOfPoint wrapper = each.next(); double area = Imgproc.contourArea(wrapper); if (area > maxArea){ maxArea = area; k = j; } j++; } return k; }

}

Android-Opencv Color Blob Detection With Rectangle

I'm trying Can anyone help me to make it can detect color blob more than one rectangle. But it just show me one rectangle. Can anybody tell me what's the problem?understand this? i got this from someone's blog online. What does "int j" mean and what "divided by two" means? dst.x = (tl.x + br.x)/2; dst.y = (tl.y + br.y)/2;

public static void detectMultipleBlob(Mat src, Mat image, String text, Mat dst){
List<MatOfPoint> contours = new ArrayList<MatOfPoint>(); //vector<vector<Point> > contours;
Mat hierarchy = new Mat();
src.copyTo(dst);

Imgproc.findContours(image, contours, hierarchy, Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE);

int k = getBiggestContourIndex(contours);
Rect boundRect = setContourRect(contours, k);

Point center = new Point();
getCenterPoint(boundRect.tl(), boundRect.br(), center);
Core.rectangle(dst, boundRect.tl(), boundRect.br(), new Scalar(255, 255, 0), 2, 8, 0 );

Core.putText(dst, text, boundRect.tl(), 0/*font*/, 1, new Scalar(255, 0, 0, 255), 3);
}

public static void getCenterPoint(Point tl, Point br, Point dst){
dst.x = (tl.x + br.x)/2;
dst.y = (tl.y + br.y)/2;
}


public static Rect setContourRect(List<MatOfPoint> contours,int k){
Rect boundRect = new Rect();
Iterator<MatOfPoint> each = contours.iterator();
int j = 0;
while (each.hasNext()){
MatOfPoint wrapper = each.next();
if (j==k){
return Imgproc.boundingRect( wrapper );
}
j++;
}
return boundRect;
}


public static int getBiggestContourIndex(List<MatOfPoint> contours){
double maxArea = 0;
Iterator<MatOfPoint> each = contours.iterator();
int j = 0;
int k = -1;
while (each.hasNext())
{
MatOfPoint wrapper = each.next();
double area = Imgproc.contourArea(wrapper);
if (area > maxArea){
maxArea = area;
k = j;
}
j++;
}
return k;
}

Android-Opencv Color Blob Detection With Rectangle

Can anyone help me to understand this? i got this from someone's blog online. What does "int j" mean and what "divided by two" means? dst.x = (tl.x + br.x)/2; dst.y = (tl.y + br.y)/2;

int k = getBiggestContourIndex(contours);
Rect boundRect = setContourRect(contours, k);

Point center = new Point();
getCenterPoint(boundRect.tl(), boundRect.br(), center);
Core.rectangle(dst, boundRect.tl(), boundRect.br(), new Scalar(255, 255, 0), 2, 8, 0 );

Core.putText(dst, text, boundRect.tl(), 0/*font*/, 1, new Scalar(255, 0, 0, 255), 3);
}

public static void getCenterPoint(Point tl, Point br, Point dst){
dst.x = (tl.x + br.x)/2;
dst.y = (tl.y + br.y)/2;
}


public static Rect setContourRect(List<MatOfPoint> contours,int k){
Rect boundRect = new Rect();
Iterator<MatOfPoint> each = contours.iterator();
int j = 0;
while (each.hasNext()){
MatOfPoint wrapper = each.next();
if (j==k){
return Imgproc.boundingRect( wrapper );
}
j++;
}
return boundRect;
}


public static int getBiggestContourIndex(List<MatOfPoint> contours){
double maxArea = 0;
Iterator<MatOfPoint> each = contours.iterator();
int j = 0;
int k = -1;
while (each.hasNext())
{
MatOfPoint wrapper = each.next();
double area = Imgproc.contourArea(wrapper);
if (area > maxArea){
maxArea = area;
k = j;
}
j++;
}
return k;
}

Color Blob Detection With Rectangle

Can anyone help me to understand this? i got this from someone's blog online. What does "int j" mean and what "divided by two" means? dst.x = (tl.x + br.x)/2; dst.y = (tl.y + br.y)/2;

int k = getBiggestContourIndex(contours);
Rect boundRect = setContourRect(contours, k);

Point center = new Point();
getCenterPoint(boundRect.tl(), boundRect.br(), center);
Core.rectangle(dst, boundRect.tl(), boundRect.br(), new Scalar(255, 255, 0), 2, 8, 0 );

Core.putText(dst, text, boundRect.tl(), 0/*font*/, 1, new Scalar(255, 0, 0, 255), 3);
}

public static void getCenterPoint(Point tl, Point br, Point dst){
dst.x = (tl.x + br.x)/2;
dst.y = (tl.y + br.y)/2;
}


public static Rect setContourRect(List<MatOfPoint> contours,int k){
Rect boundRect = new Rect();
Iterator<MatOfPoint> each = contours.iterator();
int j = 0;
while (each.hasNext()){
MatOfPoint wrapper = each.next();
if (j==k){
return Imgproc.boundingRect( wrapper );
}
j++;
}
return boundRect;
}


public static int getBiggestContourIndex(List<MatOfPoint> contours){
double maxArea = 0;
Iterator<MatOfPoint> each = contours.iterator();
int j = 0;
int k = -1;
while (each.hasNext())
{
MatOfPoint wrapper = each.next();
double area = Imgproc.contourArea(wrapper);
if (area > maxArea){
maxArea = area;
k = j;
}
j++;
}
return k;
}

Color Blob Detection With Rectangle

Can anyone help me to understand this? i got this from someone's blog online. What does "int j" mean and what "divided by two" means? dst.x = (tl.x + br.x)/2; dst.y = (tl.y + br.y)/2;online.

public static int getBiggestContourIndex(List<MatOfPoint> contours){
double maxArea = 0;
Iterator<MatOfPoint> each = contours.iterator();
int j = 0;
int k = -1;
while (each.hasNext())
{
MatOfPoint wrapper = each.next();
double area = Imgproc.contourArea(wrapper);
if (area > maxArea){
maxArea = area;
k = j;
}
j++;
}
return k;
}

Color Blob Detection With Rectangle

Can anyone help me to understand this? i got this from someone's blog online.this?

public static int getBiggestContourIndex(List<MatOfPoint> contours){
double maxArea = 0;
Iterator<MatOfPoint> each = contours.iterator();
int j = 0;
int k = -1;
while (each.hasNext())
{
MatOfPoint wrapper = each.next();
double area = Imgproc.contourArea(wrapper);
if (area > maxArea){
maxArea = area;
k = j;
}
j++;
}
return k;
}