Implements the Canny algorithm for edge detection.
| Parameters: |
|
|---|
The function finds the edges on the input image image and marks them in the output image edges using the Canny algorithm. The smallest value between threshold1 and threshold2 is used for edge linking, the largest value is used to find the initial segments of strong edges.
Calculates eigenvalues and eigenvectors of image blocks for corner detection.
| Parameters: |
|
|---|
For every pixel, the function cvCornerEigenValsAndVecs() considers a
neigborhood S(p). It calcualtes the covariation matrix of derivatives over the neigborhood as:

After that it finds eigenvectors and eigenvalues of the matrix and stores them into destination image in form
where
*are the eigenvalues of
; not sorted
*are the eigenvectors corresponding to 
*are the eigenvectors corresponding to 
Harris edge detector.
| Parameters: |
|
|---|
The function runs the Harris edge detector on the image. Similarly to CornerMinEigenVal and CornerEigenValsAndVecs, for each pixel it calculates a
gradient covariation matrix
over a
neighborhood. Then, it stores

to the destination image. Corners in the image can be found as the local maxima of the destination image.
Calculates the minimal eigenvalue of gradient matrices for corner detection.
| Parameters: |
|
|---|
The function is similar to CornerEigenValsAndVecs but it calculates and stores only the minimal eigen value of derivative covariation matrix for every pixel, i.e.
in terms of the previous function.
Extracts Speeded Up Robust Features from an image.
| Parameters: |
|
|---|
The function cvExtractSURF finds robust features in the image, as described in Bay06 . For each feature it returns its location, size, orientation and optionally the descriptor, basic or extended. The function can be used for object tracking and localization, image stitching etc. See the find_obj.cpp demo in OpenCV samples directory.
Refines the corner locations.
| Parameters: |
|
|---|
The function iterates to find the sub-pixel accurate location of corners, or radial saddle points, as shown in on the picture below.
Sub-pixel accurate corner locator is based on the observation that every vector from the center
to a point
located within a neighborhood of
is orthogonal to the image gradient at
subject to image and measurement noise. Consider the expression:

where
is the image gradient at the one of the points
in a neighborhood of
. The value of
is to be found such that
is minimized. A system of equations may be set up with
set to zero:

where the gradients are summed within a neighborhood (“search window”) of
. Calling the first gradient term
and the second gradient term
gives:

