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

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?

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:
Try a smaller image (in .png format).
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

Related

Loading external urdf with CMakeList for apt installed drake

I am trying to integrate drake as a physics simulator with in my code. My code does have ros2 as IPC, but the code itself is ROS agnostic. I am using colcon to build the code and I am using CMakeList with drake installed using apt on ubuntu 22.04.
I am trying to load the urdf in drake with in my class structure. I my header file, I defined the following parameters:
drake::systems::DiagramBuilder<double> builder_;
drake::multibody::MultibodyPlant<double>* plant_{};
drake::geometry::SceneGraph<double>* scene_graph_{};`
In my source file, my code is
std::tie(plant_, scene_graph_) = AddMultibodyPlantSceneGraph(&builder_, std::make_unique<MultibodyPlant<double>>(1e-3));
const std::string urdf = drake::FindResourceOrThrow("path_to_urdf/urdf.urdf");
drake::multibody::Parser(plant_).AddModelFromFile(urdf);
However, when I run the code, I get the following message
[****] terminate called after throwing an instance of 'std::runtime_error'
[***] what(): Drake resource_path '~/path_to_urdf/urdf.urdf' does not start with drake/.
I verified that file is available on the link. I tried creating the manual drake folder as well, but it keeps complaining.
I did saw the issue https://github.com/RobotLocomotion/drake-external-examples/issues/170 open but I am not sure if it is related to that. Any help or guidance will be highly appreciated.
In general, don't use FindResourceOrThrow to load models. It's intended only for Drake build system resources.
To use AddModelFromFile, just pass it an absolute path:
std::tie(plant_, scene_graph_) = ...
drake::multibody::Parser(plant_).AddModels("/full/path/to/myproject/urdf/foo.urdf");
You can also use ROS package paths, if you are using package.xml files:
std::tie(plant_, scene_graph_) = ...
drake::multibody::Parser parser(plant_);
parser.package_map().PopulateFromRosPackagePath();
std::string package_dir = parser.package_map().GetPath("myproject");
parser.AddModels(package_dir + "/urdf/foo.urdf");
In the next version of Drake (v1.13.0), there will also be a AddModelsFromUrl function to make ROS package paths even easier.

Running lua ML model from Google Colab

I am trying to run the AdaIN-style model in Google Colab. In order to do this, I need to install Lua. I saw this question and tried the solution given (reproduced below for convenience), both with the given distro and the official torch distro.
%cd /content/
!git clone https://github.com/nagadomi/distro.git torch --recursive
import os
os.chdir('./torch/')
!bash install-deps
!./install.sh
!. ./install/bin/torch-activate
Now it should work using absolute path to th:
!/content/torch/install/bin/th neural_style.lua -style_image examples/inputs/picasso_selfport1907.jpg -content_image examples/inputs/brad_pitt.jpg
However, the last line fails, giving me the below error
/bin/bash: . ./install/bin/torch-activate: No such file or directory
However, the binary for th seems to exist at the given filepath. Thus, I try to run the given command
th test.lua -content input/content/cornell.jpg -style input/style/woman_with_hat_matisse.jpg
but I get the following error
/content/torch/install/bin/luajit: /content/torch/install/share/lua/5.1/trepl/init.lua:389: module 'cudnn' not found:No LuaRocks module found for cudnn
I tried looking this up further, but wasn't able to make much progress.
I also tried this method, which seems similar to the above, but I get the same errors.
Any pointers would be appreciated.

No module named 'manipulation'

I am using Ubuntu 22.04 LTS via WSL and working on Python 3.10. When I try to run Drake tutorials locally with python3 -m pydrake.tutorials I get the following error: ERROR: the Jupyter notebook runtime is not installed! which is not the case since I already installed jupyter-notebook using sudo apt-get install jupyter-notebook and can easily open a jupyter notebook myself when typing jupyter notebook.
Additionally, I tried to copy-paste and run the following code from a tutorial:
import pydot
from IPython.display import HTML, SVG, display
from pydrake.all import (AddMultibodyPlantSceneGraph, DiagramBuilder,
FindResourceOrThrow, GenerateHtml,
InverseDynamicsController, MeshcatVisualizer,
MeshcatVisualizerParams, MultibodyPlant, Parser,
Simulator, StartMeshcat)
from manipulation import running_as_notebook
and i get the following error:
ModuleNotFoundError: No module named 'manipulation'
It seems as I don't have a module called manipulation except the one inside pydrake library. Is this a version issue?
I desired to mention it in case the two errors are interconnected.
None of the tutorials in Drake import anything from manipulation. The manipulation textbook repository examples absolutely do. You can find more about those here: https://manipulation.csail.mit.edu/drake.html .

pydrake is not available for installation anymore through google colab?

I have been using a google colab template for iterative LQR that uses the Pydrake, however, it seems like the code repository is removed and I can't reinstall it on google Colab:
try:
import pydrake
import underactuated
except ImportError:
!curl -s https://raw.githubusercontent.com/RussTedrake/underactuated/master/scripts/setup/jupyter_setup.py > jupyter_setup.py
from jupyter_setup import setup_underactuated
setup_underactuated()
# Setup matplotlib backend (to notebook, if possible, or inline).
from underactuated.jupyter import setup_matplotlib_backend
plt_is_interactive = setup_matplotlib_backend()
File "/content/jupyter_setup.py", line 1
404: Not Found
^
SyntaxError: invalid syntax
I tried clicking this link https://raw.githubusercontent.com/RussTedrake/underactuated/master/scripts/setup/jupyter_setup.py, and the page is not found... everything was working fine yesterday
Sorry. You're correct... I updated it this morning, and don't have a good deprecation policy in place on that repo, and this setup script is two versions ago. The path you want is https://raw.githubusercontent.com/RussTedrake/underactuated/master/setup/jupyter_setup.py
(remove the script from the directory). But if you look at that file, you'll see that even that is pointing to an updated setup script which you might want to point to.
This is actually all good news... we are on the path to a much better solution. You can now just pip install drake on colab (see the drake installation guide). Once I land the pip install underactuated (probably in time for my Spring offering of the class), then all of that nasty setup will be gone.

how to combine Opencv module (virtualenvwrapper) and Tensorflow module (another virtualenv)?

Following several instructions on the web, I could install Opencv3.0 and tensorflow on my Ubuntu 16.04. Each tutorial recommends using virtual environment. Although I agree that, problem is that I just followed the tutorials and created separate environments.
** For minor information, Tensorflow installation was easy, but Opencv3.0 was hard.
I used virtualenv for Tensorflow with the name tf, and virtualenvwrapper for Opencv with the name cv, i.e., I activate tf by $ source ~/project/tf/bin/activate, and cv by $ workon cv.
In this case, what is the best way of using both?
Should I activate both always?
Should I enter one environment and install the other again?
Should I symlink site-package/cv.so to tf environment?
I think cv is now in the python site-package folder. I create tf with --site-package option, but it was before installing cv. I am so confusing. Please help.
Yes, I had the same issue and the sym-link between tensorflow and openCV will not work after making the cv.so inside the tf virtualenv after some struggle I got them both to work in the same environment but I suggest uninstalling openCV and then install it back without using a virtual environment for better results.
Cheers.

Resources