简体   繁体   中英

Python Opencv Structured Forests Edge Detection TypeError

When I call the OpenCV Structured Forests Edge Detection in Python as shown below, I get an error:

import numpy as np
import cv2

img = cv2.imread('2009_005193.jpg')
gray_img = np.asarray(img.mean(axis=2) / 255, np.float32)
out = cv2.ximgproc_StructuredEdgeDetection.detectEdges(gray_img)

The error I get is:

Traceback (most recent call last):
  File "gop1.py", line 19, in <module>
    out = cv2.ximgproc_StructuredEdgeDetection.detectEdges(gray_img)
TypeError: descriptor 'detectEdges' requires a 'cv2.ximgproc_StructuredEdgeDetection' object but received a 'numpy.ndarray'

In the documentation ( link to documentation ), it is present under ximgproc_StructuredEdgeDetection, as a function detectEdges().

As in the documentation, it will require 3-channel float 32 image. Perhaps you need to create the StructuredEdgeDetection Object first. However, this worked for me:

imgrgb=cv2.cvtColor(img,cv2.COLOR_BGR2RGB)/255
imgrgb=imgrgb.astype(np.float32)
model='structured edge/model.yml'
retval=cv2.ximgproc.createStructuredEdgeDetection(model)
out=retval.detectEdges(imgrgb)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM