ofDocsdocumentation addons ofxOpenCv ofxCvImage

ofxCvImage

This is the base class for all the ofxOpenCV image types: ofxCvShortImage, ofxCvColorImage, ofxCvFloatImage, ofxCvGrayscaleImage. It's made to provide interoperability between the core OF imaging types, ofImage and ofTexture, and OpenCv.


allocate( ... )

void allocate(int w, int h)

Allocates the image with the w, h passed in. This must be done before the pixels of the image are created.


allocatePixels( ... )

void allocatePixels(int w, int h)

allocateTexture( )

void allocateTexture()

blur( ... )

void blur(int value=3)

Blurs the image

![Blurring] (../blur.png "Blurring an image original on Left")


blurGaussian( ... )

void blurGaussian(int value=3)

Blurs the using Gaussian blurring. Gaussian blurring is typically to reduce image noise and reduce detail.


clear( )

void clear()

Clears the pixel data of the image. The image must be allocated again with a call to allocate() before it can be used.


contrastStretch( )

void contrastStretch()

This increases the contrast of the image remapping the brightest points in the image to 255 and the darkest points in the image to 0.


convertToRange( ... )

void convertToRange(float min, float max)

Maps the pixels of an image to the min and max range passed in.


colors.setFromPixels(grabber.getPixels());

first = colors; // will leave unaltered
second = colors; // change it
second.convertToRange(100, 140); // super low contrast

Image convert to range


countNonZeroInRegion( ... )

int countNonZeroInRegion(int x, int y, int w, int h)

Returns the number of non-zero pixels in an image.


dilate( )

void dilate()

![Dilating] (../dilate.png "Dilating an image, original on Left")


draw( ... )

void draw(float x, float y)

Draw the image at the x,y.


draw( ... )

void draw(float x, float y, float w, float h)

Draw the image at the x,y with the w,h.


draw( ... )

void draw(const ofPoint &point)

Draw the image at the ofPoint passed in.


draw( ... )

void draw(const ofRectangle &rect)

Draw the image into the ofRectangle passed in.


drawBlobIntoMe( ... )

void drawBlobIntoMe(ofxCvBlob &blob, int color)

Draw the outline of an ofxCvblob into the ofxCvImage.


drawROI( ... )

void drawROI(float x, float y)

Draw just the Region of Interest of the image at the x,y.


drawROI( ... )

void drawROI(float x, float y, float w, float h)

Draw just the Region of Interest of the image into the x,y with the w,h passed in.


erode( )

void erode()

Erodes the image.

![Eroding] (../erode.png "Eroding an image, original on Left")


flagImageChanged( )

void flagImageChanged()

Marks the image as changed so that the ofTexture can be updated, if the image contains one.


getCv8BitsImage( )

int * getCv8BitsImage()

getCv8BitsRoiImage( )

int * getCv8BitsRoiImage()

getCvImage( )

int * getCvImage()

Returns a raw pointer to the OpenCV IplImage.


getCvImage( )

const int * getCvImage()

getHeight( )

float getHeight()

Returns the height of the image in pixels.


getIntersectionROI( ... )

ofRectangle getIntersectionROI(const ofRectangle &rec1, const ofRectangle &rec2)

getPixels( )

ofPixels & getPixels()

Returns a raw pointer to the pixel data within the image.


getPixels( )

const ofPixels & getPixels()

getROI( )

ofRectangle getROI()

Returns the region of interest in an ofxCvImage.


getRoiPixels( )

ofPixels & getRoiPixels()

Returns a raw pointer to the pixel data within the Region of Interest in the ofxCvImage.


getRoiPixels( )

const ofPixels & getRoiPixels()

getTexture( )

ofTexture & getTexture()

getTexture( )

const ofTexture & getTexture()

getWidth( )

float getWidth()

Returns the width of the image in pixels.


invert( )

void invert()

Flip the pixel values of the image.

![Inverting an image] (../invert.png "Original on Left")


isUsingTexture( )

bool isUsingTexture()

matchingROI( ... )

