Blobscanner
Class Detector

java.lang.Object
  extended by Blobscanner.Detector

public class Detector
extends java.lang.Object

The Detector class


Constructor Summary
Detector(processing.core.PApplet p5, int sx, int sy, int w, int h, int threshold)
           Detector class constructor.
 
Method Summary
 void drawBlobContour(int blobnumber, int contourColor, float thickness)
          Draws the blob contour for the blob specified by blobnumber parameter value.
 void drawBox(int boxColor, float thickness)
          Draws the blob bounding box.
 void drawContours(int contoursColor, float thickness)
          Draws the edge of each blob.
 void drawSelectBox(int minimumWeight, int boxColor, float thickness)
          Draws the blob's bounding box only for blobs which weight is bigger than or equals to minimumWeight parameter value.
 void drawSelectContours(int minimumWeight, int contoursColor, float thickness)
          Draws the contour only for blobs which weight is bigger than or equals to minimumWeight parameter value.
 void findBlobs(int[] pix_array, int trueWidth, int trueHeight)
          Finds all the blob pixels and saves them into the pixel group buffer MyGroup.
 void findCentroids(boolean printLocation, boolean drawCentroids)
          Calculates the blob centroids.
 processing.core.PVector[] getA()
          Returns an array of PVectors which contains all the left upper corners of the blobs bounding boxes.
 processing.core.PVector[] getB()
          Returns an array of PVectors which contains all the right upper corners of the blobs bounding boxes.
 int getBlobHeight(int blobnumber)
          Returns the blob height.
 int getBlobNumberAt(int x, int y)
          Returns the blob number at the x y coordinates.
 processing.core.PVector[] getBlobPixelsLocation(int blobnumber)
          Computes and returns the coordinates of all the pixels in the specified blob.
 int getBlobsNumber()
          The total number of blobs in the current frame or image.
 int getBlobWeight(int blobNum)
          Returns the weight of the blob specified.
 int getBlobWeightLabel(int label)
          Returns the weight of the blob with the specified label.
 int getBlobWidth(int blobnumber)
          Returns the blob width.
 float getBoxCentX(int blobnumber)
          Returns the x coordinates of the bounding box center.
 float getBoxCentY(int blobnumber)
          Returns the y coordinates of the bounding box center.
 processing.core.PVector[] getC()
          Returns an array of PVectors which contains all the left lower corners of the blobs bounding boxes.
 float getCentroidX(int blobnumber)
          Returns the blob centroid x coordinate.
 float getCentroidY(int blobnumber)
          Returns the blob centroid y coordinate.
 processing.core.PVector getCrossPoints(int blobnumber, int pointVector, boolean draw_them)
          Finds the coordinates of the middle point of the blob's bounding box side.
 processing.core.PVector[] getD()
          Returns an array of PVectors which contains all the right lower corners of the blobs bounding boxes.
 processing.core.PVector[] getEdgePoints(int blobnumber)
          Computes the coordinates of the edge's pixels for the specified blob.
 int getEdgeSize(int blobnumber)
          Computes the number of edge pixels for the specified blob.
 int getEdgeX(int blobnumber, int index)
          Deprecated.  
 processing.core.PVector[] getEdgeXY()
          Deprecated.  
 int getEdgeY(int blobnumber, int index)
          Deprecated.  
 int getGlobalWeight()
          Get the total weight for all the blobs in the current frame or image.
 int getLabel(int blobnumber)
          Returns the label of the blob indicated by the blobnumber parameter.
 int getLabel(int x, int y)
          Returns the blob label at x, y screen coordinates.
 void imageFindBlobs(processing.core.PImage img)
          Like findBlobs(int[],int,int) but to be used with a PImage object.
 boolean isBlob(int x, int y)
          Returns true if at x y location finds a blob pixel.
 boolean isEdge(int x, int y)
          Returns true if the pixel at x y coordinates is a blob edge pixel.
 boolean isMatch(int x, int y, int blobToMatch)
          Returns true only if the pixel at the coordinates x y is inside the blob represented by the parameter blobToMatch.
 void loadBlobsFeatures()
          findBlobs() or imageFindBlobs(PImage) methods must be called before to call this method.
 void weightBlobs(boolean printConsoleIfNoBlobs)
          Calculates the total blob weight (mass) for each frame or image.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Detector

