Python canny边缘检测中的误差获取

Python canny边缘检测中的误差获取,python,opencv,Python,Opencv,我正在尝试使用opencv python编写一段代码,自动获取canny阈值,而不是每次手动执行 img= cv2.imread('micro.png',0) output = np.zeros(img.shape, img.dtype) # Otsu's thresholding ret2,highthresh = cv2.threshold(img,0,255,cv2.THRESH_BINARY+cv2.THRESH_OTSU) lowthresh=0.1*highthres edges =

我正在尝试使用opencv python编写一段代码,自动获取canny阈值,而不是每次手动执行

img= cv2.imread('micro.png',0)
output = np.zeros(img.shape, img.dtype)
# Otsu's thresholding
ret2,highthresh = cv2.threshold(img,0,255,cv2.THRESH_BINARY+cv2.THRESH_OTSU)
lowthresh=0.1*highthres
edges = cv2.Canny(img,output,lowthresh,highthresh)
cv2.imshow('canny',edges)
我得到了这个错误 文件“test2.py”,第14行,在 边缘=cv2.Canny(img、输出、低阈值、高阈值) TypeError:只能将长度为1的数组转换为Python标量“


有人能帮我整理一下这个错误吗?thankx提前

看起来像是
cv2。threshold
返回检测到的边缘,Canny将其应用于图像。下面的代码对我很有用,在我的图像中给了我一些很好的检测到的边缘

import cv2

cv2.namedWindow('canny demo')

img= cv2.imread('micro.png',0)
ret2,detected_edges = cv2.threshold(img,0,255,cv2.THRESH_BINARY+cv2.THRESH_OTSU)
edges = cv2.Canny(detected_edges,0.1,1.0)
dst = cv2.bitwise_and(img,img,mask = edges)
cv2.imshow('canny',dst)

if cv2.waitKey(0) == 27:
    cv2.destroyAllWindows()

它看起来像是
cv2.threshold
返回检测到的边缘,并且
Canny
将它们应用于图像。下面的代码对我很有用,在我的图像中给了我一些很好的检测到的边缘

import cv2

cv2.namedWindow('canny demo')

img= cv2.imread('micro.png',0)
ret2,detected_edges = cv2.threshold(img,0,255,cv2.THRESH_BINARY+cv2.THRESH_OTSU)
edges = cv2.Canny(detected_edges,0.1,1.0)
dst = cv2.bitwise_and(img,img,mask = edges)
cv2.imshow('canny',dst)

if cv2.waitKey(0) == 27:
    cv2.destroyAllWindows()

它看起来像是
cv2.threshold
返回检测到的边缘,并且
Canny
将它们应用于图像。下面的代码对我很有用,在我的图像中给了我一些很好的检测到的边缘

import cv2

cv2.namedWindow('canny demo')

img= cv2.imread('micro.png',0)
ret2,detected_edges = cv2.threshold(img,0,255,cv2.THRESH_BINARY+cv2.THRESH_OTSU)
edges = cv2.Canny(detected_edges,0.1,1.0)
dst = cv2.bitwise_and(img,img,mask = edges)
cv2.imshow('canny',dst)

if cv2.waitKey(0) == 27:
    cv2.destroyAllWindows()

它看起来像是
cv2.threshold
返回检测到的边缘,并且
Canny
将它们应用于图像。下面的代码对我很有用,在我的图像中给了我一些很好的检测到的边缘

import cv2

cv2.namedWindow('canny demo')

img= cv2.imread('micro.png',0)
ret2,detected_edges = cv2.threshold(img,0,255,cv2.THRESH_BINARY+cv2.THRESH_OTSU)
edges = cv2.Canny(detected_edges,0.1,1.0)
dst = cv2.bitwise_and(img,img,mask = edges)
cv2.imshow('canny',dst)

if cv2.waitKey(0) == 27:
    cv2.destroyAllWindows()
您正在运行:

cv2.Canny(img,output,lowthresh,highthresh)
它正在寻找

cv2.Canny(img,lowthresh,highthresh,output)
我认为在某些版本中,顺序发生了变化,因为我看到了两者的引用。

您正在运行:

cv2.Canny(img,output,lowthresh,highthresh)
它正在寻找

cv2.Canny(img,lowthresh,highthresh,output)
我认为在某些版本中,顺序发生了变化,因为我看到了两者的引用。

您正在运行:

cv2.Canny(img,output,lowthresh,highthresh)
它正在寻找

cv2.Canny(img,lowthresh,highthresh,output)
我认为在某些版本中,顺序发生了变化,因为我看到了两者的引用。

您正在运行:

cv2.Canny(img,output,lowthresh,highthresh)
它正在寻找

cv2.Canny(img,lowthresh,highthresh,output)

我认为在某些版本中,顺序发生了变化,因为我看到了两者的引用。

这没有给我所需的输出。我必须处理多张图片,这就是为什么我不能每次设置阈值,因为我从这里得到了概念。但它不适用于methis,它没有给我所需的输出。我必须处理多张图片,这就是为什么我不能每次设置阈值,因为我从这里得到了概念。但它不适用于methis,它没有给我所需的输出。我必须处理多张图片,这就是为什么我不能每次设置阈值,因为我从这里得到了概念。但它不适用于methis,它没有给我所需的输出。我必须处理多张图片,这就是为什么我不能每次设置阈值,因为我从这里得到了概念。但它不为梅工作,我认为它与png文件有问题,我也得到同样的错误。尝试将图像转换为JPGI。我认为它与png文件有问题,我也得到了相同的错误。尝试将图像转换为JPGI。我认为它与png文件有问题,我也得到了相同的错误。尝试将图像转换为JPGI。我认为它与png文件有问题,我也得到了相同的错误。尝试将图像转换为JPG