Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

modified for C++17 and OpenCV4 compatibility #31

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ tested with version 1.3.0. which is included in /thirdparty.



#### 5. Dataset Description:
The dataset used is [TUM dataset](https://vision.in.tum.de/data/datasets/mono-dataset). For photometric calibration, it contains `images.zip`, `pcalib.txt`, `times.txt` and `camera.txt` files.
- `camera.txt` contains camera parameters (as per the camera model) normalized to the video frame dimensions.
- `pcalib.txt` is the output of gamma calibration and contains inverse irradiance values [0, 255].
- `times.txt` contains 3 columns: `video_frame_number`, `video_frame_timestamp` (absolute/relative time), exposure_values (1/f). For `exposure_values` TUM_dataset has used sensors but one can use another workaround; capture a static scene without camera motion through various discrete exposure values and
set the exposure values in the `times.txt` `exposure_values` column (generated the files and tested in custom dataset).

**NOTE:** Gamma calibration requires `times.txt`, `camera.txt` and `images.zip` and outputs `pcalib.txt`
while Vignette calibration requires `camera.txt`, `images.zip` and `pcalib.txt` and outputs `vignette.png`


# Usage: C++ code
Expand Down
5 changes: 2 additions & 3 deletions src/BenchmarkDatasetReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ class DatasetReader
if(!isZipped)
{
// CHANGE FOR ZIP FILE
return cv::imread(files[id],CV_LOAD_IMAGE_GRAYSCALE);
return cv::imread(files[id],cv::IMREAD_GRAYSCALE);
}
else
{
Expand All @@ -271,7 +271,7 @@ class DatasetReader
exit(1);
}
}
return cv::imdecode(cv::Mat(readbytes,1,CV_8U, databuffer), CV_LOAD_IMAGE_GRAYSCALE);
return cv::imdecode(cv::Mat(readbytes,1,CV_8U, databuffer),cv::IMREAD_GRAYSCALE);
}
}

Expand Down Expand Up @@ -343,4 +343,3 @@ class DatasetReader

float* internalTempBuffer;
};

5 changes: 1 addition & 4 deletions src/PhotometricUndistorter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ PhotometricUndistorter::PhotometricUndistorter(


printf("Reading Vignette Image from %s\n",vignetteImage.c_str());
cv::Mat vignetteMat = cv::imread(vignetteImage.c_str(), CV_LOAD_IMAGE_UNCHANGED);
cv::Mat vignetteMat = cv::imread(vignetteImage.c_str(), cv::IMREAD_UNCHANGED);
vignetteMap = new float[w*h];
vignetteMapInv = new float[w*h];
if(vignetteMat.rows != h || vignetteMat.cols != w)
Expand Down Expand Up @@ -210,6 +210,3 @@ void PhotometricUndistorter::unMapImage(
for(int i=0;i<n;i++) if(image_in[i]==255) image_out[i]=NAN;
}
}



32 changes: 30 additions & 2 deletions src/main_responseCalib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,23 @@ int leakPadding=2;
int nits = 10;
int skipFrames = 1;


void swap(double* xp, double* yp)
{
double temp = *xp;
*xp = *yp;
*yp = temp;
}

void bubbleSort(double arr[])
{
int i, j;
for (i = 0; i < 255; i++)

// Last i elements are already in place
for (j = 0; j < 255 - i; j++)
if (arr[j] > arr[j + 1])
swap(&arr[j], &arr[j + 1]);
}

Eigen::Vector2d rmse(double* G, double* E, std::vector<double> &exposureVec, std::vector<unsigned char*> &dataVec, int wh)
{
Expand Down Expand Up @@ -345,9 +361,21 @@ int main( int argc, char** argv )
plotE(E,w,h, buf);
}

double max_G = 0;
for(int i = 0; i < 256; i++)
{
if(max_G < G[i])
{
max_G = G[i];
}
}
std::cout << " Max G = " << max_G << std::endl;

bubbleSort(G);