public Detector(processing.core.PApplet p5,
                int sx,
                int sy,
                int w,
                int h,
                int threshold)
Detector class constructor.

Parameters:
p5 - Reference to register with the host PApplet.
sx - The x coordinate of the top left corner of the rectangular area scanned for blobs.
sy - The y coordinate of the top left corner of the rectangular area scanned for blobs.
w - The width of the rectangular area scanned for blobs.
h - The height of the rectangular area scanned for blobs.
threshold - Blobscanner will search for blobs which brightness is equals to this parameter's value.
Method Detail

findBlobs

public void findBlobs(int[] pix_array,
                      int trueWidth,
                      int trueHeight)
Finds all the blob pixels and saves them into the pixel group buffer MyGroup.

Parameters:
pix_array - The screen buffer to scan for blobs.
trueWidth - The width of the image or video to search for blobs.
trueHeight - The height of the image or video to search for blobs.

imageFindBlobs

public void imageFindBlobs(processing.core.PImage img)
Like findBlobs(int[],int,int) but to be used with a PImage object.

Parameters:
img - PImage to scan for blobs.

weightBlobs

public void weightBlobs(boolean printConsoleIfNoBlobs)
Calculates the total blob weight (mass) for each frame or image. This method must be called before calling getBlobWeight(int blobNum) , getBlobWeightLabel(int label) , drawSelectBox(int minimumWeight,int boxColor,float thickness) , drawSelectContours(int minimumWeight,int contourColor,float thickness) and findCentroids(boolean, boolean)methods. findBlobs() or imageFindBlobs(PImage) must be called first to call this method.

Parameters:
printConsoleIfNoBlobs - If true, the method prints a message to the console if zero blobs have been found.

drawContours

public void drawContours(int contoursColor,
                         float thickness)
Draws the edge of each blob.

Parameters:
contoursColor - The edges color. Here can be passed color( r, g, b) Processing method. This parameter is passed to the stroke Processing method.
thickness - The edges thickness. This parameter is passed to strokeWeight(int) Processing method. findBlobs() or imageFindBlobs(PImage) must be called first to call this method.

drawSelectContours

public void drawSelectContours(int minimumWeight,
                               int contoursColor,
                               float thickness)
Draws the contour only for blobs which weight is bigger than or equals to minimumWeight parameter value. findBlobs() or imageFindBlobs(PImage), weightBlobs(boolean) and loadBlobsFeatures() methods must be called before to call this method.

Parameters:
minimumWeight - The minimum weight of the blobs for which the contour is drawn
contoursColor - The pixel edge color. Here it can be passed color( r, g, b) Processing method.
thickness - The edge thickness. This parameter is passed to strokeWeight(int) Processing method.
See Also:
loadBlobsFeatures(), weightBlobs(boolean)

drawBlobContour

public void drawBlobContour(int blobnumber,
                            int contourColor,
                            float thickness)
Draws the blob contour for the blob specified by blobnumber parameter value. findBlobs() or imageFindBlobs(PImage) and loadBlobsFeatures() methods must be called before to call this method.

Parameters:
blobnumber - The blob which contours are drawn
contourColor - The contour color. Here it can be passed color( r, g, b) Processing method.
thickness - The contour thickness. This parameter is passed to strokeWeight Processing method.
See Also:
loadBlobsFeatures()

drawBox

public void drawBox(int boxColor,
                    float thickness)
Draws the blob bounding box.

Parameters:
boxColor - The bounding box color. Here it can be passed color( r, g, b) Processing function. This parameter is passed to stroke Processing method. findBlobs() or imageFindBlobs(PImage), loadBlobsFeatures() methods must be called before to call this method.
thickness - The bounding box thickness. This parameter is passed to strokeWeight Processing method.

