使用opencv测量点到线的距离

博客介绍了如何利用opencv库,通过鼠标选择两点绘制直线,再选取一点计算其到直线的距离。由于鼠标精度限制,测量存在误差。
摘要由CSDN通过智能技术生成

首先通过鼠标操作在图片上随机点两个点,创建一条直线。然后点第三个点,该点到直线的距离就出来了。
由于鼠标点击有误差,所以测的距离有误差,还请大佬指点!

#include "opencv2/opencv.hpp"
#include <iostream>
#include <math.h>

using namespace cv;
using namespace std;

//定义一个计算两点距离的函数
double getDistance(CvPoint pointO, CvPoint pointA)
{
   
	double distance;
	distance = powf((pointO.x - pointA.x), 2) + powf((pointO.y - pointA.y), 2);
	distance = sqrtf(distance);
	return distance;
}

//定义一个将长整形转换成字符串型的函数
string convertToString(long d)
{
   
	ostringstream os;
	if (os << d)
		return os.str();
	return "invalid conversion";
}


//定义全局变量
static Mat img_src;

static Point point1 = Point(0, 0);//第一个点(x1,y1)
static Point point2 = Point(0, 0);//第二个点(x2,y2)
static Point point3 = Point(0, 0);//第三个点(x3,y3)
static Point point4;//第四个点(x4,y4)
static Point point5;

static Point mouse_dot;
static string window_name = "image&#
  • 0
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值