Skip to content

Commit

Permalink
Opencv4 upgrade (#781)
Browse files Browse the repository at this point in the history
!!!!!!!!!!!!!!!!!!!!!!!!!!!Users need to remove:
    dpkg -r astrobee0 &&
    dpkg -r libalvar2 &&
    dpkg -r libopenmvg1 &&
    dpkg -r libdbow21 &&
    dpkg -r libdbowdlib1 &&
    dpkg -r libopencv3.3.1
and re-do the install setup!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

* Starting to update the marker tracking

* Compiles with OpenCV4

* Now Astrobee works

* Clean up references to old OpenCV find cmake path

* Cleaned up

* Set 4.2.0 version

* Set opencv back on list of thirdparty, now installed in /usr

* Fixed gazebo parameter passing bug in xacro and allowed using ns bsharp by deleting hard-coded assumption of bsharp in astrobee_gazebo

* install newer ar_track_alvar instead of alvar

* compiling in ubuntu 20.04 with full opencv

* reverting sim changes

* fixing ar-track-alvar install

* add new alvar libs to gitignore

* patch fixes cmake error

* reverting sim changes not related to this PR

* minimal opencv install of only xfeatures2d

* fixing astrobee dependencies

* Add debian build configuration for ar-track-alvar-msgs

* Remove postinst and postrm files from alvar-msgs

These files won't work when installing on the robots

* Add debian build configuration files for ar-track-alvar

* Remove postinst and postrm from alvar

These files won't work on the robots

* Remove use of bloom-generate

Pretty cool tool but not the best option in the context of the
robots and compilation for armhf

* Remove .dirs files since dh_install is enough

* Update opencv install files

Using arch-specific files since there is no expansion support
in compat 9. Also I don't want to make the install file an
executable.

* Remove old alvar script

* Update opencv not-installed to include files from any architecture

* Update openmvg debian control files

* Changelog now reflects new patch
* Removing unnecessary dependency to save space on the robots

* Upgrade dbow2 to OpenCV 4

* Increase version to reflect opencv4 upgrade

* Add our custom CMake modules

This may be a temporal thing if we decide to put back this change
into the nodes that require it

* fix gen hugin script for ubuntu 20

* remove ros-pcl dependency

* Update remove_pcl patch

* fix hugin api read pto

* fixes from review

* adding packages to install list

* change install script to be clear we're not installing the entire opencv

* reducing the not-install list

* changing cmake name to make it clearer; didn't want to add an extra line to the cmake on all the opencv4 dependencies

* fixes from running docker

---------

Co-authored-by: Ana C. Huaman Quispe <[email protected]>
Co-authored-by: Ruben Garcia <[email protected]>
  • Loading branch information
3 people authored May 28, 2024
1 parent ca223f5 commit 9964356
Show file tree
Hide file tree
Showing 107 changed files with 690 additions and 1,248 deletions.
41 changes: 0 additions & 41 deletions cmake/FindOpenCV331.cmake

This file was deleted.

108 changes: 108 additions & 0 deletions cmake/FindOpenCV4WithXFeatures.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@

# Find OpenCV installation
find_package(OpenCV 4.0 REQUIRED)


list(APPEND OpenCV_LIB_COMPONENTS "opencv_xfeatures2d")

if(NOT CMAKE_VERSION VERSION_LESS "2.8.11")
# Target property INTERFACE_INCLUDE_DIRECTORIES available since 2.8.11:
# * http://www.cmake.org/cmake/help/v2.8.11/cmake.html#prop_tgt:INTERFACE_INCLUDE_DIRECTORIES
foreach(__component ${OpenCV_LIB_COMPONENTS})
if(TARGET ${__component})
set_target_properties(
${__component}
PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${OpenCV_INCLUDE_DIRS}"
)
endif()
endforeach()
endif()

# ==============================================================
# Form list of modules (components) to find
# ==============================================================
if(NOT OpenCV_FIND_COMPONENTS)
set(OpenCV_FIND_COMPONENTS ${OpenCV_LIB_COMPONENTS})
list(REMOVE_ITEM OpenCV_FIND_COMPONENTS opencv_java)
if(GTest_FOUND OR GTEST_FOUND)
list(REMOVE_ITEM OpenCV_FIND_COMPONENTS opencv_ts)
endif()
endif()

set(OpenCV_WORLD_COMPONENTS )

# expand short module names and see if requested components exist
foreach(__cvcomponent ${OpenCV_FIND_COMPONENTS})
# Store the name of the original component so we can set the
# OpenCV_<component>_FOUND variable which can be checked by the user.
set (__original_cvcomponent ${__cvcomponent})
if(NOT __cvcomponent MATCHES "^opencv_")
set(__cvcomponent opencv_${__cvcomponent})
endif()
list(FIND OpenCV_LIB_COMPONENTS ${__cvcomponent} __cvcomponentIdx)
if(__cvcomponentIdx LESS 0)
if(_OpenCV_HANDLE_COMPONENTS_MANUALLY)
# Either the component is required or the user did not set any components at
# all. In the latter case, the OpenCV_FIND_REQUIRED_<component> variable
# will not be defined since it is not set by this config. So let's assume
# the implicitly set components are always required.
if(NOT DEFINED OpenCV_FIND_REQUIRED_${__original_cvcomponent} OR
OpenCV_FIND_REQUIRED_${__original_cvcomponent})
message(FATAL_ERROR "${__cvcomponent} is required but was not found")
elseif(NOT OpenCV_FIND_QUIETLY)
# The component was marked as optional using OPTIONAL_COMPONENTS
message(WARNING "Optional component ${__cvcomponent} was not found")
endif()
endif(_OpenCV_HANDLE_COMPONENTS_MANUALLY)
#indicate that module is NOT found
string(TOUPPER "${__cvcomponent}" __cvcomponentUP)
set(${__cvcomponentUP}_FOUND "${__cvcomponentUP}_FOUND-NOTFOUND")
set(OpenCV_${__original_cvcomponent}_FOUND FALSE)
else()
# Not using list(APPEND) here, because OpenCV_LIBS may not exist yet.
# Also not clearing OpenCV_LIBS anywhere, so that multiple calls
# to find_package(OpenCV) with different component lists add up.
set(OpenCV_LIBS ${OpenCV_LIBS} "${__cvcomponent}")
#indicate that module is found
string(TOUPPER "${__cvcomponent}" __cvcomponentUP)
set(${__cvcomponentUP}_FOUND 1)
set(OpenCV_${__original_cvcomponent}_FOUND TRUE)
endif()
if(OpenCV_SHARED AND ";${OpenCV_WORLD_COMPONENTS};" MATCHES ";${__cvcomponent};" AND NOT TARGET ${__cvcomponent})
get_target_property(__implib_dbg opencv_world IMPORTED_IMPLIB_DEBUG)
get_target_property(__implib_release opencv_world IMPORTED_IMPLIB_RELEASE)
get_target_property(__location_dbg opencv_world IMPORTED_LOCATION_DEBUG)
get_target_property(__location_release opencv_world IMPORTED_LOCATION_RELEASE)
get_target_property(__include_dir opencv_world INTERFACE_INCLUDE_DIRECTORIES)
add_library(${__cvcomponent} SHARED IMPORTED)
set_target_properties(${__cvcomponent} PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${__include_dir}")
if(__location_dbg)
set_property(TARGET ${__cvcomponent} APPEND PROPERTY IMPORTED_CONFIGURATIONS DEBUG)
set_target_properties(${__cvcomponent} PROPERTIES
IMPORTED_IMPLIB_DEBUG "${__implib_dbg}"
IMPORTED_LINK_INTERFACE_LIBRARIES_DEBUG ""
IMPORTED_LOCATION_DEBUG "${__location_dbg}"
)
endif()
if(__location_release)
set_property(TARGET ${__cvcomponent} APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE)
set_target_properties(${__cvcomponent} PROPERTIES
IMPORTED_IMPLIB_RELEASE "${__implib_release}"
IMPORTED_LINK_INTERFACE_LIBRARIES_RELEASE ""
IMPORTED_LOCATION_RELEASE "${__location_release}"
)
endif()
endif()
if(TARGET ${__cvcomponent})
ocv_map_imported_config(${__cvcomponent})
endif()
endforeach()

if(__remap_warnings AND NOT OpenCV_FIND_QUIETLY)
message("OpenCV: configurations remap warnings:\n${__remap_warnings}OpenCV: Check variable OPENCV_MAP_IMPORTED_CONFIG=${OPENCV_MAP_IMPORTED_CONFIG}")
endif()

# find_package(OpenCV 4 REQUIRED PATHS ${OpenCV_DIR_LOCAL})
set(OpenCV_LIBRARIES ${OpenCV_LIBS})

2 changes: 1 addition & 1 deletion debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ Depends: ${misc:Depends}
ros-${ros-distro}-rosnode, ros-${ros-distro}-rosout, ros-${ros-distro}-rosparam,
ros-${ros-distro}-rosservice, ros-${ros-distro}-rostopic, ros-${ros-distro}-roswtf,
ros-${ros-distro}-std-srvs, ros-${ros-distro}-topic-tools, ros-${ros-distro}-xmlrpcpp,
ros-kinetic-opencv3 | libopencv3.3.1,
libopencv-core, libopencv-calib3d, libopencv-highgui, libopencv-imgcodecs, libopencv-imgproc, libopencv-features2d, libopencv-xfeatures2d,
libjsoncpp1, libprotoc9v5 | libprotoc17, libgoogle-glog0v5,
libtinyxml2.6.2v5, libyaml-cpp0.5v5 | libyaml-cpp0.6
Description: Astrobee flight software.
Expand Down
3 changes: 1 addition & 2 deletions hardware/is_camera/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ find_package_handle_standard_args(V4L2 DEFAULT_MSG


# Find OpenCV
LIST(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/../../cmake")
find_package(OpenCV331 REQUIRED)
find_package(OpenCV 4.0 REQUIRED)

catkin_package(
LIBRARIES is_camera
Expand Down
3 changes: 1 addition & 2 deletions localization/camera/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ find_package(Boost REQUIRED COMPONENTS system)
find_package(Eigen3 REQUIRED)

# Find OpenCV
LIST(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/../../cmake")
find_package(OpenCV331 REQUIRED)
find_package(OpenCV 4.0 REQUIRED)



Expand Down
5 changes: 2 additions & 3 deletions localization/depth_odometry/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,8 @@ find_package(catkin2 REQUIRED COMPONENTS
vision_common
)

# Find OpenCV3
LIST(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/../../cmake")
find_package(OpenCV331 REQUIRED)
# Find OpenCV
find_package(OpenCV 4.0 REQUIRED)

find_package(Eigen3 REQUIRED)

Expand Down
3 changes: 1 addition & 2 deletions localization/graph_localizer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ find_package(catkin2 REQUIRED COMPONENTS
)

# Find OpenCV
LIST(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/../../cmake")
find_package(OpenCV331 REQUIRED)
find_package(OpenCV 4.0 REQUIRED)

catkin_package(
LIBRARIES ${PROJECT_NAME} ${GLOG_LIBRARIES} ${GTSAM_LIBRARIES}
Expand Down
4 changes: 2 additions & 2 deletions localization/handrail_detect/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ find_package(catkin2 REQUIRED COMPONENTS
ff_util
)

# Find OpenCV3
find_package(OpenCV 3.3.1 REQUIRED)
# Find OpenCV
find_package(OpenCV 4.0 REQUIRED)

catkin_package(
LIBRARIES ${PROJECT_NAME}
Expand Down
4 changes: 2 additions & 2 deletions localization/interest_point/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ find_package(OpenMVG QUIET REQUIRED)

# Find OpenCV
LIST(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/../../cmake")
find_package(OpenCV331 REQUIRED)
find_package(OpenCV4WithXFeatures REQUIRED)

catkin_package(
INCLUDE_DIRS include
Expand Down Expand Up @@ -94,4 +94,4 @@ install(DIRECTORY include/${PROJECT_NAME}/
DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}
FILES_MATCHING PATTERN "*.h"
PATTERN ".svn" EXCLUDE
)
)
6 changes: 3 additions & 3 deletions localization/interest_point/test/test_matching.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ class MatchingTest : public ::testing::Test {
// that is not where the test imagery is located.
std::string data_dir = std::string(std::getenv("DATA_DIR"));
image1 = cv::imread(data_dir + "/m0004000.jpg",
CV_LOAD_IMAGE_GRAYSCALE);
cv::IMREAD_GRAYSCALE);
image2 = cv::imread(data_dir + "/m0004025.jpg",
CV_LOAD_IMAGE_GRAYSCALE);
cv::IMREAD_GRAYSCALE);

// Decimate the image to speed things up for our unit tests
cv::resize(image1, image1, cv::Size(), 0.7, 0.7, cv::INTER_AREA);
Expand All @@ -62,7 +62,7 @@ TEST_F(MatchingTest, SURF) {
EXPECT_NEAR(keypoints2.size(), 2047u, 10);
EXPECT_EQ(descriptor1.cols, 64);
// KNN matching seems to be variable
EXPECT_NEAR(matches.size(), 798u, 10);
EXPECT_NEAR(matches.size(), 800u, 10);
}

TEST_F(MatchingTest, ORGBRISK) {
Expand Down
3 changes: 1 addition & 2 deletions localization/localization_measurements/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ find_package(PCL REQUIRED COMPONENTS common features filters octree search)
find_package(pcl_conversions REQUIRED)

# Find OpenCV
LIST(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/../../cmake")
find_package(OpenCV331 REQUIRED)
find_package(OpenCV 4.0 REQUIRED)

# System dependencies are found with CMake's conventions
find_package(Eigen3 REQUIRED)
Expand Down
3 changes: 1 addition & 2 deletions localization/localization_node/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ find_package(OpenMVG QUIET REQUIRED)
find_package(Eigen3 REQUIRED)

# Find OpenCV
LIST(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/../../cmake")
find_package(OpenCV331 REQUIRED)
find_package(OpenCV 4.0 REQUIRED)

catkin_package(
INCLUDE_DIRS include
Expand Down
14 changes: 6 additions & 8 deletions localization/marker_tracking/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,20 @@ find_package(catkin2 REQUIRED COMPONENTS
camera
nodelet
msg_conversions
ar_track_alvar
)

# System dependencies are found with CMake's conventions
find_package(cmake_modules REQUIRED)
find_package(Eigen3 REQUIRED)
find_package(Alvar REQUIRED)
find_package(Alvar REQUIRED)

find_package(PCL REQUIRED COMPONENTS common)

# Find OpenCV
LIST(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/../../cmake")
find_package(OpenCV331 REQUIRED)
find_package(OpenCV 4.0 REQUIRED)

catkin_package(
LIBRARIES ${PROJECT_NAME}
CATKIN_DEPENDS roscpp ff_util message_runtime std_msgs geometry_msgs cv_bridge image_transport camera msg_conversions nodelet
CATKIN_DEPENDS roscpp ff_util message_runtime std_msgs geometry_msgs cv_bridge image_transport camera msg_conversions nodelet ar_track_alvar
)

###########
Expand All @@ -59,9 +57,9 @@ catkin_package(
include_directories(
include
${catkin_INCLUDE_DIRS}
${ALVAR_INCLUDE_DIRS}
${EIGEN3_INCLUDE_DIRS}
${OpenCV_INCLUDE_DIRS}
${PCL_INCLUDE_DIRS}
)

# Declare C++ libraries
Expand All @@ -72,7 +70,7 @@ add_library(marker_tracking
src/marker_tracking/marker_detector.cc
)
add_dependencies(marker_tracking ${catkin_EXPORTED_TARGETS})
target_link_libraries(marker_tracking ${catkin_LIBRARIES} ${ALVAR_LIBRARIES})
target_link_libraries(marker_tracking ${catkin_LIBRARIES})

## Declare a C++ executable: generate_ar_target
add_executable(generate_ar_target tools/marker_tracking/generate_ar_target.cc)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
#include <camera/camera_params.h>

#include <opencv2/core/core_c.h>
#include <alvar/Alvar.h>
#include <alvar/Util.h>
#include <ar_track_alvar/Alvar.h>
#include <ar_track_alvar/Util.h>

#include <vector>

Expand All @@ -47,7 +47,7 @@ class ALVAR_EXPORT Labeling {
/**
* \brief Pointer to binary image that is then labeled.
*/
IplImage *bw_;
std::shared_ptr<cv::Mat> bw_;

camera::CameraParameters cam_;
int thresh_param1_, thresh_param2_;
Expand All @@ -69,9 +69,9 @@ class ALVAR_EXPORT Labeling {
/**
* \brief Labels image and filters blobs to obtain square-shaped objects from the scene.
*/
virtual void LabelSquares(IplImage* image) = 0;
virtual void LabelSquares(std::shared_ptr<cv::Mat> image) = 0;

bool CheckBorder(CvSeq* contour, int width, int height);
bool CheckBorder(std::vector<cv::Point> contour, int width, int height);

void SetThreshParams(int param1, int param2);

Expand All @@ -87,13 +87,12 @@ class ALVAR_EXPORT LabelingCvSeq : public Labeling {
int n_blobs_;
int min_edge_;
int min_area_;
CvMemStorage* storage_;

public:
explicit LabelingCvSeq(camera::CameraParameters const& cam);
virtual ~LabelingCvSeq();

void LabelSquares(IplImage* image);
void LabelSquares(std::shared_ptr<cv::Mat> image);
};

} // namespace marker_tracking
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
#include <Eigen/Core>

#include <opencv2/core/core_c.h> // I don't need all of OpenCV
#include <alvar/Marker.h>
#include <ar_track_alvar/Marker.h>

#include <vector>

Expand All @@ -54,7 +54,7 @@ namespace marker_tracking {
explicit MarkerCornerDetector(camera::CameraParameters const& camera);
~MarkerCornerDetector();

void Detect(IplImage *image,
void Detect(std::shared_ptr<cv::Mat> image,
float max_new_marker_error,
float max_track_error);

Expand Down
2 changes: 2 additions & 0 deletions localization/marker_tracking/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
<build_depend>nodelet</build_depend>
<build_depend>camera</build_depend>
<build_depend>msg_conversions</build_depend>
<build_depend>ar_track_alvar</build_depend>
<run_depend>roscpp</run_depend>
<run_depend>ff_util</run_depend>
<run_depend>message_runtime</run_depend>
Expand All @@ -38,6 +39,7 @@
<run_depend>nodelet</run_depend>
<run_depend>camera</run_depend>
<run_depend>msg_conversions</run_depend>
<run_depend>ar_track_alvar</run_depend>
<export>
<nodelet plugin="${prefix}/nodelet_plugins.xml" />
</export>
Expand Down
Loading

0 comments on commit 9964356

Please sign in to comment.