drawSelectBox

public void drawSelectBox(int minimumWeight,
                          int boxColor,
                          float thickness)
Draws the blob's bounding box only for blobs which weight is bigger than or equals to minimumWeight parameter value. imageFindBlobs(PImage),findBlobs() or weightBlobs(boolean) , loadBlobsFeatures() methods must be called before to call this method.

Parameters:
minimumWeight - The minimum weight of the blob for which the bounding box is drawn
boxColor - The bounding box color. Here it can be passed color( r, g, b) Processing function.
thickness - The edges thickness. This parameter is passed to strokeWeight Processing function.
See Also:
loadBlobsFeatures(), weightBlobs(boolean)

isBlob

public boolean isBlob(int x,
                      int y)
Returns true if at x y location finds a blob pixel. findBlobs() or imageFindBlobs(PImage) methods must be called before to call this method.

Parameters:
x - The x location of the pixel to check.
y - The y location of the pixel to check.
Returns:
Returns true if at x y location finds a blob pixels.

isEdge

public boolean isEdge(int x,
                      int y)
Returns true if the pixel at x y coordinates is a blob edge pixel. findBlobs() or imageFindBlobs(PImage) must be called first to call this method.

Parameters:
x - The screen x coordinate to check.
y - The screen y coordinate to check.
Returns:
Returns true if the pixel at x y coordinates is a blob edge pixel.

isMatch

public boolean isMatch(int x,
                       int y,
                       int blobToMatch)
Returns true only if the pixel at the coordinates x y is inside the blob represented by the parameter blobToMatch. findBlobs() or imageFindBlobs(PImage) must be called first to call this method.

Parameters:
x - The X coordinate of the pixel to test.
y - The Y coordinate of the pixel to test.
blobToMatch - The blob to match
Returns:
Returns true only if the pixel at the coordinates x y is inside the blob represented by the parameterblobToMatch.

loadBlobsFeatures

public void loadBlobsFeatures()
findBlobs() or imageFindBlobs(PImage) methods must be called before to call this method. This method must be called before any call to one of the followings methods : getA, getB, getC, getD, getBlobWidth, getBlobHeight, getBoxCentX, getBoxCentY, getCentroidX, getCentroidY, getcrossPoints, getEdgeX, getEdgeY, getEdgeXY, findCentroids.

See Also:
getA(), getB(), getC(), getD(), getBoxCentX(int), getBoxCentY(int), getBlobWidth(int), getBlobHeight(int), findCentroids(boolean, boolean), getCentroidX(int), getCentroidY(int), getEdgeX(int, int), getEdgeY(int, int), #getEdgeXY(int), getCrossPoints(int, int, boolean)

findCentroids

public void findCentroids(boolean printLocation,
                          boolean drawCentroids)
Calculates the blob centroids. findBlobs() or imageFindBlobs(PImage), weightBlobs(boolean) and loadBlobsFeatures() methods must be called first to call this method. Also this method must be called always before callinggetCentroidX(int)<,/code> and getCentroidY(int) methods.

Parameters:
printLocation - If true prints to the console the blob's centroid coordinate x y.
drawCentroids - If true draws a point at the centroid coordinates.
See Also:
getCentroidX(int), getCentroidY(int), weightBlobs(boolean), loadBlobsFeatures()

getCentroidX

public float getCentroidX(int blobnumber)
Returns the blob centroid x coordinate. findBlobs() or imageFindBlobs(PImage), weightBlobs(boolean), findCentroids(boolean, boolean) and loadBlobsFeatures() methods must be called before to call this method.

Parameters:
blobnumber - The blob for which the centroid is returned.
Returns:
the blob centroid x coordinates.
See Also:
findCentroids(boolean,boolean)

getCentroidY

public float getCentroidY(int blobnumber)
Returns the blob centroid y coordinate. findBlobs() or imageFindBlobs(PImage), weightBlobs(boolean), findCentroids(boolean, boolean) and loadBlobsFeatures() methods must be called first to call this method.

