概述黑马程序员人工智能教程_10小时学会图像处理OpenCV入门教程,3.6霍夫线检测代码,关于直线绘制的部分,没看懂,这里,根据据我自己的理解,画直线的代码已经实现了。原理与实现对于直角坐标系下的y=ax+b,极坐标系下rho=x*cos(theta)+y*sin(theta),两边同时除以sin(theta)得到以下公式:y=-cos(theta)/sin(theta)*x+rho/sin(theta)当sin(theta)==0时,有x=rho/cos(theta)当sin(theta)!=0时,有一个=-cos(theta)/sin(theta);b=rho/sin(theta)由a,b可以得到直角坐标系下直线的方程,求出两点画直线。在图片上画直线的代码如下所示,最终效果与老师视频中的效果一致。代码看起来像这样print('lines.shape=',lines.shape)h,w=img.shape[:2]forlineinlines:rho,theta=line[0]ifmath.sin(theta)==0:x=int(rho/math.cos(theta))cv.line(img,(x,0),(x,h-1),(0,255,0))else:a=-数学。cos(theta)/math.sin(theta)b=rho/math.sin(theta)#y=a*x+b,计算直线上的两个点x1=0y1=int(b)x2=w-1y2=int(a*x1+b)cv.line(img,(x1,y1),(x2,y2),(0,255,0))参考https://zhuanlan.zhihu.com/p/。..(houghtransform原理及实现(转载)-知乎)
