哪位大佬帮忙看下这段代码报错得怎么改

import cv2 as cv
import numpy as np

def line_detection(image):
# 变换为灰度图
gray = cv.cvtColor(image, cv.COLOR_BGR2GRAY)
# 进行Canny边缘检测
edge = cv.Canny(gray, 50, 100, apertureSize=3)
cv.imshow(“edge”, edge)
# 进行霍夫直线运算
lines = cv.HoughLines(edge, 1, np.pi/180, 200)
# 对检测到的每一条线段
for line in lines:
# 霍夫变换返回的是 r 和 theta 值
rho, theta = line[0]
a = np.cos(theta)
b = np.sin(theta)
# 确定x0 和 y0
x0 = a * rho
y0 = b * rho
# 认为构建(x1,y1),(x2, y2)
x1 = int(x0 + 1000 * (-b))
y1 = int(y0 + 1000 * a)
x2 = int(x0 - 1000 * (-b))
y2 = int(y0 - 1000 * a)
# 用cv2.line( )函数在image上画直线
cv.line(image, (x1, y1), (x2, y2), (0, 0, 255), 2)
cv.imshow(“line_detection”, image)

src = cv.imread(“road.jpg”)
cv.imshow(“shufa”, src)
line_detection(src)
cv.waitKey(0)
cv.destroyAllWindows()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值