opencv计算点集凸包

2023-10-13 03:30
文章标签 计算 opencv 点集 凸包

本文主要是介绍opencv计算点集凸包,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

点集求凸包的问题经常会遇到,https://www.geeksforgeeks.org/orientation-3-ordered-points/  给出了一种思路,有空了再仔细研究,本文总结了opencv中相关的方法并给出一个实例。

参考:OpenCV: Structural Analysis and Shape Descriptors

1、opencv接口

hull = cv.convexHull(points[, hull[, clockwise[, returnPoints]]])

参数说明:

  1. points:点集。需要注意的是,该参数输入的坐标系是向右为X,向上为Y,和迪卡尔坐标系是相同的,而opencv中的图像坐标系是向右为X,向下为Y,即图像的左上角坐标为(0,0)。
  2. clockwise:如果设置为True,输出的凸包是顺时针的,如果设置为False,输出的凸包是逆时针的。
  3. returnPoints:如果设置为True,返回凸包的点坐标,如果设置为False,输出凸包点在点集points中的序号。

2、示例

代码如下:

# encoding:utf-8import numpy as np
import cv2
import matplotlib.pyplot as pltaxis_list = [[3,1],[2,2],[3,3],[4,4],[2,4],[2,3],[1,2],[2,2],[2,1]]
axis_list = np.array(axis_list)hull = cv2.convexHull(axis_list,clockwise=True,returnPoints=True)
print(hull)hull = np.squeeze(hull)
plt.scatter(axis_list[:,0],axis_list[:,1])
plt.plot(hull[:,0],hull[:,1],"r")
plt.plot([hull[-1,0],hull[0,0]],[hull[-1,1],hull[0,1]],"r")
plt.show()

计算结果如下图所示,其中蓝色点是点集,红色线条是凸包轮廓。

这篇关于opencv计算点集凸包的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/200460

相关文章

使用opencv优化图片(画面变清晰)

文章目录 需求影响照片清晰度的因素 实现降噪测试代码 锐化空间锐化Unsharp Masking频率域锐化对比测试 对比度增强常用算法对比测试 需求 对图像进行优化,使其看起来更清晰,同时保持尺寸不变,通常涉及到图像处理技术如锐化、降噪、对比度增强等 影响照片清晰度的因素 影响照片清晰度的因素有很多,主要可以从以下几个方面来分析 1. 拍摄设备 相机传感器:相机传

poj 1113 凸包+简单几何计算

题意: 给N个平面上的点,现在要在离点外L米处建城墙,使得城墙把所有点都包含进去且城墙的长度最短。 解析: 韬哥出的某次训练赛上A出的第一道计算几何,算是大水题吧。 用convexhull算法把凸包求出来,然后加加减减就A了。 计算见下图: 好久没玩画图了啊好开心。 代码: #include <iostream>#include <cstdio>#inclu

uva 1342 欧拉定理(计算几何模板)

题意: 给几个点,把这几个点用直线连起来,求这些直线把平面分成了几个。 解析: 欧拉定理: 顶点数 + 面数 - 边数= 2。 代码: #include <iostream>#include <cstdio>#include <cstdlib>#include <algorithm>#include <cstring>#include <cmath>#inc

uva 11178 计算集合模板题

题意: 求三角形行三个角三等分点射线交出的内三角形坐标。 代码: #include <iostream>#include <cstdio>#include <cstdlib>#include <algorithm>#include <cstring>#include <cmath>#include <stack>#include <vector>#include <

XTU 1237 计算几何

题面: Magic Triangle Problem Description: Huangriq is a respectful acmer in ACM team of XTU because he brought the best place in regional contest in history of XTU. Huangriq works in a big compa

poj 2187 凸包or旋转qia壳法

题意: 给n(50000)个点,求这些点与点之间距离最大的距离。 解析: 先求凸包然后暴力。 或者旋转卡壳大法。 代码: #include <iostream>#include <cstdio>#include <cstdlib>#include <algorithm>#include <cstring>#include <cmath>#include <s

Codeforces Beta Round #47 C凸包 (最终写法)

题意慢慢看。 typedef long long LL ;int cmp(double x){if(fabs(x) < 1e-8) return 0 ;return x > 0 ? 1 : -1 ;}struct point{double x , y ;point(){}point(double _x , double _y):x(_x) , y(_y){}point op

HDU 1392 HDU 1348 凸包

求凸包的周长,  注意n=1 , 2时特殊情况 int cmp(double x){if(fabs(x) < 1e-8) return 0 ;if(x > 0) return 1 ;return -1 ;}struct point{double x , y ;point(){}point(double _x , double _y):x(_x) , y(_y){}frien

opencv 滚动条

参数介绍:createTrackbar( trackbarname , "hello" , &alpha_slider ,alpha_max ,  on_trackbar )  ;在标签中显示的文字(提示滑动条的用途) TrackbarName创建的滑动条要放置窗体的名字 “hello”滑动条的取值范围从 0 到 alpha_max (最小值只能为 zero).滑动后的值存放在

android-opencv-jni

//------------------start opencv--------------------@Override public void onResume(){ super.onResume(); //通过OpenCV引擎服务加载并初始化OpenCV类库,所谓OpenCV引擎服务即是 //OpenCV_2.4.3.2_Manager_2.4_*.apk程序包,存