diff --git a/cv-node/README.md b/cv-node/README.md index 5e024ad8f0d2e4bd187528e33ff4b1a15e3aa234..309950751026663a24e0139d5731475b7e20299d 100644 --- a/cv-node/README.md +++ b/cv-node/README.md @@ -14,7 +14,8 @@ make ` ## Install -TODO. Currently, copy `<source_direction>/config/config.json` to `~/config/ftl`. +TODO. Currently, copy `<source_direction>/config/config.json` to +`~/.config/ftl/config.json` on Linux. ## Usage An optional command-line argument can be passed to specify a stereo video file @@ -30,7 +31,9 @@ JSON config option at `{ "disparity": { "algorithm": "sgbm" }}`. ### Calibration Cameras can be calibrated by using argument `--calibrate`. You either need to provide a calibration video as an argument or do it live. A checkerboard -grid pattern is required, the size can be configured in the json file. +grid pattern is required, the size can be configured in the json file. After +callibration the data is save and will be reloaded automatically next time you +run `cv-node`. Note: best calibration is not too close or far from the cameras, the board must be fully visible in each camera and move to cover as much of the visual field diff --git a/cv-node/config/config.json b/cv-node/config/config.json index f14b58abd4e80de53243bf15c71e8780e38a273d..a634c12ff4b77010ad380e4a322c77d8a7b10317 100644 --- a/cv-node/config/config.json +++ b/cv-node/config/config.json @@ -8,8 +8,8 @@ "calibration": { "board_size": [9,6], "square_size": 50, - "frame_delay": 100, - "num_frames": 25, + "frame_delay": 1.0, + "num_frames": 35, "assume_zero_tangential_distortion": true, "fix_aspect_ratio": true, "fix_principal_point_at_center": true, @@ -33,7 +33,7 @@ "disparity": { "algorithm": "rtcensus", "use_cuda": true, - "minimum": 10, + "minimum": 0, "maximum": 208, "tau": 0.0, "gamma": 0.0, diff --git a/cv-node/include/ftl/calibrate.hpp b/cv-node/include/ftl/calibrate.hpp index 2539864f0b2a6a87c6a9601b3b1d6585be3d14fc..99d6908473f3ddb4e18c14473e8290819622a329 100644 --- a/cv-node/include/ftl/calibrate.hpp +++ b/cv-node/include/ftl/calibrate.hpp @@ -35,7 +35,7 @@ class Calibrate { float squareSize; // The size of a square in your defined unit (point, millimeter,etc). int nrFrames; // The number of frames to use from the input for calibration float aspectRatio; // The aspect ratio - int delay; // In case of a video input + float delay; // In case of a video input bool writePoints; // Write detected feature points bool writeExtrinsics; // Write extrinsic parameters bool writeGrid; // Write refined 3D target grid points diff --git a/cv-node/src/algorithms/rtcensus.cu b/cv-node/src/algorithms/rtcensus.cu index 63f940018428ed4b0645f276b9a5026cf1ee4113..cb2010b7f4ca7945e1e7174dcf8fd7ab6c276372 100644 --- a/cv-node/src/algorithms/rtcensus.cu +++ b/cv-node/src/algorithms/rtcensus.cu @@ -26,29 +26,43 @@ using namespace cv; namespace ftl { namespace gpu { +// --- SUPPORT ----------------------------------------------------------------- + +/* + * Sparse 16x16 census (so 8x8) creating a 64bit mask + * (14) & (15), based upon (9) + */ __device__ uint64_t sparse_census(unsigned char *arr, size_t u, size_t v, size_t w) { uint64_t r = 0; unsigned char t = arr[v*w+u]; - for (int n=-7; n<=7; n+=2) { - auto u_ = u + n; for (int m=-7; m<=7; m+=2) { - auto v_ = v + m; - r <<= 1; - r |= XHI(t, arr[v_*w+u_]); - } + auto start_ix = (v + m)*w + u; + for (int n=-7; n<=7; n+=2) { + r <<= 1; + r |= XHI(t, arr[start_ix+n]); + } } return r; } +/* + * Parabolic interpolation between matched disparities either side. + * Results in subpixel disparity. (20). + */ __device__ float fit_parabola(size_t pi, uint16_t p, uint16_t pl, uint16_t pr) { float a = pr - pl; float b = 2 * (2 * p - pl - pr); return static_cast<float>(pi) + (a / b); } +// --- KERNELS ----------------------------------------------------------------- + +/* + * Calculate census mask for left and right images together. + */ __global__ void census_kernel(PtrStepSzb l, PtrStepSzb r, uint64_t *census) { //extern __shared__ uint64_t census[]; @@ -62,23 +76,18 @@ __global__ void census_kernel(PtrStepSzb l, PtrStepSzb r, uint64_t *census) { size_t width = l.cols; for (size_t v=v_start; v<v_end; v++) { - //for (size_t u=7; u<width-7; u++) { size_t ix = (u + v*width) * 2; uint64_t cenL = sparse_census(l.data, u, v, l.step); uint64_t cenR = sparse_census(r.data, u, v, r.step); census[ix] = cenL; census[ix + 1] = cenR; - - //disp(v,u) = (float)cenL; - //} } - - //__syncthreads(); - - return; } - + +/* + * Generate left and right disparity images from census data. (19) + */ __global__ void disp_kernel(float *disp_l, float *disp_r, size_t width, size_t height, uint64_t *census, size_t ds) { //extern __shared__ uint64_t cache[]; diff --git a/cv-node/src/calibrate.cpp b/cv-node/src/calibrate.cpp index c4e07f071bc334a724fe775777500751a758d17d..403ad8f9ed531e154bb43fa60f87575db41ab29c 100644 --- a/cv-node/src/calibrate.cpp +++ b/cv-node/src/calibrate.cpp @@ -409,7 +409,7 @@ bool Calibrate::_recalibrate(vector<vector<Point2f>> *imagePoints, found1 = findChessboardCorners( view[0], settings_.boardSize, pointBuf[0], chessBoardFlags); found2 = !local_->isStereo() || findChessboardCorners( view[1], settings_.boardSize, pointBuf[1], chessBoardFlags); - if (found1 && found2 && local_->getTimestamp()-prevTimestamp > 0.5) // If done with success, + if (found1 && found2 && local_->getTimestamp()-prevTimestamp > settings_.delay) // If done with success, { prevTimestamp = local_->getTimestamp(); // improve the found corners' coordinate accuracy for chessboard