Unknown C++ exception from OpenCV code in Holistically-Nested Edge Detection (HED)

44 Views Asked by At

I am currently working on an image processing project and have encountered an issue with the apply_hed function. The function aims to perform HED (Holistically-Nested Edge Detection) on an input image using OpenCV's dnn module. However, I am encountering an unknown C++ exception during the execution of the net.forward() method.

Here is the relevant code snippet:

# Net is loaded with the pretrained model and weights
net = cv2.dnn.readNetFromCaffe('deploy.prototxt', 'hed_pretrained_bsds.caffemodel')

def apply_hed(image):
    # Get the width and height
    height, width = image.shape[:2]

    # Perform HED on the resized image
    net.setInput(cv2.dnn.blobFromImage(image, scalefactor=1.0, size=(width, height),
                                      mean=(tuple(np.average(image, axis=(0, 1)))), swapRB=False, crop=False))
    hed_output = net.forward()  # <-- Exception occurs here
    hed_output = hed_output[0, 0, :, :]
    hed = (255 * hed_output).astype("uint8")
    
    return hed

The error message I am getting is:


----> 8 hed_output = net.forward()

error: Unknown C++ exception from OpenCV code

I am using a pretrained HED model from the following sources:

deploy.prototxt hed_pretrained_bsds.caffemodel

Interestingly, the code runs without issues if the input image dimensions are below 3000 pixels in height and width. Any insights or suggestions would be greatly appreciated. Thank you!

What I tried:

I tried using different versions of OpenCV within a virtual environment to explore potential version-specific compatibility issues. I tested multiple versions to see if the exception persisted or if there were any improvements. Unfortunately, the issue remained unresolved across different OpenCV versions.

Expectation:

I expected the net.forward() method to successfully compute the HED output for the given image, and subsequently, the function would return the edge-detected result (hed). The goal was to integrate HED into my image processing pipeline.

Actual Result:

Unfortunately, during the execution of net.forward(), an unknown C++ exception from OpenCV code occurred. The error message provided little information about the specific nature of the exception, making it challenging to identify the root cause of the issue. Notably, I observed that the code runs without issues if the input image dimensions are below 3000 pixels in height and width. This led me to suspect that the exception might be related to the image size.

0

There are 0 best solutions below