Darwin  1.10(beta)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Classes | Enumerations | Functions | Variables
drwnOpenCVUtils.h File Reference

Utilities for working with OpenCV. More...

Go to the source code of this file.

Classes

class  drwnMouseState
 Mouse state and mouse callback for populating the mouse state. Used by the drwnWaitMouse function. More...
 

Enumerations

enum  drwnColorMap {
  DRWN_COLORMAP_RAINBOW, DRWN_COLORMAP_HOT, DRWN_COLORMAP_COOL, DRWN_COLORMAP_REDGREEN,
  DRWN_COLORMAP_ANU
}
 
enum  drwnFillType { DRWN_FILL_SOLID, DRWN_FILL_DIAG, DRWN_FILL_CROSSHATCH }
 

Functions

string toString (const cv::Mat &m)
 
string toString (const vector< cv::Mat > &vm)
 
string toString (const cv::Rect &r)
 
string toString (const cv::Point &pt)
 
string toString (const cv::Size &sz)
 
string toString (const cv::Scalar &slr)
 
bool operator== (const CvRect &r, const CvRect &s)
 equality operator for CvRect objects
 
bool operator< (const CvSize &r, const CvSize &s)
 inequality operator for CvSize objects (allows partial sorting)
 
bool operator< (const CvPoint &p, const CvPoint &q)
 inequality operator for CvPoint objects (allows partial sorting)
 
int drwnCmpCount (const cv::Mat &s, const cv::Mat &t, int cmpOp=CV_CMP_EQ)
 count number of entries matching comparison
 
int drwnShowDebuggingImage (const cv::Mat &img, const std::string &name, bool bWait)
 show an image (scale if not CV_8U) and wait (returns result from cv::waitKey)
 
int drwnShowDebuggingImage (const vector< cv::Mat > &views, const std::string &name, bool bWait, int rows=-1)
 show an array of images and wait (returns result from cv::waitKey)
 
cv::Rect drwnFitBoundingBox (const vector< cv::Rect > &rects)
 finds the smallest bounding box around these rectangles
 
cv::Rect drwnFitBoundingBox (const vector< cv::Point > &points)
 finds the smallest bounding box around these points
 
cv::Rect drwnFitBoundingBox (cv::Rect r, double aspectRatio)
 finds the smallest bounding box around these rectangles with given aspect ratio (w/h)
 
double area (const cv::Rect &r)
 area defined by the rectangle
 
double aspect (const cv::Rect &r)
 aspect ratio defined by the rectangle
 
double areaOverlap (const cv::Rect &r, const cv::Rect &s)
 area of the intersection between two rectangles
 
double areaUnion (const cv::Rect &r, const cv::Rect &s)
 area of the union between two rectangles
 
cv::Mat drwnGreyImage (const cv::Mat &src)
 convert image to greyscale (32-bit floating point)
 
cv::Mat drwnColorImage (const cv::Mat &src)
 convert image to color (8-bit)
 
cv::Mat drwnSoftEdgeMap (const cv::Mat &src, bool bNormalize=false)
 compute a soft edge map for an image (32-bit floating point)
 
void drwnGreyImageInplace (cv::Mat &img)
 convert an image to 32-bit greyscale in place
 
void drwnColorImageInplace (cv::Mat &img)
 convert an image to color in place
 
cv::Mat drwnPixelwiseMean (const vector< cv::Mat > &imgStack)
 Compute the pixelwise average of a stack of images. All images must be of the same size and type.
 
cv::Mat drwnPixelwiseMedian (const vector< cv::Mat > &imgStack)
 Compute the pixelwise median of a stack of images. All images must be of the same size and of type CV_8U. The images must also be continuous.
 
cv::Mat drwnPadImage (const cv::Mat &src, int margin)
 pad an image and copy the boundary
 
cv::Mat drwnPadImage (const cv::Mat &src, const cv::Rect &page)
 pad an image and copy the boundary, top-left reference is (0, 0) so page x- and y-coordinates must be non-positive
 
cv::Mat drwnTranslateMatrix (const cv::Mat &matrix, const cv::Point &origin, double fillValue=0.0)
 translate an array
 
