OpenCV Error: Bad argument (Unknown interpolation method) in resize problem solving

created at 07-31-2021 views: 34

environment

  • The operating environment of this article
  • System: Ubuntu 18.04
  • ROS version: melodic
  • OpenCV version: 3.4.3
  • Python version: 3.6

Issue

OpenCV Error: Bad argument (Unknown interpolation method) in resize, file /build/opencv-XDqSFW/opencv-3.2.0+dfsg/modules/imgproc/src/imgwarp.cpp, line 3367
terminate called after throwing an instance of 'cv::Exception'
what(): /build/opencv-XDqSFW/opencv-3.2.0+dfsg/modules/imgproc/src/imgwarp.cpp:3367: error: (-5) Unknown interpolation method in function resize

I encountered this problem when using OpenCV's detectMultiScale function in ROS. There is no problem with the code during compilation, but an error will be reported during runtime. Here you can refer to a blog:

Unknown interpolation method in function resize

The author mentioned in the blog that this problem may be caused by a conflict in library functions called during operation. Since the conversion of image data in ROS uses the cv_bridge package, this package is installed by default, and the OpenCV version it references is likely to be different from the one used in our project, which leads to conflicts. Therefore, recompiling the cv_bridge package has become the key to solving the problem.

Compile cv_bridge

step1: Enter the project directory (it is your project project, do not create other workspaces):

cd catkin_ws/src

step 2: Download the cv_bridge code:

git clone https://github.com/ros-perception/vision_opencv.git

step3: Compile the code:

cd ..
catkin_make

If at this step, you directly compile and pass, then congratulations, you are very lucky.
However, generally if you fail to pass, you will encounter some errors

Solve compilation errors

Issue 1

Could not find the following Boost libraries:boost_python37

The problem is that the boost_python37 library cannot be found. The solution to this problem is:

//Establish soft link
cd /usr/lib/x86_64-linux-gnu/
sudo ln -s libboost_python-py36.so libboost_python37.so
sudo ln -s libboost_python-py36.a libboost_python37.a

Issue 2

/usr/include/python2.7/numpy/__multiarray_api.h:1537:144: error: return-statement with no value, in function returning ‘void*’ [-fpermissive]

This problem is because cv_bridge uses python2 to compile, we need to change the python version to python3
solution

# Open the CMakeLists.txt in the cv_bridge package, and add the following two sentences in front of find_package(PythonLibs)
set(PYTHON_NUMPY_INCLUDE_DIR ~/.local/lib/python3.6/site-packages/numpy/core/include)
set(PYTHON_INCLUDE_DIR /usr/include/python3.6)

Note that the above two addresses should be changed to your own corresponding addresses

To show the address of python3 numpy:

pip3 show numpy 
created at:07-31-2021
edited at: 07-31-2021: