Mag1c_D
2021-07-21 02:30
采纳率: 100%
浏览 188
已结题

OpenCv cv.Canny函数总是报错

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](

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题