Skip to content

Commit

Permalink
remove remaning references to the term 'buffer'
Browse files Browse the repository at this point in the history
  • Loading branch information
atduskgreg committed Jul 9, 2013
1 parent 6281727 commit 632494a
Showing 1 changed file with 34 additions and 35 deletions.
69 changes: 34 additions & 35 deletions src/gab/opencv/OpenCV.java
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ public boolean getUseColor(){
return useColor;
}

private Mat getCurrentBuffer(){
private Mat getCurrentMat(){
if(useROI){
return matROI;

Expand Down Expand Up @@ -345,7 +345,7 @@ public void loadCascade(String cascadeFileName){

public Rectangle[] detect(){
MatOfRect detections = new MatOfRect();
classifier.detectMultiScale(getCurrentBuffer(), detections);
classifier.detectMultiScale(getCurrentMat(), detections);

Rect[] rects = detections.toArray();

Expand All @@ -362,8 +362,8 @@ public void startBackgroundSubtraction(int history, int nMixtures, double backgr
}

public void updateBackground(){
Mat foreground = imitate(getCurrentBuffer());
backgroundSubtractor.apply(getCurrentBuffer(), foreground, 0.05);
Mat foreground = imitate(getCurrentMat());
backgroundSubtractor.apply(getCurrentMat(), foreground, 0.05);
setGray(foreground);
}

Expand All @@ -384,7 +384,7 @@ public void contrast(float amt){
modifier = new Scalar(amt);
}

Core.multiply(getCurrentBuffer(), modifier, getCurrentBuffer());
Core.multiply(getCurrentMat(), modifier, getCurrentMat());
}

/**
Expand All @@ -394,7 +394,7 @@ public void contrast(float amt){
* A PVector with the location of the maximum value.
*/
public PVector max(){
MinMaxLocResult r = Core.minMaxLoc(getCurrentBuffer());
MinMaxLocResult r = Core.minMaxLoc(getCurrentMat());
return OpenCV.pointToPVector(r.maxLoc);
}

Expand All @@ -405,7 +405,7 @@ public PVector max(){
* A PVector with the location of the minimum value.
*/
public PVector min(){
MinMaxLocResult r = Core.minMaxLoc(getCurrentBuffer());
MinMaxLocResult r = Core.minMaxLoc(getCurrentMat());
return OpenCV.pointToPVector(r.minLoc);
}

Expand All @@ -430,7 +430,7 @@ public void brightness(int amt){
modifier = new Scalar(amt);
}

Core.add(getCurrentBuffer(), modifier, getCurrentBuffer());
Core.add(getCurrentMat(), modifier, getCurrentMat());
}

public static Mat imitate(Mat m){
Expand All @@ -442,16 +442,16 @@ public void diff(PImage img){
Mat imgMat = imitate(getColor());
toCv(img, imgMat);

Mat dst = imitate(getCurrentBuffer());
Mat dst = imitate(getCurrentMat());

if(useColor){
ARGBtoBGRA(imgMat, imgMat);
Core.absdiff(getCurrentBuffer(), imgMat, dst);
Core.absdiff(getCurrentMat(), imgMat, dst);
} else {
Core.absdiff(getCurrentBuffer(), OpenCV.gray(imgMat), dst);
Core.absdiff(getCurrentMat(), OpenCV.gray(imgMat), dst);
}

dst.assignTo(getCurrentBuffer());
dst.assignTo(getCurrentMat());
}

public static void diff(Mat mat1, Mat mat2){
Expand All @@ -461,58 +461,58 @@ public static void diff(Mat mat1, Mat mat2){
}

public void threshold(int threshold){
Imgproc.threshold(getCurrentBuffer(), getCurrentBuffer(), threshold, 255, Imgproc.THRESH_BINARY);
Imgproc.threshold(getCurrentMat(), getCurrentMat(), threshold, 255, Imgproc.THRESH_BINARY);
}

public void adaptiveThreshold(int blockSize, int c){
try{
Imgproc.adaptiveThreshold(getCurrentBuffer(), getCurrentBuffer(), 255, Imgproc.ADAPTIVE_THRESH_GAUSSIAN_C, Imgproc.THRESH_BINARY, blockSize, c);
Imgproc.adaptiveThreshold(getCurrentMat(), getCurrentMat(), 255, Imgproc.ADAPTIVE_THRESH_GAUSSIAN_C, Imgproc.THRESH_BINARY, blockSize, c);
} catch(CvException e){
PApplet.println("ERROR: adaptiveThreshold function only works on gray images.");
}
}

public void equalizeHistogram(){
try{
Imgproc.equalizeHist(getCurrentBuffer(), getCurrentBuffer());
Imgproc.equalizeHist(getCurrentMat(), getCurrentMat());
} catch(CvException e){
PApplet.println("ERROR: equalizeHistogram only works on a gray image.");
}
}

public void invert(){
Core.bitwise_not(getCurrentBuffer(),getCurrentBuffer());
Core.bitwise_not(getCurrentMat(),getCurrentMat());
}

public void dilate(){
Imgproc.dilate(getCurrentBuffer(), getCurrentBuffer(), new Mat());
Imgproc.dilate(getCurrentMat(), getCurrentMat(), new Mat());
}

public void erode(){
Imgproc.erode(getCurrentBuffer(), getCurrentBuffer(), new Mat());
Imgproc.erode(getCurrentMat(), getCurrentMat(), new Mat());
}

public void blur(int blurSize){
Imgproc.blur(getCurrentBuffer(), getCurrentBuffer(), new Size(blurSize, blurSize));
Imgproc.blur(getCurrentMat(), getCurrentMat(), new Size(blurSize, blurSize));
}

public void findCannyEdges(int lowThreshold, int highThreshold){
Imgproc.Canny(getCurrentBuffer(), getCurrentBuffer(), lowThreshold, highThreshold);
Imgproc.Canny(getCurrentMat(), getCurrentMat(), lowThreshold, highThreshold);
}

public void findSobelEdges(int dx, int dy){
Mat sobeled = new Mat(getCurrentBuffer().height(), getCurrentBuffer().width(), CvType.CV_32F);
Imgproc.Sobel(getCurrentBuffer(), sobeled, CvType.CV_32F, dx, dy);
sobeled.convertTo(getCurrentBuffer(), getCurrentBuffer().type());
Mat sobeled = new Mat(getCurrentMat().height(), getCurrentMat().width(), CvType.CV_32F);
Imgproc.Sobel(getCurrentMat(), sobeled, CvType.CV_32F, dx, dy);
sobeled.convertTo(getCurrentMat(), getCurrentMat().type());
}

public void findScharrEdges(int direction){
if(direction == HORIZONTAL){
Imgproc.Scharr(getCurrentBuffer(), getCurrentBuffer(), -1, 1, 0 );
Imgproc.Scharr(getCurrentMat(), getCurrentMat(), -1, 1, 0 );
}

if(direction == VERTICAL){
Imgproc.Scharr(getCurrentBuffer(), getCurrentBuffer(), -1, 0, 1 );
Imgproc.Scharr(getCurrentMat(), getCurrentMat(), -1, 0, 1 );
}
}

Expand All @@ -527,7 +527,7 @@ public ArrayList<Contour> findContours(boolean findHoles, boolean sort){
try{
int contourFindingMode = (findHoles ? Imgproc.RETR_LIST : Imgproc.RETR_EXTERNAL);

Imgproc.findContours(getCurrentBuffer(), contourMat, new Mat(), contourFindingMode, Imgproc.CHAIN_APPROX_NONE);
Imgproc.findContours(getCurrentMat(), contourMat, new Mat(), contourFindingMode, Imgproc.CHAIN_APPROX_NONE);
} catch(CvException e){
PApplet.println("ERROR: findContours only works with a gray image.");
}
Expand All @@ -544,14 +544,14 @@ public ArrayList<Contour> findContours(boolean findHoles, boolean sort){

public ArrayList<PVector> findChessboardCorners(int patternWidth, int patternHeight){
MatOfPoint2f corners = new MatOfPoint2f();
Calib3d.findChessboardCorners(getCurrentBuffer(), new Size(patternWidth,patternHeight), corners);
Calib3d.findChessboardCorners(getCurrentMat(), new Size(patternWidth,patternHeight), corners);
return matToPVectors(corners);
}

/**
*
* @param buffer
* The buffer from which to calculate the histogram. Get this from getBufferGray(), getBufferR(), getBufferG(), or getBufferB().
* @param mat
* The mat from which to calculate the histogram. Get this from getGray(), getR(), getG(), getB(), etc..
* By default this will normalize the histogram (scale the values to 0.0-1.0). Pass false as the third argument to keep values unormalized.
* @param numBins
* The number of bins into which divide the histogram should be divided.
Expand All @@ -560,12 +560,12 @@ public ArrayList<PVector> findChessboardCorners(int patternWidth, int patternHei
* @return
* A Histogram object that you can call draw() on.
*/
public Histogram findHistogram(Mat buffer, int numBins){
return findHistogram(buffer, numBins, true);
public Histogram findHistogram(Mat mat, int numBins){
return findHistogram(mat, numBins, true);
}


public Histogram findHistogram(Mat buffer, int numBins, boolean normalize){
public Histogram findHistogram(Mat mat, int numBins, boolean normalize){

MatOfInt channels = new MatOfInt(0);
MatOfInt histSize = new MatOfInt(numBins);
Expand All @@ -574,7 +574,7 @@ public Histogram findHistogram(Mat buffer, int numBins, boolean normalize){
Mat hist = new Mat();

ArrayList<Mat> images = new ArrayList<Mat>();
images.add(buffer);
images.add(mat);

Imgproc.calcHist( images, channels, new Mat(), hist, histSize, ranges);

Expand All @@ -583,7 +583,6 @@ public Histogram findHistogram(Mat buffer, int numBins, boolean normalize){
}

return new Histogram(parent, hist);

}

/**
Expand All @@ -596,7 +595,7 @@ public Histogram findHistogram(Mat buffer, int numBins, boolean normalize){
* @param upperBound
*/
public void inRange(int lowerBound, int upperBound){
Core.inRange(getCurrentBuffer(), new Scalar(lowerBound), new Scalar(upperBound), getCurrentBuffer());
Core.inRange(getCurrentMat(), new Scalar(lowerBound), new Scalar(upperBound), getCurrentMat());
}

/**
Expand Down

0 comments on commit 632494a

Please sign in to comment.