Parameters:
blobnumber - The blob for which the centroid is returned.
Returns:
the blob centroid y coordinates.
See Also:
findCentroids(boolean,boolean)

getBlobWidth

public int getBlobWidth(int blobnumber)
Returns the blob width. findBlobs() or imageFindBlobs(PImage), loadBlobsFeatures() methods must be called before to call this method.

Parameters:
blobnumber -
Returns:
the width of the blob referred by the parameter.
See Also:
loadBlobsFeatures()

getBlobHeight

public int getBlobHeight(int blobnumber)
Returns the blob height. findBlobs() or imageFindBlobs(PImage), loadBlobsFeatures() methods must be called before to call this method.

Parameters:
blobnumber -
Returns:
the heigh of the blob referred by the parameter.
See Also:
loadBlobsFeatures()

getBlobsNumber

public int getBlobsNumber()
The total number of blobs in the current frame or image. findBlobs() or imageFindBlobs(PImage) methods must be called first to call this method.

Returns:
The total number of blobs in the current frame or image.

getGlobalWeight

public int getGlobalWeight()
Get the total weight for all the blobs in the current frame or image. findBlobs() or imageFindBlobs(PImage) methods must be called first to call this method.

Returns:
countBlobPixel The total weight for all the blobs in the current frame or image.

getBlobWeight

public int getBlobWeight(int blobNum)
Returns the weight of the blob specified. findBlobs() or imageFindBlobs(PImage), weightBlobs(boolean), methods must be called first to call this method.

Parameters:
blobNum - The number of the blob for which the weight is returned. The first blob is numbered with 0.
Returns:
The weight of the blob specified by the parameter blobNum.

getBlobWeightLabel

public int getBlobWeightLabel(int label)
Returns the weight of the blob with the specified label. The first label is numbered with 1. The labels are not consecutive. You can use getLabel(int blobnumber) or getLabel(int x, int y) to find the a blob label number to pass to this method. findBlobs() or imageFindBlobs(PImage), weightBlobs(boolean), and loadBlobsFeatures() methods must be called before to call this method.

Parameters:
label - The label of the blob for which the weight is returned. The labels start from 1, not 0.
Returns:
The weight of the blob labelled with the parameter label.
See Also:
weightBlobs(boolean), getLabel(int), getLabel(int, int)

getA

public processing.core.PVector[] getA()
Returns an array of PVectors which contains all the left upper corners of the blobs bounding boxes. findBlobs() or imageFindBlobs(PImage), loadBlobsFeatures() methods must be called first to call this method.

Returns:
A An array of PVectors. Each vector represents the left upper corner of a blob's bounding box.

getB

public processing.core.PVector[] getB()
Returns an array of PVectors which contains all the right upper corners of the blobs bounding boxes. findBlobs() or imageFindBlobs(PImage), loadBlobsFeatures() methods must be called first to call this method.

Returns:
B An array of PVectors. Each vector represents the right upper corner of a blob's bounding box .

getC

public processing.core.PVector[] getC()
Returns an array of PVectors which contains all the left lower corners of the blobs bounding boxes. findBlobs() or imageFindBlobs(PImage), loadBlobsFeatures() methods must be called first to call this method.

Returns:
C An array of PVectors. Each vector represents the left lower corner of a blob's bounding box .

getD

public processing.core.PVector[] getD()
Returns an array of PVectors which contains all the right lower corners of the blobs bounding boxes. findBlobs() or imageFindBlobs(PImage), loadBlobsFeatures() methods must be called first to call this method.

Returns:
D An array of PVectors. Each vector represents the right lower corner of a blob's bounding box .

getBlobNumberAt

public int getBlobNumberAt(int x,
                           int y)
Returns the blob number at the x y coordinates. If at these coordinate there isn't a blob returns -1; findBlobs() or imageFindBlobs(PImage) must be called first to call this method.

Parameters:
x - The X coordinate to check for blob presence.
y - The Y coordinate to check for blob presence.
Returns:
Returns the blob number at the x y coordinates. If at these coordinate there isn't a blob returns -1;

