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

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条回答

      报告相同问题?

      相关推荐 更多相似问题

      问题事件

      • 系统已结题 8月31日
      • 已采纳回答 8月23日
      • 创建了问题 7月21日

      悬赏问题

      • ¥15 session失效问题
      • ¥15 GMS地下水数值模拟无法打开
      • ¥15 树型结构的数据怎么匹配分支
      • ¥15 stm32F4用.引不出来结构体成员怎么解决
      • ¥15 .exe文件打不开怎么解决?
      • ¥30 Syntax Error: TypeError: this.getOptions is not a function的问题
      • ¥15 eclipse Android环境搭建
      • ¥15 unity中脚本之间的继承有什么作用
      • ¥15 C语言内存对齐代码不太理解
      • ¥15 uniapp中的uni-file-picker组件多图上传,删除,显示。以及C#.Net后端处理问题