Tossy0423 / yolov4-for-darknet_ros

This is the environment in which YOLO V4 is ported to darknet_ros.
MIT License
108 stars 53 forks source link

error "OpenCV 4.x+ requires enabled C++11 support" #13

Open liang-grape opened 3 years ago

liang-grape commented 3 years ago

When I catkin_make,

the error "/usr/include/opencv4/opencv2/core/cvdef.h:690:4: error: #error "OpenCV 4.x+ requires enabled C++11 support" occurs. I have tried all ways I can search online, but I cannot solve the problem.

Could you give some advice?

Thank you

fjlv520 commented 3 years ago

hello, I met the same issue, did u solve it?

fjlv520 commented 3 years ago

Ok,I solve it. Modify the cvbridgeConfig.cmake file,change the SET_OPENCV_DIR to the path of opencv 3.x.x

zeta0707 commented 3 years ago

Hi fjlv520,

I met same issue with Jetson Nano, image is Jetpack4.5.1. OpenCV 4.1.1 is pre-installed here. Do you install openCV3.x in parallel?

Thanks!

fjlv520 commented 3 years ago

@zeta0707 Yes, I installed opencv3.4.1 additionally.

zeta0707 commented 3 years ago

@fjlv520

I delete pre-installed opencv4.1.1, then installed opencv3.4.6 into /usr/local. I also built successfully.

Thanks!

iamrajee commented 2 years ago

same issue!

iamrajee commented 2 years ago

I want to work with yolov4 with opencv4, leggedrobotics branch support opencv4 but not yolov4 and Tossy0423 branch support yolov4 but not opencv4.

iamrajee commented 2 years ago

@fjlv520

I delete pre-installed opencv4.1.1, then installed opencv3.4.6 into /usr/local. I also built successfully.

Thanks!

Could you eloborate the steps. I install the opencv 3.4.1 using pip, however I couldn't locate it in /usr/include. Additionally I couldn't even locate "SET_OPENCV_DIR". Instead I found the include path as below Screenshot from 2021-10-04 16-38-46

Am I doing something wrong? (I'm on noetic) I'm new to opencv, sorry for asking a silly doubt, Thanks for the help!

fettahyildizz commented 2 years ago

4.1 addi

Could you eloborate the steps, please? I am having the same issue.

iamrajee commented 2 years ago

@fettahyildizz I got it running by following the below steps. Just install OpenCV 3 and changed cvbridge opencv path.

iamrajee commented 2 years ago

@fettahyildizz Here are the detailed steps:

Installing OpenCV 3.4.6 (along with previous '4.5.3') https://learnopencv.com/install-opencv3-on-ubuntu/

cd /usr/include/

  1. git clone https://github.com/opencv/opencv.git

  2. cd opencv

  3. git checkout 3.3.1

  4. cd ..

  5. git clone https://github.com/opencv/opencv_contrib.git

  6. cd opencv_contrib

  7. git checkout 3.3.1

  8. cd ..

  9. cd opencv

  10. mkdir build

  11. cd build

cmake -D CMAKE_BUILD_TYPE=RELEASE \
      -D CMAKE_INSTALL_PREFIX=/usr/local \
      -D INSTALL_C_EXAMPLES=ON \
      -D INSTALL_PYTHON_EXAMPLES=ON \
      -D WITH_TBB=ON \
      -D WITH_V4L=ON \
      -D WITH_QT=ON \
      -D WITH_OPENGL=ON \
      -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules \
      -D BUILD_EXAMPLES=ON ..
  1. find out number of CPU cores in your machine

  2. nproc
  3. substitute 4 by output of nproc

  4. make -j4
  5. sudo make install
  6. sudo sh -c 'echo "/usr/local/lib" >> /etc/ld.so.conf.d/opencv.conf'
  7. sudo ldconfig

Now lets check if we can import previous version of opencv i.e 4.5.3

python3

import cv2 cv2.version ⇒ Should output '4.5.3', if not and give the below error

ImportError: ERROR: recursion is detected during loading of "cv2" binary extensions. Check OpenCV installation.

Then run this: sudo pip3 install opencv-python --upgrade --force-reinstall

Now, Lets change opencv version in cv_bridge cd /opt/ros/noetic/share/cv_bridge/cmake code cv_bridgeConfig.cmake image

fettahyildizz commented 2 years ago

@iamrajee wow you're a life saver. Thanks a lot for detailed explanations. I will try it on monday.

fettahyildizz commented 2 years ago

@iamrajee I will be using this package on Ros-Melodic therefore, I will run it on Python 2.7. I am going to change every "pip3" command to "pip" while following your steps.

tandrewsnz commented 2 years ago

A bit late but I found an easier fix was using sudo apt -y --allow-downgrades install libopencv-dev=3.2.0+dfsg-4ubuntu0.1 to force downgrade my opencv version to 3.2 from 4.1. as mentioned here

iamrajee commented 2 years ago

Is there any way to get it work with OpenCV 4.x itself, like by adding -std=c++11 somewhere in CMakeLists.txt as suggest here(1, 2). I tried adding below lines, but none of them helped.

add_definitions(-std=c++11)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_FLAGS "-std=c++11 ${CMAKE_CXX_FLAGS}")

What is the root problem here? Could somebody elaborate? Thank you!

kyuhyong commented 2 years ago

@iamrajee Did you solve the issue? I am having the same problem. Installed opencv 3.4 on jetson nano. Also running ros-melodic.

kyuhyong commented 12 months ago

After a while I revisited this issue and finally able to build and run on ROS noetic + CUDA 12.2 + opencv4+ You can checkout my forked version of darknet_ros as branch opencv4 and clone to your catkin workspace. https://github.com/kyuhyong/yolov4-for-darknet_ros/tree/opencv4