|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object gab.opencv.OpenCV
public class OpenCV
This is a template class and can be used to start a new processing library or tool. Make sure you rename this class as well as the name of the example package 'template' to your own library or tool naming convention.
Field Summary | |
---|---|
static int |
BOTH
|
static String |
CASCADE_CLOCK
|
static String |
CASCADE_EYE
|
static String |
CASCADE_FRONTALFACE
|
static String |
CASCADE_FULLBODY
|
static String |
CASCADE_LOWERBODY
|
static String |
CASCADE_MOUTH
|
static String |
CASCADE_NOSE
|
static String |
CASCADE_PEDESTRIAN
|
static String |
CASCADE_PEDESTRIANS
|
static String |
CASCADE_PROFILEFACE
|
static String |
CASCADE_RIGHT_EAR
|
static String |
CASCADE_UPPERBODY
|
CascadeClassifier |
classifier
|
int |
colorSpace
|
Flow |
flow
|
int |
height
|
static int |
HORIZONTAL
|
Mat |
matA
|
Mat |
matB
|
Mat |
matBGRA
|
Mat |
matG
|
Mat |
matGray
|
Mat |
matH
|
Mat |
matHSV
|
Mat |
matR
|
Mat |
matROI
|
Mat |
matS
|
Mat |
matV
|
Mat |
nonROImat
|
static String |
VERSION
|
static int |
VERTICAL
|
int |
width
|
Constructor Summary | |
---|---|
OpenCV(PApplet theParent,
int width,
int height)
Initialize OpenCV with a width and height. |
|
OpenCV(PApplet theParent,
PImage img)
Initialize OpenCV with an image. |
|
OpenCV(PApplet theParent,
PImage img,
boolean useColor)
Initialize OpenCV with an image. |
|
OpenCV(PApplet theParent,
String pathToImg)
Initialize OpenCV with the path to an image. |
|
OpenCV(PApplet theParent,
String pathToImg,
boolean useColor)
Initialize OpenCV with the path to an image. |
Method Summary | |
---|---|
void |
adaptiveThreshold(int blockSize,
int c)
Apply an adaptive threshold to an image. |
static void |
ARGBtoBGRA(Mat rgba,
Mat bgra)
|
void |
blur(int blurSize)
Blur an image symetrically by a given number of pixels. |
void |
blur(int blurW,
int blurH)
Blur an image assymetrically by a different number of pixels in x- and y-directions. |
void |
brightness(int amt)
Adjust the brightness of the image. |
void |
calculateOpticalFlow()
Calculate the optical flow of the current image relative to a running series of images (typically frames from video). |
void |
contrast(float amt)
Adjust the contrast of the image. |
Rectangle[] |
detect()
Detect objects using the cascade classifier. |
Rectangle[] |
detect(double scaleFactor,
int minNeighbors,
int flags,
int minSize,
int maxSize)
Detect objects using the cascade classifier. |
static void |
diff(Mat mat1,
Mat mat2)
A helper function that diffs two Mats using absdiff. |
void |
diff(PImage img)
Calculate the difference between the current image loaded into OpenCV and a second image. |
void |
dilate()
Dilate the image. |
void |
drawOpticalFlow()
|
void |
equalizeHistogram()
Normalize the histogram of the image. |
void |
erode()
Erode the image. |
void |
findCannyEdges(int lowThreshold,
int highThreshold)
Find edges in the image using Canny edge detection. |
ArrayList<PVector> |
findChessboardCorners(int patternWidth,
int patternHeight)
|
ArrayList<Contour> |
findContours()
|
ArrayList<Contour> |
findContours(boolean findHoles,
boolean sort)
|
Histogram |
findHistogram(Mat mat,
int numBins)
|
Histogram |
findHistogram(Mat mat,
int numBins,
boolean normalize)
|
ArrayList<Line> |
findLines(int threshold,
double minLineLength,
double maxLineGap)
|
void |
findScharrEdges(int direction)
|
void |
findSobelEdges(int dx,
int dy)
|
void |
flip(int direction)
Flip the current image. |
Mat |
getA()
|
PVector |
getAverageFlow()
|
PVector |
getAverageFlowInRegion(int x,
int y,
int w,
int h)
|
Mat |
getB()
|
Mat |
getColor()
|
int |
getColorSpace()
Get the colorSpace of the current color image. |
PVector |
getFlowAt(int x,
int y)
|
Mat |
getG()
|
Mat |
getGray()
|
Mat |
getH()
|
PImage |
getInput()
|
PImage |
getOutput()
|
Mat |
getR()
|
Mat |
getROI()
|
Mat |
getS()
|
int |
getSize()
|
PImage |
getSnapshot()
|
PImage |
getSnapshot(Mat m)
|
PVector |
getTotalFlow()
|
PVector |
getTotalFlowInRegion(int x,
int y,
int w,
int h)
|
boolean |
getUseColor()
Checks whether OpenCV is currently using the color version of the image or the grayscale version. |
Mat |
getV()
|
void |
gray()
|
static Mat |
gray(Mat src)
|
static Mat |
imitate(Mat m)
Helper to create a new OpenCV Mat whose channels and bit-depth mask an existing Mat. |
void |
inRange(int lowerBound,
int upperBound)
Filter the image for values between a lower and upper bound. |
void |
invert()
Invert the image. |
void |
loadCascade(String cascadeFileName)
Load a cascade file for face or object detection. |
void |
loadCascade(String cascadeFilePath,
boolean absolute)
Load a cascade file for face or object detection. |
void |
loadImage(PImage img)
|
void |
loadImage(String imgPath)
Load an image from a path. |
int[] |
matToARGBPixels(Mat m)
Convert a 4 channel OpenCV Mat object into pixels to be shoved into a 4 channel ARGB PImage's pixel array. |
static ArrayList<PVector> |
matToPVectors(MatOfPoint mat)
|
static ArrayList<PVector> |
matToPVectors(MatOfPoint2f mat)
|
String |
matToS(Mat mat)
|
PVector |
max()
Get the x-y location of the maximum value in the current image. |
PVector |
min()
Get the x-y location of the minimum value in the current image. |
static PVector |
pointToPVector(Point p)
Helper function to convert an OpenCV Point into a Processing PVector |
void |
releaseROI()
|
void |
setColor(Mat m)
|
void |
setGray(Mat m)
|
boolean |
setROI(int x,
int y,
int w,
int h)
Set a Region of Interest within the image. |
void |
startBackgroundSubtraction(int history,
int nMixtures,
double backgroundRatio)
Setup background subtraction. |
void |
threshold(int threshold)
Apply a global threshold to an image. |
static void |
toCv(PImage img,
Mat m)
Convert a Processing PImage to an OpenCV Mat. |
void |
toPImage(Mat m,
PImage img)
Convert an OpenCV Mat object into a PImage to be used in other Processing code. |
static Rectangle[] |
toProcessing(Rect[] rects)
Convert an array of OpenCV Rect objects into an array of java.awt.Rectangle rectangles. |
void |
updateBackground()
Update the running background for background subtraction based on the current image loaded into OpenCV. |
void |
useColor()
Apply subsequent image processing to the color version of the loaded image. |
void |
useColor(int colorSpace)
Set the main working image to be the color version of the imported image. |
void |
useGray()
Set OpenCV to do image processing on the grayscale version of the loaded image. |
static String |
version()
return the version of the library. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public int width
public int height
public Mat matBGRA
public Mat matR
public Mat matG
public Mat matB
public Mat matA
public Mat matHSV
public Mat matH
public Mat matS
public Mat matV
public Mat matGray
public Mat matROI
public Mat nonROImat
public int colorSpace
public CascadeClassifier classifier
public Flow flow
public static final String VERSION
public static final String CASCADE_FRONTALFACE
public static final String CASCADE_PEDESTRIANS
public static final String CASCADE_EYE
public static final String CASCADE_CLOCK
public static final String CASCADE_NOSE
public static final String CASCADE_MOUTH
public static final String CASCADE_UPPERBODY
public static final String CASCADE_LOWERBODY
public static final String CASCADE_FULLBODY
public static final String CASCADE_PEDESTRIAN
public static final String CASCADE_RIGHT_EAR
public static final String CASCADE_PROFILEFACE
public static final int HORIZONTAL
public static final int VERTICAL
public static final int BOTH
Constructor Detail |
---|
public OpenCV(PApplet theParent, String pathToImg)
theParent
- - A PApplet representing the user sketch, i.e "this"pathToImg
- - A String with a path to the image to be loadedpublic OpenCV(PApplet theParent, String pathToImg, boolean useColor)
theParent
- - A PApplet representing the user sketch, i.e "this"pathToImg
- - A String with a path to the image to be loadeduseColor
- - (Optional) Set to true if you want to use the color version of the image for processing.public OpenCV(PApplet theParent, PImage img)
theParent
- A PApplet representing the user sketch, i.e "this"img
- A PImage to be loadedpublic OpenCV(PApplet theParent, PImage img, boolean useColor)
theParent
- A PApplet representing the user sketch, i.e "this"img
- A PImage to be loadeduseColor
- (Optional) Set to true if you want to use the color version of the image for processing.public OpenCV(PApplet theParent, int width, int height)
theParent
- A PApplet representing the user sketch, i.e "this"width
- intheight
- intMethod Detail |
---|
public void useColor()
public int getColorSpace()
public void useColor(int colorSpace)
colorSpace
- The color space of the image to be processed. Either RGB or HSB.public void useGray()
public boolean getUseColor()
public void loadCascade(String cascadeFileName)
OpenCV.CASCADE_FRONTALFACE OpenCV.CASCADE_PEDESTRIANS OpenCV.CASCADE_EYE OpenCV.CASCADE_CLOCK OpenCV.CASCADE_NOSE OpenCV.CASCADE_MOUTH OpenCV.CASCADE_UPPERBODY OpenCV.CASCADE_LOWERBODY OpenCV.CASCADE_FULLBODY OpenCV.CASCADE_PEDESTRIANS OpenCV.CASCADE_RIGHT_EAR OpenCV.CASCADE_PROFILEFACETo pass your own cascade file, provide an absolute path and a second argument of true, thusly:
opencv.loadCascade("/path/to/my/custom/cascade.xml", true)(NB: ant build scripts copy the data folder outside of the jar so that this will work.)
cascadeFileName
- The name of the cascade file to be loaded form within OpenCV for Processing.
Must be one of the constants provided by this librarypublic void loadCascade(String cascadeFilePath, boolean absolute)
cascadeFilePath
- A string. Either an absolute path to a cascade XML file or
one of the constants provided by this library.absolute
- Whether or not the cascadeFilePath is an absolute path to an XML file.public static Rectangle[] toProcessing(Rect[] rects)
Rect[]
- rects
public Rectangle[] detect(double scaleFactor, int minNeighbors, int flags, int minSize, int maxSize)
scaleFactor
- minNeighbors
- flags
- minSize
- maxSize
-
public Rectangle[] detect()
public void startBackgroundSubtraction(int history, int nMixtures, double backgroundRatio)
history
- nMixtures
- backgroundRatio
- public void updateBackground()
public void calculateOpticalFlow()
public PVector getTotalFlowInRegion(int x, int y, int w, int h)
public PVector getAverageFlowInRegion(int x, int y, int w, int h)
public PVector getTotalFlow()
public PVector getAverageFlow()
public PVector getFlowAt(int x, int y)
public void drawOpticalFlow()
public void flip(int direction)
direction
- One of: OpenCV.HORIZONTAL, OpenCV.VERTICAL, or OpenCV.BOTHpublic void contrast(float amt)
amt
- Amount of contrast to apply. 0-1.0 reduces contrast. Above 1.0 increases contrast.public PVector max()
public PVector min()
public static PVector pointToPVector(Point p)
p
- A Point
public void brightness(int amt)
amt
- The amount to brighten the image. Ranges -255 to 255.public static Mat imitate(Mat m)
m
- The Mat to match
public void diff(PImage img)
img
- A PImage to diff against.public static void diff(Mat mat1, Mat mat2)
mat1
- The destination Matmat2
- The Mat to diff againstpublic void threshold(int threshold)
threshold
- An int from 0-255.public void adaptiveThreshold(int blockSize, int c)
blockSize
- The size of the pixel neighborhood to use.c
- A constant subtracted from the mean of each neighborhood.public void equalizeHistogram()
public void invert()
public void dilate()
public void erode()
public void blur(int blurSize)
blurSize
- int - the amount to blur by in x- and y-directions.public void blur(int blurW, int blurH)
blurW
- amount to blur in the x-directionblurH
- amount to blur in the y-directionpublic void findCannyEdges(int lowThreshold, int highThreshold)
lowThreshold
- highThreshold
- public void findSobelEdges(int dx, int dy)
public void findScharrEdges(int direction)
public ArrayList<Contour> findContours()
public ArrayList<Contour> findContours(boolean findHoles, boolean sort)
public ArrayList<Line> findLines(int threshold, double minLineLength, double maxLineGap)
public ArrayList<PVector> findChessboardCorners(int patternWidth, int patternHeight)
public Histogram findHistogram(Mat mat, int numBins)
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.numBins
- The number of bins into which divide the histogram should be divided.normalize
- (optional)
Whether or not to normalize the histogram (scale the values to 0.0-1.0). Defaults to true.
public Histogram findHistogram(Mat mat, int numBins, boolean normalize)
public void inRange(int lowerBound, int upperBound)
lowerBound
- upperBound
- public static Mat gray(Mat src)
src
- A Mat of type 8UC4 with channels arranged as BGRA.
public void gray()
public boolean setROI(int x, int y, int w, int h)
public void releaseROI()
public void loadImage(String imgPath)
imgPath
- String with the path to the imagepublic void loadImage(PImage img)
public static void ARGBtoBGRA(Mat rgba, Mat bgra)
public int getSize()
public int[] matToARGBPixels(Mat m)
m
- An RGBA Mat we want converted
public void toPImage(Mat m, PImage img)
m
- A Mat you want convertedimg
- The PImage you want the Mat converted into.public static void toCv(PImage img, Mat m)
img
- The PImage to convert.m
- The Mat to receive the image data.public static ArrayList<PVector> matToPVectors(MatOfPoint mat)
public static ArrayList<PVector> matToPVectors(MatOfPoint2f mat)
public String matToS(Mat mat)
public PImage getInput()
public PImage getOutput()
public PImage getSnapshot()
public PImage getSnapshot(Mat m)
public Mat getR()
public Mat getG()
public Mat getB()
public Mat getA()
public Mat getH()
public Mat getS()
public Mat getV()
public Mat getGray()
public void setGray(Mat m)
public void setColor(Mat m)
public Mat getColor()
public Mat getROI()
public static String version()
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |