Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize Convex Hull Detection by C++ OpenCV

2025-04-07 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces C++ OpenCV how to achieve convex hull detection, the article is very detailed, has a certain reference value, interested friends must read it!

Convex hull

Convex hull means that if the straight segment connecting any two points in set An is inside A, then set An is said to be convex. To put it simply, it is a polygonal type with no concave place. Convex hull (convex hull) can contain all the points in a point set. Convex hull detection is often used in object recognition, gesture recognition, boundary detection and other fields.

An outline can have countless shells that surround it, and the shell with the smallest surface area is the convex hull.

Related API

The function convexHull () is provided in OpenCV to detect the convex hull of the object outline and to analyze the convex hull defect of the shape.

Void convexHull (InputArray points, OutputArray hull, bool clockwise = false, bool returnPoints = true)

Points: input 2D point sets (usually outline point sets), these point sets are stored in the container vector or Mat, in the following source code, I am forced to convert to the Mat type.

Hull: convex hull point set output. The type is either an integer vector or a point set vector. if it is an integer vector, then only the index is stored, and the object of the index is the input two-dimensional point set (if you do not understand the meaning of this sentence, take a look at the source code given below).

Clockwise: the sign bit of the convex hull direction. If it's true, it's based on clockwise, if it's false, it's based on counterclockwise.

ReturnPoints: indicates the number of returned points. If the second parameter is vector, it is automatically ignored.

Code demonstration

Implementation steps

Conversion of image from RGB to grayscale

Conversion of grayscale image to binary image

Get candidate points by discovering contours

Convex hull API call

Drawing and display

Create a new project opencv-0024, configure properties (VS2017 configure OpenCV common properties), and then write # include and main methods in the source file

Processing code of convex hull

The following is the display effect

Let's try a few more images to see the effect.

The above is all the contents of the article "how to achieve Convex Hull Detection in C++ OpenCV". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

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.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report