惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

S
Securelist
V
V2EX
MongoDB | Blog
MongoDB | Blog
量子位
J
Java Code Geeks
GbyAI
GbyAI
Attack and Defense Labs
Attack and Defense Labs
Y
Y Combinator Blog
T
The Blog of Author Tim Ferriss
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
博客园 - 叶小钗
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Cloudbric
Cloudbric
Recorded Future
Recorded Future
月光博客
月光博客
Help Net Security
Help Net Security
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
N
Netflix TechBlog - Medium
M
MIT News - Artificial intelligence
N
News and Events Feed by Topic
阮一峰的网络日志
阮一峰的网络日志
The Register - Security
The Register - Security
Scott Helme
Scott Helme
Google DeepMind News
Google DeepMind News
W
WeLiveSecurity
G
Google Developers Blog
T
Troy Hunt's Blog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
I
InfoQ
S
SegmentFault 最新的问题
G
GRAHAM CLULEY
C
Check Point Blog
Project Zero
Project Zero
有赞技术团队
有赞技术团队
B
Blog RSS Feed
大猫的无限游戏
大猫的无限游戏
P
Privacy International News Feed
AI
AI
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
F
Full Disclosure
C
CXSECURITY Database RSS Feed - CXSecurity.com
H
Hackread – Cybersecurity News, Data Breaches, AI and More
H
Hacker News: Front Page
S
Secure Thoughts
罗磊的独立博客
T
Threat Research - Cisco Blogs
aimingoo的专栏
aimingoo的专栏
博客园_首页
宝玉的分享
宝玉的分享
C
Cybersecurity and Infrastructure Security Agency CISA

博客园 - 鹅要长大

【ubuntu基础】使用sshfs挂载远程主机目录 【c++编程基础】理解lambda表达式 【c++编程基础】字节对齐pack的理解 【c++编程基础】虚函数virtual的理解与使用 【linux基础知识】理解nohup 【linux基础】如何理解python train_dtld.py 2>&1 | tee my_error_log.txt 【工具使用】docker的使用 【基础算法】银行家舍入法 【ubuntu工具】ubuntu好用工具总结 【ubuntu基础工具使用】ubuntu中screen的安装与使用 【linux操作基础】多目录文件复制且同名不覆盖 【linux基础操作】windows系统生成的txt文件在ubuntu打开乱码 【opencv编程基础】fillpoly和polylines函数的理解 【c++编程基础】std::unique的理解 【编程基础】计算三个顶点之间的夹角 【计算几何算法】道格拉斯普克(Douglas-Peuker)算法 [c++]c++ 工程代码中的debug时条件编译隐去的代码会影响程序运行的性能和耗时吗 【CV基础】语义分割任务计算类别权重 【opencv基础】resize使用的问题 git stash的用法 gflags的使用 opencv 判断某个坐标点是否在多边形内cv::pointPolygonTest 用Python从零实现贝叶斯分类器 【CV数据集】智慧城市之CCPD车牌数据集
判断多边形的顶点内外角点以及对approxPolyDP函数的理解
鹅要长大 · 2024-08-31 · via 博客园 - 鹅要长大
#include <opencv2/opencv.hpp>  
#include <vector>  
  
using namespace cv;  
using namespace std;  
  
// 计算向量叉积  
int crossProduct(Point a, Point b, Point c) {  
    Point v1 = {b.x - a.x, b.y - a.y};  
    Point v2 = {c.x - b.x, c.y - b.y};  
    return v1.x * v2.y - v1.y * v2.x;  
}  
  
// 判断角点类型  
void detectCornerType(const vector<Point>& points) {  
    int n = points.size();  
    for (int i = 0; i < n; i++) {  
        int prev = (i > 0) ? i - 1 : n - 1;  
        int next = (i < n - 1) ? i + 1 : 0;  
          
        int cp = crossProduct(points[prev], points[i], points[next]);  
        if (cp > 0) {  
            cout << "内角点 at: " << points[i] << endl;  
        } else if (cp < 0) {  
            cout << "外角点 at: " << points[i] << endl;  
        } else {  
            cout << "直线点或平角点 at: " << points[i] << endl;  
        }  
    }  
}  
  
int main() {  
    // 加载图像  
    Mat img = imread("path_to_image");      
    // 转换为灰度图  
    Mat gray;  
    cvtColor(img, gray, COLOR_BGR2GRAY);        
    // 二值化  
    Mat binary;  
    threshold(gray, binary, 100, 255, THRESH_BINARY);        
    // 查找轮廓  
    vector<vector<Point>> contours;  
    findContours(binary, contours, RETR_EXTERNAL, CHAIN_APPROX_SIMPLE);        
    // 近似多边形  
    vector<Point> approx;  
    approxPolyDP(contours[0], approx, arcLength(contours[0], true) * 0.02, true);        
    // 判断角点类型  
    detectCornerType(approx);       
    return 0;  
}