Which Opencv should I use for ros Noetic?
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!
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.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 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.