cv::Mat drwnRotateImage (const cv::Mat &img, float theta)
 rotate an image clockwise by theta
 
void drwnScaleToRange (cv::Mat &m, double minValue=0.0, double maxValue=1.0)
 scale all entries in the image/matrix to the given range
 
void drwnResizeInPlace (cv::Mat &m, const cv::Size &size, int interpolation=CV_INTER_LINEAR)
 resize an image in place
 
void drwnResizeInPlace (cv::Mat &m, int rows, int cols, int interpolation=CV_INTER_LINEAR)
 resize a matrix in place
 
void drwnCropInPlace (cv::Mat &image, cv::Rect roi)
 crop an image or matrix in place
 
bool drwnValidRect (const cv::Rect &r, int width, int height)
 returns true if the rectangle has non-zero size and fits within the given image dimensions
 
bool drwnValidRect (const cv::Rect &r, const cv::Mat &img)
 returns true if the rectangle has non-zero size and fits within the given image
 
void drwnTruncateRect (cv::Rect &r, int width, int height)
 truncates a rectangle to fit inside [0, 0, width - 1, height - 1]
 
void drwnTruncateRect (cv::Rect &r, const cv::Mat &img)
 truncates a rectangle to fit inside the image
 
cv::Mat drwnCombineImages (const vector< cv::Mat > &images, int rows=-1, int cols=-1, unsigned margin=0, const cv::Scalar &colour=cv::Scalar(0))
 Assemble images into one big image. All images must be of the same format and rows * cols must be smaller than images.size(). If negative then will choose a square (rows = cols = ceil(sqrt(images.size()))). A border can be added around each image of given margin and colour.
 
cv::Mat drwnCreateHeatMap (const cv::Mat &m, drwnColorMap cm=DRWN_COLORMAP_RAINBOW)
 Convert a floating point matrix with entries in range [0, 1] to color image heatmap in either rainbow, hot or cool specturms. Integer matrices are first rescaled. More...
 
cv::Mat drwnCreateHeatMap (const cv::Mat &m, cv::Scalar colourA, cv::Scalar colourB)
 Convert a floating point matrix with entries in range [0, 1] to color image heatmap that interpolates between the given two colours.
 
cv::Mat drwnCreateHeatMap (const cv::Mat &m, const vector< cv::Scalar > &colours)
 Convert a floating point matrix with entries in range [0, 1] to color image heatmap that interpolates between the given colour table.
 
vector< cv::Scalar > drwnCreateColorTable (unsigned n, drwnColorMap cm=DRWN_COLORMAP_RAINBOW)
 Creates a color table by uniformly sampling a colormap.
 
void drwnDrawBoundingBox (cv::Mat &canvas, const cv::Rect &roi, cv::Scalar fgcolor, cv::Scalar bgcolor=CV_RGB(255, 255, 255), int lineWidth=2)
 draws a pretty bounding box
 
void drwnDrawPolygon (cv::Mat &canvas, const vector< cv::Point > &poly, cv::Scalar fgcolor, cv::Scalar bgcolor=CV_RGB(255, 255, 255), int lineWidth=2, bool bClose=true)
 draws a pretty polygon
 
void drwnDrawFullLinePlot (cv::Mat &canvas, const vector< double > &points, const cv::Scalar &lineColour, unsigned lineWidth=2, const cv::Scalar &baseShading=CV_RGB(0, 0, 0), double baseAlpha=0.0)
 draws a line across the image, optionally filling below the line
 
void drwnDrawTarget (cv::Mat &canvas, const cv::Point &center, cv::Scalar color=CV_RGB(255, 0, 0), int size=5, int lineWidth=1)
 draws a target symbol (circle and cross-hairs)
 
void drwnOnMouse (int event, int x, int y, int flags, void *ptr)
 Mouse callback function (populates MouseState data members passed as a pointer to void).
 
vector< cv::Point > drwnWaitMouse (const string &windowName, const cv::Mat &img, int numPoints=DRWN_INT_MAX)
 Waits for up to numPoints mouse clicks (or key press) and returns the location of the points. The clicked points are indicated on the given image. The window be destroyed on return unless already open. The function is similar to Matlab's ginput() function.
 
