【问题标题】:Python OpenCV, return an binary array when edge is detectedPython OpenCV,检测到边缘时返回二进制数组
【发布时间】:2018-07-28 04:32:25
【问题描述】:

通过在opencv中使用'Canny'函数,输出参数是numpy数组,如[0,0,0,0,255]等。如果检测到返回1,我可以输出一个二进制数组,如真/假或1/0。实际上matlab默认这样做。请查看输出部分。 Find edges in intensity image, Matlab

在这样的python代码中:

import cv2
import numpy as np
from matplotlib import pyplot as plt

img = cv2.imread('messi5.jpg',0)
edges = cv2.Canny(img,100,200) #numpy array. must be binary array (1/0) 

【问题讨论】:

    标签: python-3.x opencv image-processing edge-detection


    【解决方案1】:

    您可以立即转换输出数组:

     edges_bool = cv2.Canny(img,100,200).astype(bool)
    

    或者,您可以稍后使用以下功能:

    edges_bool = np.asarray(edges, dtype=bool)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-02
      • 1970-01-01
      • 1970-01-01
      • 2012-10-17
      相关资源
      最近更新 更多