import cv2 as cv
import numpy as np
def line_detect(image):
edges = cv.Canny(image, 50, 200, apertureSize=3)
print("edges", edges)
lines = cv.HoughLines(edges, 1, np.pi/180, 150)
for line in lines:
rho, theta = line[0]
a = np.cos(theta)
b = np.sin(theta)
x0 = a * rho
y0 = b * rho
x1 = int(x0 + 1000 * (-b))
y1 = int(y0 + 1000 * (a))
x2 = int(x0 - 1000 * (-b))
y2 = int(y0 - 1000 * (a))
cv.line(image, (x1, y1), (x2, y2), (0, 0, 255), 2)
cv.imshow("image_lines", image)
print("Hello")
src = cv.imread("F:/2.png")
src1 = np.array(src)
src1[..., 0] = src1[..., 0] * 0.299
src1[..., 1] = src1[..., 1] * 0.587
src1[..., 2] = src1[..., 2] * 0.114
src1 = np.sum(src1, axis=-1)
line_detect(src1)
cv.waitKey(0)
Hello
Traceback (most recent call last):
File "E:/PycharmProjects/learnPython/venv/test.py", line 33, in
line_detect(src1)
File "E:/PycharmProjects/learnPython/venv/test.py", line 6, in line_detect
edges = cv.Canny(image, 50, 200, apertureSize=3)
cv2.error: OpenCV(4.5.2) :-1: error: (-5:Bad argument) in function 'Canny'
Overload resolution failed:
- image data type = 8 is not supported
- Expected Ptrcv::UMat for argument 'image'
- Required argument 'threshold2' (pos 4) not found
- Required argument 'threshold2' (pos 4) not found
![img](