ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
1

Which Opencv should I use for ros Noetic?

asked 2022-11-11 16:11:23 -0500

Hannes Bauer gravatar image

updated 2023-06-18 10:03:56 -0500

lucasw gravatar image

Hi, I am trying to implement OpenCV into a roscpp. I already managed to compile it successfully, even though it did not work to read and print a Image. It prints me this as a warning, which is the reason why it should not work I think. I have installed OpenCV 4.6.0

/usr/bin/ld: Warnung: libopencv_imgproc.so.406, benötigt von /usr/local/lib/libopencv_highgui.so.4.6.0, kann in Konflikt geraten mit libopencv_imgproc.so.4.2
/usr/bin/ld: Warnung: libopencv_core.so.4.2, benötigt von /usr/lib/x86_64-linux-gnu/libopencv_imgproc.so.4.2.0, kann in Konflikt geraten mit libopencv_core.so.406

CMakeLists.txt looks like this:

cmake_minimum_required(VERSION 2.8)

project(OpenCV2)

find_package(catkin REQUIRED COMPONENTS
  rospy
  roscpp
  std_msgs
  OpenCV
  sensor_msgs
  cv_bridge
)

find_package(OpenCV 4 REQUIRED )

catkin_package(
  #INCLUDE_DIRS include 
  #LIBRARIES Zajicek
  #CATKIN_DEPENDS geometry_msgs nav_msgs roscpp sensor_msgs std_msgs
  #DEPENDS system_lib
)

include_directories(
 ${catkin_INCLUDE_DIRS}
  ${OpenCV_INCLUDE_DIRS}
)

add_executable(OpenCV2 src/opencv_test2.cpp)

target_link_libraries(OpenCV2 ${catkin_LIBRARIES} ${OpenCV_LIBS} )

The code is a simple read and print code like this:

#include < opencv2/opencv.hpp>
#include < opencv2/core.hpp>
#include < opencv2/imgcodecs.hpp>
#include < opencv2/highgui.hpp>
#include < string>
#include < iostream>
#include < stdio.h>
#include " ros/ros.h"

int main(int argc, char* argv[])
{
  std::string image_path = "/home/nico/CATKINWS/src/OpenCV2/Loewe.jpg";

  // cv::Mat img= cv::imread("/home/nico/Greyscale.png", cv::IMREAD_GRAYSCALE);
  cv::Mat img;
  img = cv::imread(image_path, cv::IMREAD_COLOR);

  if (img.empty())
  {
    std::cout << "Could not read the image: " << image_path << std::endl;
    return -1;
  }
  else
  {
    cv::namedWindow("OpenCV Image", cv::WINDOW_AUTOSIZE);
    ;
    cv::imshow("Display window", img);
    cv::waitKey(0);  // Wait for a keystroke in the window
    cv::destroyAllWindows();
    return 0;
  }
}

It prints the following message:

"Could not read the image: /home/nico/CATKINWS/src/OpenCV2/Loewe.jpg"

So it get stuck in the if clause when img.empty()

I tried nearly the same code without ROS, and compiled it with cmake . and it worked as it should, So my guess is that OpenCV 4.6.0 is not compatible! So my question now is, which version should I use? Is my guess for the problem correct? and can I just download an old version and change the find package in the CMakeLists.txt to make it run, or do I have to delete the 4.6 version too? Thank you in advance!

edit retag flag offensive close merge delete

Comments

You do not need to compile OpenCV separately because ROS binaries comes along with OpenCV. Please install ros-noetic-desktop-full. On the other hand, in my computer, I can see that ROS Noetic is using OpenCV 4.2.0.

ravijoshi gravatar image ravijoshi  ( 2022-11-11 22:29:52 -0500 )edit

May I ask how you mean that I don't have to compile opencv alone? I generally compile the program with catkin_make ? I just tried without ros with cmake and it worked?

Apart from that I installed the ros-noetic-desktop-full? Should I now delete opencv4.6 and download 4.2? Best regards

Hannes Bauer gravatar image Hannes Bauer  ( 2022-11-12 08:02:18 -0500 )edit
1

@Hannes Bauer You have confusingly named your own ros package "opencv". Anyone you share this code with is going to be confused because of the system library with a very similar name.

Mike Scheutzow gravatar image Mike Scheutzow  ( 2022-11-12 11:42:32 -0500 )edit

1 Answer

Sort by » oldest newest most voted
1

answered 2022-11-12 11:40:09 -0500

Mike Scheutzow gravatar image

If you want to use the binary ros apt repository, noetic requires your code to compile with the ubuntu libopencv-dev package, which is opencv version 4.2 in ubuntu 20. Most people install this library from apt.

It takes much more effort for you to use any other version of opencv in noetic. You will need to compile any ros-packages that use opencv from source code, and you will have to debug the problems created by the API changes that the opencv devs make frequently.

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2022-11-11 16:11:23 -0500

Seen: 1,944 times

Last updated: Nov 12 '22