The algorithm sets the center of the neighborhood window at this new center
and then iterates until the center keeps within a set threshold.
Retrieves keypoints using the StarDetector algorithm.
| Parameters: |
|
|---|
The function GetStarKeypoints extracts keypoints that are local scale-space extremas. The scale-space is constructed by computing approximate values of laplacians with different sigma’s at each pixel. Instead of using pyramids, a popular approach to save computing time, all of the laplacians are computed at each pixel of the original high-resolution image. But each approximate laplacian value is computed in O(1) time regardless of the sigma, thanks to the use of integral images. The algorithm is based on the paper Agrawal08 , but instead of a square, hexagon or octagon it uses an 8-end star shape, hence the name, consisting of overlapping upright and tilted squares.
Each computed feature is represented by the following structure:
typedef struct CvStarKeypoint { CvPoint pt; // coordinates of the feature int size; // feature size, see CvStarDetectorParams::maxSize float response; // the approximated laplacian value at that point. } CvStarKeypoint; inline CvStarKeypoint cvStarKeypoint(CvPoint pt, int size, float response);
Below is the small usage sample:
#include "cv.h" #include "highgui.h" int main(int argc, char** argv) { const char* filename = argc > 1 ? argv[1] : "lena.jpg"; IplImage* img = cvLoadImage( filename, 0 ), *cimg; CvMemStorage* storage = cvCreateMemStorage(0); CvSeq* keypoints = 0; int i; if( !img ) return 0; cvNamedWindow( "image", 1 ); cvShowImage( "image", img ); cvNamedWindow( "features", 1 ); cimg = cvCreateImage( cvGetSize(img), 8, 3 ); cvCvtColor( img, cimg, CV_GRAY2BGR ); keypoints = cvGetStarKeypoints( img, storage, cvStarDetectorParams(45) ); for( i = 0; i < (keypoints ? keypoints->total : 0); i++ ) { CvStarKeypoint kpt = *(CvStarKeypoint*)cvGetSeqElem(keypoints, i); int r = kpt.size/2; cvCircle( cimg, kpt.pt, r, CV_RGB(0,255,0)); cvLine( cimg, cvPoint(kpt.pt.x + r, kpt.pt.y + r), cvPoint(kpt.pt.x - r, kpt.pt.y - r), CV_RGB(0,255,0)); cvLine( cimg, cvPoint(kpt.pt.x - r, kpt.pt.y + r), cvPoint(kpt.pt.x + r, kpt.pt.y - r), CV_RGB(0,255,0)); } cvShowImage( "features", cimg ); cvWaitKey(); }
Determines strong corners on an image.
| Parameters: |
|
|---|
The function finds the corners with big eigenvalues in the image. The function first calculates the minimal eigenvalue for every source image pixel using the CornerMinEigenVal function and stores them in eigImage. Then it performs non-maxima suppression (only the local maxima in
neighborhood are retained). The next step rejects the corners with the minimal eigenvalue less than
. Finally, the function ensures that the distance between any two corners is not smaller than minDistance. The weaker corners (with a smaller min eigenvalue) that are too close to the stronger corners are rejected.
Note that the if the function is called with different values A and B of the parameter qualityLevel, and A > bgroup({B}), the array of returned corners with qualityLevel=A will be the prefix of the output corners array with qualityLevel=B.
Finds lines in a binary image using a Hough transform.
| Parameters: |
|
|---|
The function implements a few variants of the Hough transform for line detection.
Example. Detecting lines with Hough transform.
/* This is a standalone program. Pass an image name as a first parameter of the program. Switch between standard and probabilistic Hough transform by changing "#if 1" to "#if 0" and back */ #include <cv.h> #include <highgui.h> #include <math.h> int main(int argc, char** argv) { IplImage* src; if( argc == 2 && (src=cvLoadImage(argv[1], 0))!= 0) { IplImage* dst = cvCreateImage( cvGetSize(src), 8, 1 ); IplImage* color_dst = cvCreateImage( cvGetSize(src), 8, 3 ); CvMemStorage* storage = cvCreateMemStorage(0); CvSeq* lines = 0; int i; cvCanny( src, dst, 50, 200, 3 ); cvCvtColor( dst, color_dst, CV_GRAY2BGR ); #if 1 lines = cvHoughLines2( dst, storage, CV_HOUGH_STANDARD, 1, CV_PI/180, 100, 0, 0 ); for( i = 0; i < MIN(lines->total,100); i++ ) { float* line = (float*)cvGetSeqElem(lines,i); float rho = line[0]; float theta = line[1]; CvPoint pt1, pt2; double a = cos(theta), b = sin(theta); double x0 = a*rho, y0 = b*rho; pt1.x = cvRound(x0 + 1000*(-b)); pt1.y = cvRound(y0 + 1000*(a)); pt2.x = cvRound(x0 - 1000*(-b)); pt2.y = cvRound(y0 - 1000*(a)); cvLine( color_dst, pt1, pt2, CV_RGB(255,0,0), 3, 8 ); } #else lines = cvHoughLines2( dst, storage, CV_HOUGH_PROBABILISTIC, 1, CV_PI/180, 80, 30, 10 ); for( i = 0; i < lines->total; i++ ) { CvPoint* line = (CvPoint*)cvGetSeqElem(lines,i); cvLine( color_dst, line[0], line[1], CV_RGB(255,0,0), 3, 8 ); } #endif cvNamedWindow( "Source", 1 ); cvShowImage( "Source", src ); cvNamedWindow( "Hough", 1 ); cvShowImage( "Hough", color_dst ); cvWaitKey(0); } }
This is the sample picture the function parameters have been tuned for:
And this is the output of the above program in the case of probabilistic Hough transform (if 0 case):
Calculates the feature map for corner detection.
| Parameters: |
|
|---|
The function calculates the function

where
denotes one of the first image derivatives and
denotes a second image derivative.
The corners can be found as local maximums of the function below:
// assume that the image is floating-point IplImage* corners = cvCloneImage(image); IplImage* dilated_corners = cvCloneImage(image); IplImage* corner_mask = cvCreateImage( cvGetSize(image), 8, 1 ); cvPreCornerDetect( image, corners, 3 ); cvDilate( corners, dilated_corners, 0, 1 ); cvSubS( corners, dilated_corners, corners ); cvCmpS( corners, 0, corner_mask, CV_CMP_GE ); cvReleaseImage( &corners ); cvReleaseImage( &dilated_corners );
Reads the raster line to the buffer.
| Parameters: |
|
|---|
The function implements a particular application of line iterators. The function reads all of the image points lying on the line between pt1 and pt2, including the end points, and stores them into the buffer.