opencv学习日志23--霍夫变换1

前言

这篇文章主要讲述opencv中霍夫变换的使用。

一、霍夫变换1

//第二题  霍夫划线
#include <opencv2/opencv.hpp>
#include <iostream>
using namespace cv;
using namespace std;

int main()
{
	cv::Mat dst;
	cv::Mat src = imread("C://Users//john//Desktop//1.jpg",0);
	std::vector<cv::Vec2f>lines;
	 Canny(src, dst, 75, 80, 3, false);
	 cv::imshow("src", src);
	 cv::imshow("dstMat", dst);
	cv::HoughLines(dst, lines, 0.7, CV_PI / 180, 90);
	std::vector<cv::Vec2f>::iterator it = lines.begin();
	for (; it != lines.end(); it++)
	{
		float rho = (*it)[0], theta = (*it)[1];
		cv::Point pt1, pt2;
		double a = cos(theta);
		double b = sin(theta);
		double x0 = a*rho;
		double y0 = b*rho;
		pt1.x = cv::saturate_cast<int>(x0 + 1000 * (-b));
		pt1.y = cv::saturate_cast<int>(y0 + 1000 * (a));
		pt2.x = cv::saturate_cast<int>(x0 - 1000 * (-b));
		pt2.y = cv::saturate_cast<int>(y0 - 1000 * (a));
		cv::line(src, pt1, pt2, cv::Scalar(255, 255, 255), 1, CV_AA);
	}
	cv::imshow("src", src);
	waitKey(0);
}

总结

1.代码可以直接运行,如有不懂请留言哦。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

@白圭

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值