OpenCV  4.5.2
Open Source Computer Vision
Image Moments

Table of Contents

Prev Tutorial: Creating Bounding rotated boxes and ellipses for contours
Next Tutorial: Point Polygon Test

Original author Ana Huamán
Compatibility OpenCV >= 3.0

Goal

In this tutorial you will learn how to:

Theory

Code

Explanation

Result

Here it is:

cv::String
std::string String
Definition: cvstd.hpp:150
cv::cvtColor
void cvtColor(InputArray src, OutputArray dst, int code, int dstCn=0)
Converts an image from one color space to another.
cv::samples::findFile
cv::String findFile(const cv::String &relative_path, bool required=true, bool silentMode=false)
Try to find requested data file.
cv::Mat::zeros
static MatExpr zeros(int rows, int cols, int type)
Returns a zero array of the specified size and type.
cv::Point2f
Point_< float > Point2f
Definition: types.hpp:192
cv::threshold
double threshold(InputArray src, OutputArray dst, double thresh, double maxval, int type)
Applies a fixed-level threshold to each array element.
cv::waitKey
int waitKey(int delay=0)
Waits for a pressed key.
cv::Canny
void Canny(InputArray image, OutputArray edges, double threshold1, double threshold2, int apertureSize=3, bool L2gradient=false)
Finds edges in an image using the Canny algorithm .
highgui.hpp
cv::namedWindow
void namedWindow(const String &winname, int flags=WINDOW_AUTOSIZE)
Creates a window.
cv::Scalar_< double >
cv::findContours
void findContours(InputArray image, OutputArrayOfArrays contours, OutputArray hierarchy, int mode, int method, Point offset=Point())
Finds contours in a binary image.
cv::Size
Size2i Size
Definition: types.hpp:347
cv::Canny
void Canny(InputArray dx, InputArray dy, OutputArray edges, double threshold1, double threshold2, bool L2gradient=false)
cv::imread
Mat imread(const String &filename, int flags=IMREAD_COLOR)
Loads an image from a file.
cv::Mat::empty
bool empty() const
Returns true if the array has no elements.
CV_8UC3
#define CV_8UC3
Definition: interface.h:90
cv::contourArea
double contourArea(InputArray contour, bool oriented=false)
Calculates a contour area.
cv::Mat::size
MatSize size
Definition: mat.hpp:2118
imgcodecs.hpp
cv::arcLength
double arcLength(InputArray curve, bool closed)
Calculates a contour perimeter or a curve length.
cv::dnn::print
static void print(const MatShape &shape, const String &name="")
Definition: shape_utils.hpp:198
cv::findContours
void findContours(InputArray image, OutputArrayOfArrays contours, int mode, int method, Point offset=Point())
cv::imshow
void imshow(const String &winname, InputArray mat)
Displays an image in the specified window.
cv::Scalar
Scalar_< double > Scalar
Definition: types.hpp:669
cv::RNG
Random Number Generator.
Definition: core.hpp:2782
cv::drawContours
void drawContours(InputOutputArray image, InputArrayOfArrays contours, int contourIdx, const Scalar &color, int thickness=1, int lineType=LINE_8, InputArray hierarchy=noArray(), int maxLevel=INT_MAX, Point offset=Point())
Draws contours outlines or filled contours.
cv::blur
void blur(InputArray src, OutputArray dst, Size ksize, Point anchor=Point(-1,-1), int borderType=BORDER_DEFAULT)
Blurs an image using the normalized box filter.
cv::Point
Point2i Point
Definition: types.hpp:194
cv::Mat
n-dimensional dense array class
Definition: mat.hpp:801
cv::imshow
void imshow(const String &winname, const ogl::Texture2D &tex)
Displays OpenGL 2D texture in the specified window.
cv::CommandLineParser
Designed for command line parsing.
Definition: utility.hpp:799
cv::COLOR_BGR2GRAY
@ COLOR_BGR2GRAY
convert between RGB/BGR and grayscale, color conversions
Definition: imgproc.hpp:551
cv::createTrackbar
int createTrackbar(const String &trackbarname, const String &winname, int *value, int count, TrackbarCallback onChange=0, void *userdata=0)
Creates a trackbar and attaches it to the specified window.
cv
"black box" representation of the file storage associated with a file on disk.
Definition: affine.hpp:51
imgproc.hpp
cv::moments
Moments moments(InputArray array, bool binaryImage=false)
Calculates all of the moments up to the third order of a polygon or rasterized shape.
cv::CHAIN_APPROX_SIMPLE
@ CHAIN_APPROX_SIMPLE
Definition: imgproc.hpp:442
cv::RETR_TREE
@ RETR_TREE
Definition: imgproc.hpp:430
cv::circle
void circle(InputOutputArray img, Point center, int radius, const Scalar &color, int thickness=1, int lineType=LINE_8, int shift=0)
Draws a circle.