Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/349.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 多幅图像的边缘检测_Python_Opencv_Image Processing_Edge Detection - Fatal编程技术网

Python 多幅图像的边缘检测

Python 多幅图像的边缘检测,python,opencv,image-processing,edge-detection,Python,Opencv,Image Processing,Edge Detection,嗨,我有一组图像,我想同时对所有图像进行边缘检测。我可以为每个图像手动执行,但我认为这不是正确的方法。如何一次对所有图像执行此操作?我认为它应该在一个循环中,但我不知道如何实现它 我读过多幅灰度图像,现在我想对所有图像进行边缘检测。我们如何为Canny函数选择最大值和最小值参数。可以访问这些图像 要自动选择cv2.Canny()的最大值和最小值,可以使用Adrian Rosebrock在其博客中创建的auto\u Canny()函数。其思想是计算图像中像素强度的中值,然后取该中值来确定下限和上限

嗨,我有一组图像,我想同时对所有图像进行边缘检测。我可以为每个图像手动执行,但我认为这不是正确的方法。如何一次对所有图像执行此操作?我认为它应该在一个循环中,但我不知道如何实现它

我读过多幅灰度图像,现在我想对所有图像进行边缘检测。我们如何为Canny函数选择最大值和最小值参数。可以访问这些图像


要自动选择
cv2.Canny()
的最大值和最小值,可以使用Adrian Rosebrock在其博客中创建的
auto\u Canny()
函数。其思想是计算图像中像素强度的中值,然后取该中值来确定
下限
上限
阈值。想了解更详细的解释,请查看他的博客。下面是函数

def auto_canny(image, sigma=0.33):
    # Compute the median of the single channel pixel intensities
    v = np.median(image)

    # Apply automatic Canny edge detection using the computed median
    lower = int(max(0, (1.0 - sigma) * v))
    upper = int(min(255, (1.0 + sigma) * v))
    return cv2.Canny(image, lower, upper)

要对多个图像执行边缘检测,可以使用
glob
库对每个图像进行迭代,应用canny边缘检测,然后保存图像。这是结果

def auto_canny(image, sigma=0.33):
    # Compute the median of the single channel pixel intensities
    v = np.median(image)

    # Apply automatic Canny edge detection using the computed median
    lower = int(max(0, (1.0 - sigma) * v))
    upper = int(min(255, (1.0 + sigma) * v))
    return cv2.Canny(image, lower, upper)
import cv2
import numpy as np
import glob

def auto_canny(image, sigma=0.33):
    # Compute the median of the single channel pixel intensities
    v = np.median(image)

    # Apply automatic Canny edge detection using the computed median
    lower = int(max(0, (1.0 - sigma) * v))
    upper = int(min(255, (1.0 + sigma) * v))
    return cv2.Canny(image, lower, upper)

# Read in each image and convert to grayscale
images = [cv2.imread(file,0) for file in glob.glob("images/*.jpg")]

# Iterate through each image, perform edge detection, and save image
number = 0
for image in images:
    canny = auto_canny(image)
    cv2.imwrite('canny_{}.png'.format(number), canny)
    number += 1