[−][src]Module opencv::imgproc
Image Processing
This module includes image-processing functions.
Image Filtering
Functions and classes described in this section are used to perform various linear or non-linear filtering operations on 2D images (represented as Mat's). It means that for each pixel location in the source image (normally, rectangular), its neighborhood is considered and used to compute the response. In case of a linear filter, it is a weighted sum of pixel values. In case of morphological operations, it is the minimum or maximum values, and so on. The computed response is stored in the destination image at the same location . It means that the output image will be of the same size as the input image. Normally, the functions support multi-channel arrays, in which case every channel is processed independently. Therefore, the output image will also have the same number of channels as the input one.
Another common feature of the functions and classes described in this section is that, unlike simple arithmetic functions, they need to extrapolate values of some non-existing pixels. For example, if you want to smooth an image using a Gaussian filter, then, when processing the left-most pixels in each row, you need pixels to the left of them, that is, outside of the image. You can let these pixels be the same as the left-most image pixels ("replicated border" extrapolation method), or assume that all the non-existing pixels are zeros ("constant border" extrapolation method), and so on. OpenCV enables you to specify the extrapolation method. For details, see #BorderTypes
@anchor filter_depths
Depth combinations
Input depth (src.depth()) | Output depth (ddepth) |
---|---|
CV_8U | -1/CV_16S/CV_32F/CV_64F |
CV_16U/CV_16S | -1/CV_32F/CV_64F |
CV_32F | -1/CV_32F/CV_64F |
CV_64F | -1/CV_64F |
Note: when ddepth=-1, the output image will have the same depth as the source.
Geometric Image Transformations
The functions in this section perform various geometrical transformations of 2D images. They do not change the image content but deform the pixel grid and map this deformed grid to the destination image. In fact, to avoid sampling artifacts, the mapping is done in the reverse order, from destination to the source. That is, for each pixel of the destination image, the functions compute coordinates of the corresponding "donor" pixel in the source image and copy the pixel value:
In case when you specify the forward mapping , the OpenCV functions first compute the corresponding inverse mapping and then use the above formula.
The actual implementations of the geometrical transformations, from the most generic remap and to the simplest and the fastest resize, need to solve two main problems with the above formula:
-
Extrapolation of non-existing pixels. Similarly to the filtering functions described in the previous section, for some , either one of , or , or both of them may fall outside of the image. In this case, an extrapolation method needs to be used. OpenCV provides the same selection of extrapolation methods as in the filtering functions. In addition, it provides the method #BORDER_TRANSPARENT. This means that the corresponding pixels in the destination image will not be modified at all.
-
Interpolation of pixel values. Usually and are floating-point numbers. This means that can be either an affine or perspective transformation, or radial lens distortion correction, and so on. So, a pixel value at fractional coordinates needs to be retrieved. In the simplest case, the coordinates can be just rounded to the nearest integer coordinates and the corresponding pixel can be used. This is called a nearest-neighbor interpolation. However, a better result can be achieved by using more sophisticated interpolation methods , where a polynomial function is fit into some neighborhood of the computed pixel , and then the value of the polynomial at is taken as the interpolated pixel value. In OpenCV, you can choose between several interpolation methods. See resize for details.
Note: The geometrical transformations do not work with CV_8S
or CV_32S
images.
Miscellaneous Image Transformations
Drawing Functions
Drawing functions work with matrices/images of arbitrary depth. The boundaries of the shapes can be rendered with antialiasing (implemented only for 8-bit images for now). All the functions include the parameter color that uses an RGB value (that may be constructed with the Scalar constructor ) for color images and brightness for grayscale images. For color images, the channel ordering is normally Blue, Green, Red. This is what imshow, imread, and imwrite expect. So, if you form a color using the Scalar constructor, it should look like:
If you are using your own image rendering and I/O functions, you can use any channel ordering. The drawing functions process each channel independently and do not depend on the channel order or even on the used color space. The whole image can be converted from BGR to RGB or to a different color space using cvtColor .
If a drawn figure is partially or completely outside the image, the drawing functions clip it. Also, many drawing functions can handle pixel coordinates specified with sub-pixel accuracy. This means that the coordinates can be passed as fixed-point numbers encoded as integers. The number of fractional bits is specified by the shift parameter and the real point coordinates are calculated as . This feature is especially effective when rendering antialiased shapes.
Note: The functions do not support alpha-transparency when the target image is 4-channel. In this case, the color[3] is simply copied to the repainted pixels. Thus, if you want to paint semi-transparent shapes, you can paint them in a separate buffer and then blend it with the main image.
Color Space Conversions
ColorMaps in OpenCV
The human perception isn't built for observing fine changes in grayscale images. Human eyes are more sensitive to observing changes between colors, so you often need to recolor your grayscale images to get a clue about them. OpenCV now comes with various colormaps to enhance the visualization in your computer vision application.
In OpenCV you only need applyColorMap to apply a colormap on a given image. The following sample code reads the path to an image from command line, applies a Jet colormap on it and shows the result:
@include snippets/imgproc_applyColorMap.cpp
@see #ColormapTypes
Planar Subdivision
The Subdiv2D class described in this section is used to perform various planar subdivision on a set of 2D points (represented as vector of Point2f). OpenCV subdivides a plane into triangles using the Delaunay's algorithm, which corresponds to the dual graph of the Voronoi diagram. In the figure below, the Delaunay's triangulation is marked with black lines and the Voronoi diagram with red lines.
The subdivisions can be used for the 3D piece-wise transformation of a plane, morphing, fast location of points on the plane, building special graphs (such as NNG,RNG), and so forth.
Histograms
Structural Analysis and Shape Descriptors
Motion Analysis and Object Tracking
Feature Detection
Object Detection
C API
Hardware Acceleration Layer
Functions
Interface
Structs
LineIterator | Line iterator |
Subdiv2D |
Enums
InterpolationFlags | interpolation algorithm |
UndistortTypes | cv::undistort mode |
Constants
Traits
CLAHE | Base class for Contrast Limited Adaptive Histogram Equalization. |
GeneralizedHough | finds arbitrary template in the grayscale image using Generalized Hough Transform |
GeneralizedHoughBallard | finds arbitrary template in the grayscale image using Generalized Hough Transform |
GeneralizedHoughGuil | finds arbitrary template in the grayscale image using Generalized Hough Transform |
LineSegmentDetector | Line segment detector class |
Functions
accumulate | Adds an image to the accumulator image. |
accumulate_product | Adds the per-element product of two input images to the accumulator image. |
accumulate_square | Adds the square of a source image to the accumulator image. |
accumulate_weighted | Updates a running average. |
adaptive_threshold | Applies an adaptive threshold to an array. |
apply_color_map | Applies a GNU Octave/MATLAB equivalent colormap on a given image. |
apply_color_map_user | Applies a user colormap on a given image. |
approx_poly_dp | Approximates a polygonal curve(s) with the specified precision. |
arc_length | Calculates a contour perimeter or a curve length. |
arrowed_line | Draws a arrow segment pointing from the first point to the second one. |
bilateral_filter | Applies the bilateral filter to an image. |
blend_linear | Performs linear blending of two images: block formula |
blur | Blurs an image using the normalized box filter. |
bounding_rect | Calculates the up-right bounding rectangle of a point set or non-zero pixels of gray-scale image. |
box_filter | Blurs an image using the box filter. |
box_points | Finds the four vertices of a rotated rect. Useful to draw the rotated rectangle. |
build_pyramid | Constructs the Gaussian pyramid for an image. |
calc_back_project | Calculates the back projection of a histogram. |
calc_hist | Calculates a histogram of a set of arrays. |
canny | Finds edges in an image using the Canny algorithm Canny86 . |
canny_derivative | \overload |
circle | Draws a circle. |
clip_line | Clips the line against the image rectangle. |
clip_line_size | Clips the line against the image rectangle. |
clip_line_size_i64 | Clips the line against the image rectangle. |
compare_hist | Compares two histograms. |
connected_components | computes the connected components labeled image of boolean image |
connected_components_algo | computes the connected components labeled image of boolean image |
connected_components_with_stats | computes the connected components labeled image of boolean image and also produces a statistics output for each label |
connected_components_with_stats_algo | computes the connected components labeled image of boolean image and also produces a statistics output for each label |
contour_area | Calculates a contour area. |
convert_maps | Converts image transformation maps from one representation to another. |
convex_hull | Finds the convex hull of a point set. |
convexity_defects | Finds the convexity defects of a contour. |
corner_eigen_vals_and_vecs | Calculates eigenvalues and eigenvectors of image blocks for corner detection. |
corner_harris | Harris corner detector. |
corner_min_eigen_val | Calculates the minimal eigenvalue of gradient matrices for corner detection. |
corner_sub_pix | Refines the corner locations. |
create_clahe | Creates a smart pointer to a cv::CLAHE class and initializes it. |
create_generalized_hough_ballard | Creates a smart pointer to a cv::GeneralizedHoughBallard class and initializes it. |
create_generalized_hough_guil | Creates a smart pointer to a cv::GeneralizedHoughGuil class and initializes it. |
create_hanning_window | This function computes a Hanning window coefficients in two dimensions. |
create_line_segment_detector | Creates a smart pointer to a LineSegmentDetector object and initializes it. |
cvt_color | Converts an image from one color space to another. |
cvt_color_two_plane | Converts an image from one color space to another where the source image is stored in two planes. |
demosaicing | main function for all demosaicing processes |
dilate | Dilates an image by using a specific structuring element. |
distance_transform | Calculates the distance to the closest zero pixel for each pixel of the source image. |
distance_transform_labels | Calculates the distance to the closest zero pixel for each pixel of the source image. |
draw_contours | Draws contours outlines or filled contours. |
draw_marker | Draws a marker on a predefined position in an image. |
ellipse | Draws a simple or thick elliptic arc or fills an ellipse sector. |
ellipse_2_poly | Approximates an elliptic arc with a polyline. |
ellipse_2_poly_f64 | Approximates an elliptic arc with a polyline. |
ellipse_new_rotated_rect | Draws a simple or thick elliptic arc or fills an ellipse sector. |
emd | Computes the "minimal work" distance between two weighted point configurations. |
equalize_hist | Equalizes the histogram of a grayscale image. |
erode | Erodes an image by using a specific structuring element. |
fill_convex_poly | Fills a convex polygon. |
fill_poly | Fills the area bounded by one or more polygons. |
filter_2d | Convolves an image with the kernel. |
find_contours | Finds contours in a binary image. |
find_contours_with_hierarchy | Finds contours in a binary image. |
fit_ellipse | Fits an ellipse around a set of 2D points. |
fit_ellipse_ams | Fits an ellipse around a set of 2D points. |
fit_ellipse_direct | Fits an ellipse around a set of 2D points. |
fit_line | Fits a line to a 2D or 3D point set. |
flood_fill | Fills a connected component with the given color. |
flood_fill_mask | Fills a connected component with the given color. |
gaussian_blur | Blurs an image using a Gaussian filter. |
get_affine_transform | |
get_affine_transform_slice | Calculates an affine transform from three pairs of the corresponding points. |
get_default_new_camera_matrix | Returns the default new camera matrix. |
get_deriv_kernels | Returns filter coefficients for computing spatial image derivatives. |
get_font_scale_from_height | Calculates the font-specific size to use to achieve a given height in pixels. |
get_gabor_kernel | Returns Gabor filter coefficients. |
get_gaussian_kernel | Returns Gaussian filter coefficients. |
get_perspective_transform | Calculates a perspective transform from four pairs of the corresponding points. |
get_perspective_transform_slice | returns 3x3 perspective transformation for the corresponding 4 point pairs. |
get_rect_sub_pix | Retrieves a pixel rectangle from an image with sub-pixel accuracy. |
get_rotation_matrix_2d | Calculates an affine matrix of 2D rotation. |
get_structuring_element | Returns a structuring element of the specified size and shape for morphological operations. |
get_text_size | Calculates the width and height of a text string. |
good_features_to_track | Determines strong corners on an image. |
good_features_to_track_with_gradient | C++ default parameters |
grab_cut | Runs the GrabCut algorithm. |
hough_circles | Finds circles in a grayscale image using the Hough transform. |
hough_lines | Finds lines in a binary image using the standard Hough transform. |
hough_lines_p | Finds line segments in a binary image using the probabilistic Hough transform. |
hough_lines_point_set | Finds lines in a set of points using the standard Hough transform. |
init_undistort_rectify_map | Computes the undistortion and rectification transformation map. |
init_wide_angle_proj_map_with_type_i32 | initializes maps for #remap for wide-angle |
integral | Calculates the integral of an image. |
integral_sq_depth | Calculates the integral of an image. |
integral_titled_sq | Calculates the integral of an image. |
intersect_convex_convex | finds intersection of two convex polygons |
invert_affine_transform | Inverts an affine transformation. |
is_contour_convex | Tests a contour convexity. |
laplacian | Calculates the Laplacian of an image. |
line | Draws a line segment connecting two points. |
linear_polar | Deprecated Remaps an image to polar coordinates space. |
log_polar | Deprecated Remaps an image to semilog-polar coordinates space. |
match_shapes | Compares two shapes. |
match_template | Compares a template against overlapped image regions. |
median_blur | Blurs an image using the median filter. |
min_area_rect | Finds a rotated rectangle of the minimum area enclosing the input 2D point set. |
min_enclosing_circle | Finds a circle of the minimum area enclosing a 2D point set. |
min_enclosing_triangle | Finds a triangle of minimum area enclosing a 2D point set and returns its area. |
morphology_default_border_value | returns "magic" border value for erosion and dilation. It is automatically transformed to Scalar::all(-DBL_MAX) for dilation. |
morphology_ex | Performs advanced morphological transformations. |
phase_correlate | The function is used to detect translational shifts that occur between two images. |
point_polygon_test | Performs a point-in-contour test. |
polylines | Draws several polygonal curves. |
pre_corner_detect | Calculates a feature map for corner detection. |
put_text | Draws a text string. |
pyr_down | Blurs an image and downsamples it. |
pyr_mean_shift_filtering | Performs initial step of meanshift segmentation of an image. |
pyr_up | Upsamples an image and then blurs it. |
rectangle | Draws a simple, thick, or filled up-right rectangle. |
rectangle_points | Draws a simple, thick, or filled up-right rectangle. |
remap | Applies a generic geometrical transformation to an image. |
resize | Resizes an image. |
rotated_rectangle_intersection | Finds out if there is any intersection between two rotated rectangles. |
scharr | Calculates the first x- or y- image derivative using Scharr operator. |
sep_filter_2d | Applies a separable linear filter to an image. |
sobel | Calculates the first, second, third, or mixed image derivatives using an extended Sobel operator. |
spatial_gradient | Calculates the first order image derivative in both x and y using a Sobel operator |
sqr_box_filter | Calculates the normalized sum of squares of the pixel values overlapping the filter. |
threshold | Applies a fixed-level threshold to each array element. |
undistort | Transforms an image to compensate for lens distortion. |
undistort_points | Computes the ideal point coordinates from the observed point coordinates. |
undistort_points_with_criteria | Computes the ideal point coordinates from the observed point coordinates. |
warp_affine | Applies an affine transformation to an image. |
warp_perspective | Applies a perspective transformation to an image. |
warp_polar | \brief Remaps an image to polar or semilog-polar coordinates space |
watershed | Performs a marker-based image segmentation using the watershed algorithm. |
wrapper_emd | C++ default parameters |