确定四边形的四个顶点

通过在四边形内部选取一点并分割为四块,找到每块中距离该点最远的边缘作为角点。针对钝角点可能出现的误差,通过重新计算对应块的最小余弦值得到更精确的角点位置。提供的简单代码未做优化,主要用于思路展示。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

确定四边形顶点的方法为:在四边形的内部任意取一个点,将四边形分割成四块,再在对应的块中求出边缘距离该点的最大距离,记为一个角点。缺陷:对于部分钝角的角点,会出现误差,导致钝角的角点不准确,所以可以根据已有的正确点进行重新确认点的位置。主要思路为:在对应的块部分,求取最小的余弦值,纠正距离计算的角点。

一下是简单的代码,没有做优化何处理,纯当作思路思考!

#include<iostream>
#include<string>
#include<vector>

#include "./Include/opencv/cv.h"
#include"./Include/opencv2/highgui/highgui.hpp"
#include"./Include/opencv2/imgcodecs.hpp"
#include"./Include/opencv2/imgproc.hpp"

#pragma comment(lib, "./Lib/Windows/debug/opencv_world300d.lib")

//纠正一个钝角的角点;
void correctObtuseAngle(CvPoint *pCvPointCenter, CvPoint* pCvPointVertex, const CvPoint *pCvPointLeft, \
	const CvPoint* pCvPointRight, const CvSeq* pMaxCountor, const int nPosition);

struct Vertor
{
	int x; 
	int y;
	Vertor(int _x, int _y)
	{
		x = _x;
		y = _y;
	}
};

//获取连通域的中心位置;
void getCenterPoint(CvPoint *pCvPointCenter, CvSeq* pMaxCountor)
{
	int nSize = pMaxCountor->total;
	float fAVerageX = 0;
	float fAverageY = 0;
	for (int i = 0; i < nSize; ++i)
	{
		CvPoint *pTempPoint = (CvPoint*)cvGetSeqElem(pMaxCountor, i);
		fAVerageX += pTempPoint->x * 1.0 / nSize;
		fAverageY += pTempPoint->y * 1.0 / nSize;
	}
	pCvPointCenter->x = fAVerageX;
	pCvPointCenter->y = fAverageY;
	return;
}

//获取一个角度的Cos值;
float getCosValue(CvPoint cvPointMid, CvPoint cvPointLeft, CvPoint cvPointRight)
{
	float fCosValue = (cvPointLeft.x - cvPointMid.x) * (cvPointRight.x - cvPointMid.x) + \
		(cvPointLeft.y - cvPointMid.y) * (cvPointRight.y - cvPointMid.y);
	float fAbsData = sqrt(pow(cvPointLeft.x - cvPointMid.x, 2) + pow(cvPointLeft.y - cvPointMid.y, 2)) * \
		sqrt(pow(cvPointRight.x - cvPointMid.x, 2) + pow(cvPointRight.y - cvPointMid.y, 2));
	if (fAbsData == 0)
	{
		return 0;
	}
	return fCosValue / fAbsData;
}

//修正最大的钝角点 1-左上角, 2-右上角, 3-左下角, 4-右下角;
void correctMaxObtuseAnglePoint(CvPoint* pCvPointCenter, CvPoint* pCvPointLeftUp, CvPoint* pCvPointLeftButtom, \
	CvPoint* pCvPointRightUp, CvPoint* pCvPointRightButtom, CvSeq* pMaxCountor)
{
	if (pCvPointCenter == NULL || pCvPointLeftUp == NULL || pCvPointLeftButtom == NULL || \
		pCvPointRigh
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值