Skip to content

Commit

Permalink
feature/more-code-analysis-tools (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
BAILOOL authored May 9, 2022
1 parent 7d1de8b commit 8dc1d1e
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 32 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ compile_commands.json
CTestTestfile.cmake
_deps
build
Release
Debug

###################################

Expand Down
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ project(MC-Calib)

add_definitions(-std=c++14)
set(CMAKE_CXX_FLAGS "-std=c++14") # required for Ceres https://github.com/colmap/colmap/issues/905#issuecomment-731138700
set(CMAKE_BUILD_TYPE Release)
set(DCMAKE_BUILD_TYPE Release)
set(CMAKE_CONFIGURATION_TYPES ${CMAKE_BUILD_TYPE} CACHE STRING "" FORCE)

find_package(OpenCV REQUIRED)
Expand All @@ -28,10 +26,12 @@ if(NOT TARGET Boost::filesystem)
INTERFACE_LINK_LIBRARIES ${Boost_LIBRARIES})
endif()


set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse3")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")

# sanitizers https://www.jetbrains.com/help/clion/google-sanitizers.html#Configuration
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fsanitize=address,leak")

include_directories(
include
/usr/include/opencv
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ Then the following should do the job of compiling the code:
```bash
mkdir build
cd build
cmake ..
cmake -DCMAKE_BUILD_TYPE=Release ..
make -j10
```

Expand Down
36 changes: 27 additions & 9 deletions docs/contributing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,31 @@ Extract that and place (or symlink) Blender_Images folder under MC-Calib/data/.
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Debug ..
./tests/boost_tests_run
6. Perform valgrind test and fix introduced memory leaks:
6. Run static analysis tools and fix introduced dangerous code constructs:

.. code-block:: bash
cd build
apt install cppcheck
cppcheck ../src
# known errors:
logger.h:19:1: error: There is an unknown macro here somewhere. Configuration is required. If BOOST_LOG_GLOBAL_LOGGER is a macro then please configure it. [unknownMacro] BOOST_LOG_GLOBAL_LOGGER(logger, boost::log::sources::severity_logger_mt<boost::log::trivial::severity_level>)
##############
apt install clang-tidy
cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_BUILD_TYPE=Debug ..
run-clang-tidy
7. Perform valgrind test and fix introduced memory leaks:

.. code-block:: bash
apt update
apt install valgrind
valgrind --leak-check=full \
Expand All @@ -57,14 +75,14 @@ Extract that and place (or symlink) Blender_Images folder under MC-Calib/data/.
./calibrate ../tests/configs_for_end2end_tests/calib_param_synth_Scenario1.yml
# current state of this repository:
==1204== LEAK SUMMARY:
==1204== definitely lost: 0 bytes in 0 blocks
==1204== indirectly lost: 0 bytes in 0 blocks
==1204== possibly lost: 0 bytes in 0 blocks
==1204== still reachable: 0 bytes in 0 blocks
==1204== suppressed: 419,953 bytes in 3,712 blocks
7. Create pull request.
==6274== LEAK SUMMARY:
==6274== definitely lost: 0 bytes in 0 blocks
==6274== indirectly lost: 0 bytes in 0 blocks
==6274== possibly lost: 0 bytes in 0 blocks
==6274== still reachable: 0 bytes in 0 blocks
==6274== suppressed: 420,593 bytes in 3,714 blocks
8. Create pull request.


Naming convention:
Expand Down
6 changes: 1 addition & 5 deletions src/Calibration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ void Calibration::computeReproErrAllBoard() {
std::vector<float> err_vec;
float sum_err = 0;
for (const auto &it : board_observations_) {
float err = it.second->computeReprojectionError();
std::ignore = it.second->computeReprojectionError();
}
}

Expand Down Expand Up @@ -978,14 +978,10 @@ void Calibration::initCameraGroupObs(const int camera_group_idx) {
auto obj_obs_ptr = it_obj_obs.second.lock();
if (obj_obs_ptr) {
int current_cam_id = obj_obs_ptr->camera_id_;
int current_obj_id = obj_obs_ptr->object_3d_id_;

// Check if this camera id belongs to the group
if (std::find(cam_in_group.begin(), cam_in_group.end(),
current_cam_id) != cam_in_group.end()) {
// if (count(cam_in_group.begin(), cam_in_group.end(),
// current_cam_id))
// {
// the camera is in the group so this object is visible in the cam
// group udpate the observation
new_cam_group_obs->insertObjectObservation(obj_obs_ptr);
Expand Down
20 changes: 15 additions & 5 deletions src/OptimizationCeres.h
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,9 @@ struct ReprojectionError_CameraGroupRef {

// 2. Refine the camera if it is not the referential
if (refine_camera != 0) {
ceres::AngleAxisRotatePoint(camera, pobj, pobj);
T pobj_refine[3];
ceres::AngleAxisRotatePoint(camera, pobj, pobj_refine);
std::copy_n(pobj_refine, 3, pobj);
pobj[0] += camera[3];
pobj[1] += camera[4];
pobj[2] += camera[5];
Expand Down Expand Up @@ -398,7 +400,9 @@ struct ReprojectionError_CameraGroupAndObjectRef {
// 1. Apply the board transformation in teh object
T point[3] = {T(x), T(y), T(z)};
if (refine_board != 0) {
ceres::AngleAxisRotatePoint(board_pose, point, point);
T point_refine[3];
ceres::AngleAxisRotatePoint(board_pose, point, point_refine);
std::copy_n(point_refine, 3, point);
point[0] += board_pose[3];
point[1] += board_pose[4];
point[2] += board_pose[5];
Expand All @@ -414,7 +418,9 @@ struct ReprojectionError_CameraGroupAndObjectRef {

// 3. Refine the camera if it is not the referential
if (refine_camera != 0) {
ceres::AngleAxisRotatePoint(camera, pobj, pobj);
T pobj_refine[3];
ceres::AngleAxisRotatePoint(camera, pobj, pobj_refine);
std::copy_n(pobj_refine, 3, pobj);
pobj[0] += camera[3];
pobj[1] += camera[4];
pobj[2] += camera[5];
Expand Down Expand Up @@ -545,7 +551,9 @@ struct ReprojectionError_CameraGroupAndObjectRefAndIntrinsics {
// 1. Apply the board transformation in teh object
T point[3] = {T(x), T(y), T(z)};
if (refine_board != 0) {
ceres::AngleAxisRotatePoint(board_pose, point, point);
T point_refine[3];
ceres::AngleAxisRotatePoint(board_pose, point, point_refine);
std::copy_n(point_refine, 3, point);
point[0] += board_pose[3];
point[1] += board_pose[4];
point[2] += board_pose[5];
Expand All @@ -561,7 +569,9 @@ struct ReprojectionError_CameraGroupAndObjectRefAndIntrinsics {

// 3. Refine the camera if it is not the referential
if (refine_camera != 0) {
ceres::AngleAxisRotatePoint(camera, pobj, pobj);
T pobj_refine[3];
ceres::AngleAxisRotatePoint(camera, pobj, pobj_refine);
std::copy_n(pobj_refine, 3, pobj);
pobj[0] += camera[3];
pobj[1] += camera[4];
pobj[2] += camera[5];
Expand Down
4 changes: 2 additions & 2 deletions src/geometrytools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ cv::Mat ransacP3P(const std::vector<cv::Point3f> &scenePoints,
countit++;
}

if (refine == true & (BestInNb >= 4)) {
if (refine == true && BestInNb >= 4) {
std::vector<cv::Point3f> scenePointsInliers(BestInNb);
std::vector<cv::Point2f> imagePointsInliers(BestInNb);

Expand Down Expand Up @@ -419,7 +419,7 @@ cv::Mat handeyeBootstratpTranslationCalibration(
cv::Mat labels;
cv::Mat centers;
int nb_kmean_iterations = 5;
double compactness =
std::ignore =
cv::kmeans(position_1_2, nb_cluster, labels,
cv::TermCriteria(
cv::TermCriteria::EPS + cv::TermCriteria::COUNT, 10, 0.01),
Expand Down
14 changes: 7 additions & 7 deletions src/logger.h
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ BOOST_LOG_GLOBAL_LOGGER(logger, boost::log::sources::severity_logger_mt<
boost::log::trivial::severity_level>)

// just a helper macro used by the macros below - don't use it in your code
#define LOG(severity) \
#define LOG_AT_SEVERITY(severity) \
BOOST_LOG_SEV(logger::get(), boost::log::trivial::severity)

// ===== log macros =====
#define LOG_TRACE LOG(trace)
#define LOG_DEBUG LOG(debug)
#define LOG_INFO LOG(info)
#define LOG_WARNING LOG(warning)
#define LOG_ERROR LOG(error)
#define LOG_FATAL LOG(fatal)
#define LOG_TRACE LOG_AT_SEVERITY(trace)
#define LOG_DEBUG LOG_AT_SEVERITY(debug)
#define LOG_INFO LOG_AT_SEVERITY(info)
#define LOG_WARNING LOG_AT_SEVERITY(warning)
#define LOG_ERROR LOG_AT_SEVERITY(error)
#define LOG_FATAL LOG_AT_SEVERITY(fatal)

#endif

0 comments on commit 8dc1d1e

Please sign in to comment.