In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces how C++ to achieve the moment of OpenCV images, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.
Overview
A core problem of image recognition is image feature extraction. Simple description is to describe the whole image with a set of simple data (data description quantity). The simpler the data, the better. Good features are not disturbed by light, noise and geometric deformation. with the development of image recognition technology, new image features are constantly proposed, and image moment invariant is one of them.
The moments calculated from the image usually describe different kinds of geometric features of the image, such as size, grayscale, direction, shape and so on. image moments are widely used in pattern recognition, target classification, target recognition and anti-counterfeiting estimation, image coding and reconstruction and so on.
Moments in OpenCV mainly include the following: spatial moments, central moments and central normalized moments.
Related API
Cv::moments (InputArray array, bool binaryImage = false)
Array: input array, which can be a raster image (single-channel, 8-bit, or floating-point two-dimensional array), or a two-dimensional array (1 X N or N X 1), with a two-dimensional array type of Point or Point2f
BinaryImage: the default value is false. If it is true, all non-zero pixels will be treated as a value of 1, which means that the image is binarized, and the threshold is 1. This parameter is valid only for images.
ContourArea ()
This function uses Green formula to calculate the contour area and returns the area and the number of non-zero pixels. If you draw the outline using drawContours or fillPoly, it may make a difference.
Double cv::contourArea (InputArray contour, bool oriented = false)
Contour: is a vector, two-dimensional point, and can be of type vector or Mat
Oriented: there is a default value of false for region identifiers, and if true, this function returns a signed area, positive or negative depending on the direction of the outline (clockwise or counterclockwise). According to this property, the location of the profile can be determined according to the symbol of the area. If the default value is false, the area is returned as an absolute value.
ArcLength ()
Used to calculate the perimeter of a closed contour or the length of a curve
Double cv::arcLength (InputArray curve, bool closed)
Curve: enter a set of 2D points, which can be of type vector or Mat
Closed: the flag bit of whether the curve is closed. If true is closed, it will not be closed.
Code demonstration
Create a new project opencv-0026, configure properties (VS2017 configure OpenCV common properties), and then write # include and main methods in the source file
Core code
Implementation steps:
Change to grayscale image
Gaussian blur
Edge detection
Contour extraction
Calculate the image moment
Calculate the centroid of an image
Draw contours and centroids
Display image
Running effect
The area and perimeter of each outline are shown in the command line, and the centroid of each outline is also shown in the outline of the drawing on the right.
Thank you for reading this article carefully. I hope the article "how to achieve the moment of OpenCV Image on C++" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support and follow the industry information channel. More related knowledge is waiting for you to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.