// rescale such that maximum response is 255 (fairly arbitrary choice).
double rescaleFactor=255.0 / G[255];
// double rescaleFactor=255.0 / G[255];
double rescaleFactor=255.0 / max_G;
for(int i=0;i<w*h;i++)
{
E[i] *= rescaleFactor;
Expand Down
20 changes: 15 additions & 5 deletions src/main_vignetteCalib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,14 @@
#include "BenchmarkDatasetReader.h"
#include "Eigen/Core"
#include "Eigen/LU"
#include "opencv2/core/eigen.hpp"

#include <sstream>
#include <fstream>
#include <dirent.h>
#include <algorithm>
#include<iostream>
#include<string>


// reads interpolated element from a uchar* array
Expand Down Expand Up @@ -187,7 +190,6 @@ int main( int argc, char** argv )
{
for(int i=2; i<argc;i++)
parseArgument(argv[i]);

if(-1 == system("rm -rf vignetteCalibResult")) printf("could not delete old vignetteCalibResult folder!\n");
if(-1 == system("mkdir vignetteCalibResult")) printf("could not delete old vignetteCalibResult folder!\n");

Expand All @@ -205,11 +207,19 @@ int main( int argc, char** argv )
printf("SEQUENCE NAME: %s!\n", argv[1]);

int w_out, h_out;
//Eigen::Matrix3f K = reader->getUndistorter()->getK_rect();
w_out = reader->getUndistorter()->getOutputDims()[0];
h_out = reader->getUndistorter()->getOutputDims()[1];

aruco::MarkerDetector MDetector;
std::string path = argv[1];
UndistorterFOV* undistorter = new UndistorterFOV((path+"camera.txt").c_str());
// Eigen::Matrix3f Krect = undistorter->getK_rect();
// float Omega = undistorter->getOmega();

cv::Mat camMatrix;
cv::Mat_<float> distCoeff(4, 1);
cv::eigen2cv(undistorter->getK_rect(), camMatrix);
distCoeff<< undistorter->getOmega(), 0, 0, 0;

std::vector<float*> images;
std::vector<float*> p2imgX;
Expand All @@ -236,7 +246,7 @@ int main( int argc, char** argv )
cv::Mat(h_out, w_out, CV_32F, img->image).convertTo(InImage, CV_8U, 1, 0);
delete img;

MDetector.detect(InImage,Markers);
MDetector.detect(InImage,Markers, camMatrix, distCoeff);
if(Markers.size() != 1) continue;

std::vector<cv::Point2f> ptsP;
Expand Down Expand Up @@ -321,7 +331,7 @@ int main( int argc, char** argv )
int v_dT = plane2imgY[idxT]+0.5;

if(u_dS>=0 && v_dS >=0 && u_dS<wI && v_dS<hI && u_dT>=0 && v_dT >=0 && u_dT<wI && v_dT<hI)
cv::line(dbgImg, cv::Point(u_dS, v_dS), cv::Point(u_dT, v_dT), cv::Scalar(0,0,255), 10, CV_AA);
cv::line(dbgImg, cv::Point(u_dS, v_dS), cv::Point(u_dT, v_dT), cv::Scalar(0,0,255), 10, cv::LINE_AA);
}


Expand All @@ -338,7 +348,7 @@ int main( int argc, char** argv )
int v_dT = plane2imgY[idxT]+0.5;

if(u_dS>=0 && v_dS >=0 && u_dS<wI && v_dS<hI && u_dT>=0 && v_dT >=0 && u_dT<wI && v_dT<hI)
cv::line(dbgImg, cv::Point(u_dS, v_dS), cv::Point(u_dT, v_dT), cv::Scalar(0,0,255), 10, CV_AA);
cv::line(dbgImg, cv::Point(u_dS, v_dS), cv::Point(u_dT, v_dT), cv::Scalar(0,0,255), 10, cv::LINE_AA);
}


Expand Down
Binary file added thirdparty/aruco-3.1.12.zip
Binary file not shown.
45 changes: 45 additions & 0 deletions thirdparty/aruco-3.1.12/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# ----------------------------------------------------------------------------
# Basic Configuration
# ----------------------------------------------------------------------------
cmake_minimum_required(VERSION 3.0)
project(aruco VERSION "3.1.12" LANGUAGES CXX)
set(PROJECT_SOVERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}")
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_CXX_STANDARD 11) # C++11...
set(CMAKE_CXX_STANDARD_REQUIRED ON) #...is required...
set(CMAKE_CXX_EXTENSIONS ON) #...with compiler extensions like gnu++11

include(cmake/options.cmake)

include(cmake/findDependencies.cmake)
include(cmake/compilerOptions.cmake)



add_subdirectory(src)

if(GL_FOUND AND BUILD_GLSAMPLES)
add_subdirectory(utils_gl)
endif()
if(BUILD_TESTS)
add_subdirectory(tests)
endif()


if(BUILD_UTILS)
add_subdirectory(utils)
add_subdirectory(utils_markermap)
add_subdirectory(utils_calibration)
add_subdirectory(utils_dcf)
IF(BUILD_SVM)
ADD_SUBDIRECTORY(utils_svm)
ENDIF()
ADD_SUBDIRECTORY(utils_fractal)
endif()
include(cmake/printInfo.cmake)
include(cmake/installOptions.cmake)

# Package Generator #######################################################
IF(BUILD_DEBPACKAGE)
include(cmake/cpack.cmake)
ENDIF()
Loading