getLabel

public int getLabel(int x,
                    int y)
Returns the blob label at x, y screen coordinates. If at that location there is no blob returns 0. findBlobs() or imageFindBlobs(PImage) must be called first to call this method.

Parameters:
x - The x screen coordinates.
y - The y screen coordinates.
Returns:
The value of the label at x y;

getLabel

public int getLabel(int blobnumber)
Returns the label of the blob indicated by the blobnumber parameter. blobnumber can be from 0 to getBlobsNumber() If there are 5 blobs, blobnumber = 4 returns the label of the 5th blob in the image counting from top left. findBlobs() or imageFindBlobs(PImage) must be called first to call this method.

Parameters:
blobnumber - The blob for which the label is returned.
Returns:
Blob's label.

getEdgeX

@Deprecated
public int getEdgeX(int blobnumber,
                               int index)
Deprecated. 

Use getEdgePoints(int blobnumber) instead.


getEdgeY

@Deprecated
public int getEdgeY(int blobnumber,
                               int index)
Deprecated. 

Use getEdgePoints(int blobnumber) instead.


getEdgeXY

@Deprecated
public processing.core.PVector[] getEdgeXY()
Deprecated. 

Use getEdgePoints(int blobnumber) instead.


getEdgePoints

public processing.core.PVector[] getEdgePoints(int blobnumber)
Computes the coordinates of the edge's pixels for the specified blob. findBlobs(int[], int, int) or imageFindBlobs(PImage), loadBlobsFeatures() must be called first to call this method.

Parameters:
blobnumber - The blob for which the edge's pixels coordinates are computed
Returns:
edgeCoordinates A PVector array containing the coordinates of the specified blob's edge points

getEdgeSize

public int getEdgeSize(int blobnumber)
Computes the number of edge pixels for the specified blob. findBlobs(int[], int, int) or imageFindBlobs(PImage), loadBlobsFeatures() must be called first to call this method.

Parameters:
blobnumber - The blob for which the number of edge pixels is computed.
Returns:
countEdgePoints The number of pixels in the edge.

getBlobPixelsLocation

public processing.core.PVector[] getBlobPixelsLocation(int blobnumber)
Computes and returns the coordinates of all the pixels in the specified blob. findBlobs() or imageFindBlobs(PImage), weightBlobs(boolean), and loadBlobsFeatures() methods must be called before to call this method.

Parameters:
blobnumber - The blob for which the pixels coordinates are computed.
Returns:
pixelsCoordinates The array of PVector objects containing the blob pixels coordinates.

getBoxCentX

public float getBoxCentX(int blobnumber)
Returns the x coordinates of the bounding box center. findBlobs() or imageFindBlobs(PImage), loadBlobsFeatures() must be called first to call this method.

Parameters:
blobnumber - The blob number ( starts from 0 ).
Returns:
x the x coordinates of the bounding box center.
See Also:
loadBlobsFeatures()

getBoxCentY

public float getBoxCentY(int blobnumber)
Returns the y coordinates of the bounding box center. findBlobs() or imageFindBlobs(PImage), loadBlobsFeatures() must be called first to call this method.

Parameters:
blobnumber - The blob number ( starts from 0 ).
Returns:
y the y coordinates of the bounding box center.
See Also:
loadBlobsFeatures()

getCrossPoints

public processing.core.PVector getCrossPoints(int blobnumber,
                                              int pointVector,
                                              boolean draw_them)
Finds the coordinates of the middle point of the blob's bounding box side. findBlobs() or imageFindBlobs(PImage), loadBlobsFeatures() and weightBlobs(boolean) methods must be called before to call this method.

Parameters:
blobnumber - The blob you need to compute the points for.
pointVector - The point you need extract( 0 | 1 | 2 | 3 ). The order of the vectors in the array is : 0 = top, 1 = down, 2 = left, 3 = right.
draw_them - If true draws the four points.
Returns:
The PVector containing the point coordinates (x, y).
See Also:
loadBlobsFeatures(), weightBlobs(boolean)