aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFranklin Wei <franklin@rockbox.org>2019-12-13 00:33:05 -0500
committerFranklin Wei <franklin@rockbox.org>2019-12-13 00:33:05 -0500
commitd7e246e9cdc92dede602b9fd27cbb8d553cce596 (patch)
tree014625432bf432cc5af44664845cc3086181bfd9
parent24e7095d3a8bcf907393c1e48d2e337ddf8796b4 (diff)
downloadsloreg-d7e246e9cdc92dede602b9fd27cbb8d553cce596.zip
sloreg-d7e246e9cdc92dede602b9fd27cbb8d553cce596.tar.gz
sloreg-d7e246e9cdc92dede602b9fd27cbb8d553cce596.tar.bz2
sloreg-d7e246e9cdc92dede602b9fd27cbb8d553cce596.tar.xz
Initial attempt at ECC alignment
-rw-r--r--gabor.cpp63
1 files changed, 54 insertions, 9 deletions
diff --git a/gabor.cpp b/gabor.cpp
index 400257e..d50f7b5 100644
--- a/gabor.cpp
+++ b/gabor.cpp
@@ -18,15 +18,6 @@
using namespace cv;
using namespace std;
-#if 0
-Mat contrastLUT(unsigned char thresh) {
- Mat ret = Mat(256, 1, CV_8U);
- for(int i = 0; i < 255; i++)
- ret = (i < thresh) ? 0 : i;
- return ret;
-}
-#endif
-
// uncomment for headless mode -- for benchmarking
//#define imshow(a, b)
@@ -287,9 +278,28 @@ void dumpHist(int *hist) {
cout << setw(4) << i << " " << hist[i] << endl;
}
+Mat redGreenOverlay(Mat rPlane, Mat gPlane) {
+ assert(rPlane.size() == gPlane.size());
+ Mat planes[3] = { Mat::zeros(rPlane.size(), CV_8U),
+ gPlane,
+ rPlane };
+ Mat out;
+ merge(planes, 3, out);
+ return out;
+}
+
int main()
{
+ // filtering parameters
const int nfilts = 10;
+ Mat reference;
+
+ // alignment parameters
+ bool homography = false;
+ int ecc_iters = 100;
+ double ecc_eps = 1e-5;
+ int warp_mode = MOTION_AFFINE;
+
while(1)
{
// 22 frames
@@ -361,6 +371,41 @@ int main()
Mat histplot = plotHist(hist, ymax, t);
imshow("hist", histplot);
+ // try alignment
+ if(reference.empty())
+ reference = masked;
+ else
+ {
+ Mat warp_matrix;
+ if(warp_mode == MOTION_HOMOGRAPHY)
+ warp_matrix = Mat::eye(3, 3, CV_32F);
+ else
+ warp_matrix = Mat::eye(2, 3, CV_32F);
+
+ double coeff = findTransformECC(reference,
+ masked,
+ warp_matrix,
+ warp_mode,
+ TermCriteria (TermCriteria::COUNT+TermCriteria::EPS,
+ ecc_iters, ecc_eps),
+ mask);
+ Mat warped_image = Mat(reference.rows, reference.cols, CV_32FC1);
+ if (warp_mode != MOTION_HOMOGRAPHY)
+ warpAffine(masked, warped_image, warp_matrix, warped_image.size(),
+ INTER_LINEAR + WARP_INVERSE_MAP);
+ else
+ warpPerspective(masked, warped_image, warp_matrix, warped_image.size(),
+ INTER_LINEAR + WARP_INVERSE_MAP);
+
+ imshow("aligned", warped_image);
+
+ cout << "Sizes: " << warped_image.size() << ", " << reference.size() << endl;
+
+ // create red/green overlay
+ Mat overlay = redGreenOverlay(warped_image, reference);
+ imshow("overlay", overlay);
+ }
+
waitKey(0);
}
}