cv::Rect drwnInputBoundingBox (const string &windowName, const cv::Mat &img)
 Waits for the user to input a bounding box by clicking two points on a canvas.
 
cv::Mat drwnInputScribble (const string &windowName, const cv::Mat &img, const cv::Scalar &colour=CV_RGB(255, 0, 0), int width=5)
 Allows a user to scribble on a canvas. Exits when they press a key.
 
double drwnComparePatches (const cv::Mat &patchA, const cv::Mat &patchB, int method=CV_TM_SQDIFF)
 Compute distance between two image patches. method can be one of CV_TM_SQDIFF, CV_TM_SQDIFF_NORMED, CV_TM_CCORR, CV_TM_CCORR_NORMED, CV_TM_CCOEFF, or CV_TM_CCOEFF_NORMED.
 
void drwnOverlayImages (cv::Mat &canvas, const cv::Mat &overlay, double alpha=0.5)
 overlays an image on the (same size) canvas
 
void drwnOverlayMask (cv::Mat &canvas, const cv::Mat &mask, const cv::Scalar &color, double alpha=0.5)
 overlays a soft mask (in range [0, 1]) on the (same size) canvas
 
void drwnShadeRectangle (cv::Mat &canvas, cv::Rect roi, const cv::Scalar &color, double alpha=0.5, drwnFillType fill=DRWN_FILL_SOLID, int thickness=1)
 draws a shaded rectangle on the canvas
 
void drwnShadeRegion (cv::Mat &canvas, const cv::Mat &mask, const cv::Scalar &color, double alpha=0.5, drwnFillType fill=DRWN_FILL_SOLID, int thickness=1)
 draws a shaded region on the canvas
 
void drwnMaskRegion (cv::Mat &canvas, const cv::Mat &mask)
 applies a soft mask (in range [0, 1]) to a region on the canvas
 
void drwnDrawRegionBoundaries (cv::Mat &canvas, const cv::Mat &mask, const cv::Scalar &color, int thickness=1)
 marks the boundary between regions
 
void drwnDrawRegionBoundary (cv::Mat &canvas, const cv::Mat &mask, int idRegionA, int idRegionB, const cv::Scalar &color, int thickness=1)
 marks the boundary between two specific regions
 
void drwnAverageRegions (cv::Mat &img, const cv::Mat &seg)
 Fills each region with the average of the colour within the region. img can have an arbitrary number of channels. seg must be the same size as the image and of type CV_32SC1.
 

Variables

unsigned drwnOpenCVUtils::SHOW_IMAGE_MAX_HEIGHT = DRWN_INT_MAX
 maximum image height for drwnShowDebuggingImage
 
unsigned drwnOpenCVUtils::SHOW_IMAGE_MAX_WIDTH = DRWN_INT_MAX
 maximum image width for drwnShowDebuggingImage
 

Detailed Description

Utilities for working with OpenCV.

The testDarwinVision application demonstrates how to use many of these functions.

Enumeration Type Documentation

Enumerator
DRWN_COLORMAP_RAINBOW 

ranges from blue to red through green and yellow

DRWN_COLORMAP_HOT 

ranges from red to yellow

DRWN_COLORMAP_COOL 

ranges from cyan to pink

DRWN_COLORMAP_REDGREEN 

ranges from green to red

DRWN_COLORMAP_ANU 

ranges over ANU corporate colours

Enumerator
DRWN_FILL_SOLID 

fill with solid color

DRWN_FILL_DIAG 

fill with diagonal stripes

DRWN_FILL_CROSSHATCH 

fill with crosshatching

Function Documentation

cv::Mat drwnCreateHeatMap ( const cv::Mat &  m,
drwnColorMap  cm 
)

Convert a floating point matrix with entries in range [0, 1] to color image heatmap in either rainbow, hot or cool specturms. Integer matrices are first rescaled.

Todo:
refactor to use drwnCreateHeatMap(m, vector<CvScalar>) variant