bool matchingROI(const ofRectangle &rec1, const ofRectangle &rec2)

Returns whether the Region of Interests match position and dimension or not.


mirror( ... )

void mirror(bool bFlipVertically, bool bFlipHorizontally)

Flips the image horizontally and/or vertically.


ofxCvImage( )

ofxCvImage()

Constructor.


operator&=( ... )

void operator&=(ofxCvImage &mom)

Binary & (Logical AND http://en.wikipedia.org/wiki/Bitwise_operation) the pixel data of the right hand side image from the current image:

cvPuppy.allocate( 320, 240 );
cvPuppy = puppyImg.getPixels(); // copy pixels from a loaded image

andPuppy.allocate( 320, 240 );

andPuppy.set(255, 0, 0); // make the AND image red
andPuppy &= cvPuppy; // will & all the bits

puppy AND


operator*=( ... )

void operator*=(ofxCvImage &mom)

Multiplies the pixel data of the right hand side image from the current image:

first *= second; // both are ofxCvImage instances

operator+=( ... )

void operator+=(float value)

Adds the pixel data of the right hand side image from the current image:

first += second; // both are ofxCvImage instances

operator+=( ... )

void operator+=(ofxCvImage &mom)

Adds the pixel data of the right hand side image from the current image:

first += second; // both are ofxCvImage instances

operator-=( ... )

void operator-=(float value)

Subtracts the pixel data of the right hand side image from the current image:

first -= second; // both are ofxCvImage instances

operator-=( ... )

void operator-=(ofxCvImage &mom)

Subtracts the pixel data of the right hand side image from the current image:

first -= second; // both are ofxCvImage instances

operator=( ... )

void operator=(const ofxCvGrayscaleImage &mom)

Copy a ofxCvGrayscaleImage into the current ofxCvImage.


operator=( ... )

void operator=(const ofxCvColorImage &mom)

Copy the image data of an ofxCvColorImage into the ofxCvImage instance.


operator=( ... )

void operator=(const ofxCvFloatImage &mom)

Copy the image data ofxCvFloatImage into the ofxCvImage instance.


operator=( ... )

void operator=(const ofxCvShortImage &mom)

Copy the image data of a ofxCvShortImage into the ofxCvImage instance.


operator=( ... )

void operator=(const int *mom)

rangeMap( ... )

void rangeMap(int *img, float min1, float max1, float min2, float max2)

rangeMap( ... )

void rangeMap(int *mom, int *kid, float min1, float max1, float min2, float max2)

remap( ... )

void remap(int *mapX, int *mapY)

This uses a generic geometrical transformation to remap one image to another. This is particularly useful when doing camera calibration.


resetAnchor( )

void resetAnchor()

Reset the anchor point of the image, i.e. the center point for rotations,


resetImageROI( ... )

void resetImageROI(int *img)

resetROI( )

void resetROI()

Removes the region of interest from an ofxCvImage.


resize( ... )

void resize(int w, int h)

Resizes the image to the w.h passed in.


rotate( ... )

void rotate(float angle, float centerX, float centerY)

Rotates the image. This is different than the OpenGL rotate as it actually sets the pixel data, rather than just the posotion of the drawing.


scale( ... )

void scale(float scaleX, float sclaeY)

Scales the image to the scaleX, scaleY passed in. This is different than the OpenGL rotate as it actually sets the pixel data, rather than just the posotion of the drawing.


scaleIntoMe( ... )

void scaleIntoMe(ofxCvImage &mom, int interpolationMethod)

Scales the image passed in to be the size of the current image,


ofxCvImage first;
first.allocate(640, 480);
ofxCvImage second;
second.allocate(320, 240);

second.scaleIntoMe(first); // first is now 320,240


set( ... )

void set(float value)

Set all the pixels in the image to the float value passed in. This is useful for blanking or filling an image quickly. the values are 1.0 to 255.0.


setAnchorPercent( ... )

void setAnchorPercent(float xPct, float yPct)

Set the anchor point of the image, i.e. the center point for rotations, at the percentage positions passed in.


setAnchorPoint( ... )

void setAnchorPoint(float x, float y)

Set the anchor point of the image, i.e. the center point for rotations, at the x,y passed in.


setFromPixels( ... )

void setFromPixels(const unsigned char *_pixels, int w, int h)

Set all the pixels in a ofxCvImage from a pointer to an array of unsigned char values, using the w and h parameters to determine the dimensions of the image.


setFromPixels( ... )

void setFromPixels(const ofPixels &pixels)

Set all the pixels in a ofxCvImage from an ofPixels reference.


setImageROI( ... )

void setImageROI(int *img, const ofRectangle &rect)

setROI( ... )

void setROI(int x, int y, int w, int h)

Sets the region of interest on the image. Region of Interest is a rectangular area in an image, to segment object for further processing. Once the ROI is defined, OpenCV functions will operate on the ROI, reducing the number of pixels that the operation will examine.


setROI( ... )

void setROI(const ofRectangle &rect)

Sets the region of interest on the image. Region of Interest is a rectangular area in an image, to segment object for further processing. Once the ROI is defined, OpenCV functions will operate on the ROI, reducing the number of pixels that the operation will examine.


setRoiFromPixels( ... )

void setRoiFromPixels(const unsigned char *_pixels, int w, int h)

Set the Region Of Interest using a pointer to an unsigned char array and a w,h to define the area of the ROI


setRoiFromPixels( ... )

void setRoiFromPixels(const ofPixels &pixels)

Set the Region Of Interest using an ofPixels reference The w,h of the ofPixels will define the area of the ROI


setUseTexture( ... )

void setUseTexture(bool bUse)

Sets whether the image is using a texture or not. If the image is not using a texture then calls to getTextureReference() will return null and the image cannot be drawn. This is handy if you know that you won't be displaying the image to the screen.


swapTemp( )

void swapTemp()

transform( ... )

void transform(float angle, float centerX, float centerY, float scaleX, float scaleY, float moveX, float moveY)

Transforms the image with the angle, scaling, and transformation passed in. This is different than the OpenGL rotate as it actually sets the pixel data, rather than just the posotion of the drawing.


translate( ... )

void translate(float x, float y)

Moves the image by the x,y amount passed in. This is different than the OpenGL rotate as it actually sets the pixel data, rather than just the posotion of the drawing.


undistort( ... )

void undistort(float radialDistX, float radialDistY, float tangentDistX, float tangentDistY, float focalX, float focalY, float centerX, float centerY)

/**

  • undistort Usage Example:
  • undistort( 0, 1, 0, 0, 200, 200, cwidth/2, cheight/2 );
  • creates kind of an old TV monitor distortion. */

The function cvUnDistortOnce corrects camera lens distortion for the image. It requires that you have an estimate of the camera distortion from a call to cvCalibrateCamera() or other calibration method.


updateTexture( )

void updateTexture()

Updates the texture of the ofxCvImage if it contains one. This is handy after you've changed the image pixel data and want it to be uploaded to the texture on the graphics card.


warpIntoMe( ... )

void warpIntoMe(ofxCvImage &mom, const ofPoint [4] src=4, const ofPoint [4] dst=4)

This warps the image perspective into the ofxCvImage using two sets four points passed in:

ofPoint[4] src;
src[0] = ofPoint(0, 0);
src[1] = ofPoint(320, 0);
src[2] = ofPoint(320, 240);
src[3] = ofPoint(0, 240);

ofPoint[4] dst;
dst[0] = ofPoint(10, 0);
dst[1] = ofPoint(310, 0);
dst[2] = ofPoint(310, 230);
dst[3] = ofPoint(10, 230);

image.warpIntoMe(parent, src, dst);

![Warping] (../warpPerspective.png "Four corners for warping")


warpPerspective( ... )

void warpPerspective(const ofPoint &A, const ofPoint &B, const ofPoint &C, const ofPoint &D)

This warps the image perspective to the four points passed in:

![Warping] (../warpPerspective.png "Four corners for warping")


~ofxCvImage( )

~ofxCvImage()

Destructor.