Skip to content

Instantly share code, notes, and snippets.

@Myralllka
Last active October 23, 2022 13:32
Show Gist options
  • Save Myralllka/331892191c70b6a3f3ed77b5a4125999 to your computer and use it in GitHub Desktop.
Save Myralllka/331892191c70b6a3f3ed77b5a4125999 to your computer and use it in GitHub Desktop.
how to compile OpenCV+contrib for ROS on Ubuntu 20.0.4

My system configuration

12.07.2022

  • Ubuntu 20.0.4
  • ROS Noetic
  • apt OpenCV v4.2.0
  • upstream OpenCV v4.6.0

How to compile OpenCV4 + contrib for ROS on Ubuntu 20.0.4

Important information

  • sudo apt install libopencv-dev will install OpenCV in /usr/include/..., but in the official documentation) path is different
  • I just made a semlynk from /usr/local/include/opencv4/opencv2 to /usr/include/opencv4/opencv2 after renaiming the last one original to opencv2_recovery
  • vision_opencv ROS package also should be built from scretch. Just clone it to your workspace and catkin clean; catkin build

How to compile OpenCV2 behind with OpenCV4 on Ubuntu 20.0.4 for OCamCalib usage with automated cornes extraction in year 2022

  • Download the official sources to some directory (for example ~/Downloads)
  • In CMakeLists.txt change the CMAKE_INSTALL_PREFIX to some path (for example ~/libs/opencv2)
  • Change the Makefile in OCamCalib to:
INCS = -I/home/$USER/libs/opencv2/include
LIBS = -L/home/$USER/libs/opencv2/lib

LINKLIBS = -lopencv_core -lopencv_highgui -lopencv_imgproc

CPP  = g++
CC   = gcc
OBJ  = main.o cvcalibinit3.o 
LINKOBJ  = main.o cvcalibinit3.o 
BIN  = FindCorners.exe
RM = rm -f

all: $(BIN)

clean:
	${RM} $(OBJ) $(BIN)

$(BIN): $(OBJ)
	$(CPP) $(LINKOBJ) -g -o $(BIN)  $(LIBS) $(LINKLIBS)

main.o: main.cpp
	$(CPP) -c -g main.cpp -o main.o $(INCS)

cvcalibinit3.o: cvcalibinit3.cpp
	$(CPP) -c -g cvcalibinit3.cpp -o cvcalibinit3.o  $(INCS)

(not a lot of changes)

  • Also some additional shared libraries for Matlab and OpenCV should be installed (which one - it will be written in the output of the OCamCalib during the calibration process)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment