opencvdnn9

cv2.error: OpenCV(4.3.0) ../opencv_contrib/modules/dnn_superres/src/dnn_superres.cpp:97: error: (-2:Unspecified error) Model not specified


Im trying out this article;

https://towardsdatascience.com/deep-learning-based-super-resolution-with-opencv-4fd736678066

this is the code copied out of the article;

import cv2 from cv2 import dnn_superres

sr = dnn_superres.DnnSuperResImpl_create()

image = cv2.imread('./input.png')

path = "EDSR_x3.pb" sr.readModel(path)

sr.setModel("edsr", 3)

result = sr.upsample(image)

cv2.imwrite("./upscaled.png", result)

i also tried opencv Super Resolution Tutorial;

https://docs.opencv.org/master/d5/d29/tutorial_dnn_superres_upscale_image_single.html

import cv2 from cv2 import dnn_superres

sr = dnn_superres.DnnSuperResImpl_create()

image = cv2.imread('./image.png')

path = "EDSR_x4.pb" sr.readModel(path)

sr.setModel("edsr", 4)

result = sr.upsample(image)

cv2.imwrite("./upscaled.png", result)

My enviroment is anaconda3 opencv 4.3.0. I either get the error from the title or i get "killed" when i run the opencv example.

*My file directory is all on the same level of the sample codes. I would just change my image file names. I did try to compile opencv and opencv_contrib from cmake but, i didn't know how to have python refer to opencv and opencv_contrib from source. ifollow this documentation to install opencv from source; https://d*ocs.opencv.org/3.4/d2/de6/tutorial_py_setup_in_ubuntu.html

I opted to use anaconda wrapping of opencv 4.3.0 because i ran into too many dependency and wrongly installed package problems.

My friend from a meetup managed to apply the code from the article just as the article depicted while i tried to follow exactly what he did, using an anaconda enviorment. Would my problem stem from my virtual enviorment or opencv package version or the code itself? i did have another colleague run my code from my github branch and he had my exact same problems. How should i apprach the bugs im having and apply the super resolution examples i found?


Solution

  • The error 'Model not specified' comes from the fact that the Net is empty. You have to actually download the model and then provide the path to the 'sr.readModel()' function.

    If you did that and it still does not work, you could try these two things:

    1. Try a smaller image (in .png format).

    2. Build OpenCV from source. Do not forget the contrib modules (this is where the dnn_superres module resides). You said you had a problem linking python. I would suggest to use this tutorial. After following that tutorial, do the following command (after you already did sudo make install), to link the python libraries:

    sudo ldconfig