Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/extern
diff options
context:
space:
mode:
authorSergey Sharybin <sergey.vfx@gmail.com>2011-08-13 01:56:08 +0400
committerSergey Sharybin <sergey.vfx@gmail.com>2011-08-13 01:56:08 +0400
commit36c5f5761686c76edf03e1a89c683a7be2a8583c (patch)
tree43bdd49062912f304913f991ce06543d8ccf4b83 /extern
parentfa89789247c72c4b674919abd2c99b5057198f29 (diff)
Camera tracking integration
=========================== - Distortion/undistortion were accidentally swapped in both of grease pencil calibration and grid. This was fixed but distortion coefficients should be re-adjusted. There are some issues with high distortion coefficients but it came from libmv and until it'll be fixed there nothing really can be done here. - Fixed displayed aspect ratio for muted footage when pixel/display aspect ratio is differ from 1.0 or proxy size is not Full Render, - Added c-api for image distortion/undistortion, Not used yet.
Diffstat (limited to 'extern')
-rw-r--r--extern/libmv/ChangeLog85
-rw-r--r--extern/libmv/libmv-capi.cpp50
-rw-r--r--extern/libmv/libmv-capi.h11
-rw-r--r--extern/libmv/libmv/simple_pipeline/camera_intrinsics.cc56
-rw-r--r--extern/libmv/libmv/simple_pipeline/camera_intrinsics.h39
5 files changed, 148 insertions, 93 deletions
diff --git a/extern/libmv/ChangeLog b/extern/libmv/ChangeLog
index 8bdbe6c2154..228ae54c06a 100644
--- a/extern/libmv/ChangeLog
+++ b/extern/libmv/ChangeLog
@@ -1,3 +1,33 @@
+commit 10bdad9ad2cea2603896263cde5a5339169a9af0
+Author: Matthias Fauconneau <matthias.fauconneau@gmail.com>
+Date: Fri Aug 12 21:05:32 2011 +0200
+
+ Fix out of bound access in warp bilinear sampling.
+
+commit dd9a418db021a28af2c1198d5e5b9e68fe048a03
+Author: Matthias Fauconneau <matthias.fauconneau@gmail.com>
+Date: Fri Aug 12 19:14:36 2011 +0200
+
+ Fix compilation with -funsigned-char.
+
+commit bd1a268ede39b67f2ba4b360f6fc693419e7cd7f
+Author: Matthias Fauconneau <matthias.fauconneau@gmail.com>
+Date: Fri Aug 12 18:39:27 2011 +0200
+
+ CameraIntrinsics fixes.
+
+commit ae513b39fb779632f96ceff7c1e014fb8e68702a
+Author: Matthias Fauconneau <matthias.fauconneau@gmail.com>
+Date: Tue Aug 9 19:38:58 2011 +0200
+
+ Remove stray QDebug include.
+
+commit 1e58f55078ce6009a885be30ae0316aec6ed8239
+Author: Matthias Fauconneau <matthias.fauconneau@gmail.com>
+Date: Tue Aug 9 14:16:31 2011 +0200
+
+ Make API future-proof (for an eventual affine or planar tracker).
+
commit c2af303e7bf0dddcb02937323ac5846b1801e6cc
Author: Matthias Fauconneau <matthias.fauconneau@gmail.com>
Date: Tue Aug 9 11:13:29 2011 +0200
@@ -388,58 +418,3 @@ Date: Wed Jul 13 10:21:52 2011 +0200
Add feature detection.
Remove unused keyframe selection code.
-
-commit 1088517da70ae9ec2369752fbc17dde4bb869c47
-Author: Matthias Fauconneau <matthias.fauconneau@gmail.com>
-Date: Mon Jul 11 22:42:14 2011 +0200
-
- Replace system file dialog with custom one which supports multiple file/folder selection.
- Add Stop button when adding frame from video.
-
-commit 323af7a3a1344e7ef419c72fe22b674c17c578e3
-Author: Matthias Fauconneau <matthias.fauconneau@gmail.com>
-Date: Mon Jul 11 16:30:59 2011 +0200
-
- Add stub for feature detection.
-
-commit 739ec729fa8bc6e0ba6a40cc7b89d85e5332e900
-Author: Matthias Fauconneau <matthias.fauconneau@gmail.com>
-Date: Mon Jul 11 16:30:42 2011 +0200
-
- Fix compilation of Qt Calibration tool.
-
-commit 113ccc413db6bdfb75839418bddfba5ce3ba60f7
-Author: Matthias Fauconneau <matthias.fauconneau@gmail.com>
-Date: Mon Jul 11 12:27:47 2011 +0200
-
- Add raw on-disk video cache.
-
- This is useful for faster testing iterations.
- It avoids waiting for the footage to decode on startup.
- Using file memory mapping, we let the OS handle caching.
- The OS disk cache also has the advantage of being kept in memory between runs.
- A cache is only created for shot < 1GiB (e.g 17s of 1080@30).
-
-commit efbe8b6a3e2a8cff497726e11afffbce0ec6aa53
-Author: Matthias Fauconneau <matthias.fauconneau@gmail.com>
-Date: Mon Jul 11 11:11:47 2011 +0200
-
- Miscellaneous UI fixes, faster grayscale conversion, compute window size from pattern size and pyramid level count.
-
-commit 0c6911831b0a391da14bf1c5833b1e5c0d5056b7
-Author: Matthias Fauconneau <matthias.fauconneau@gmail.com>
-Date: Sun Jul 10 22:48:15 2011 +0200
-
- Add Video support using FFmpeg to Qt Calibration.
-
-commit c9f2bd5a17585f816bf0ef89097ac8f222ad058e
-Author: Matthias Fauconneau <matthias.fauconneau@gmail.com>
-Date: Sun Jul 10 19:44:35 2011 +0200
-
- Add Video support using FFmpeg to Qt Tracker.
-
-commit af8f9c412b0592868a0e68a14686651b45de9737
-Author: Matthias Fauconneau <matthias.fauconneau@gmail.com>
-Date: Sat Jul 9 12:08:28 2011 +0200
-
- Update README with instructions to build Qt OpenCV Calibration tool.
diff --git a/extern/libmv/libmv-capi.cpp b/extern/libmv/libmv-capi.cpp
index 8390a197cf5..0d1e381a103 100644
--- a/extern/libmv/libmv-capi.cpp
+++ b/extern/libmv/libmv-capi.cpp
@@ -501,6 +501,56 @@ void libmv_destroyCorners(struct libmv_Corners *libmv_corners)
delete (std::vector<libmv::Corner> *)libmv_corners;
}
+/* ************ distortion ************ */
+
+void libmv_undistortByte(double focal_length, double principal_x, double principal_y, double k1, double k2, double k3,
+ unsigned char *src, unsigned char *dst, int width, int height, int channels)
+{
+ libmv::CameraIntrinsics intrinsics;
+
+ intrinsics.SetFocalLength(focal_length, focal_length);
+ intrinsics.SetPrincipalPoint(principal_x, principal_y);
+ intrinsics.SetRadialDistortion(k1, k2, k3);
+
+ intrinsics.Undistort(src, dst, width, height, channels);
+}
+
+void libmv_undistortFloat(double focal_length, double principal_x, double principal_y, double k1, double k2, double k3,
+ float *src, float *dst, int width, int height, int channels)
+{
+ libmv::CameraIntrinsics intrinsics;
+
+ intrinsics.SetFocalLength(focal_length, focal_length);
+ intrinsics.SetPrincipalPoint(principal_x, principal_y);
+ intrinsics.SetRadialDistortion(k1, k2, k3);
+
+ intrinsics.Undistort(src, dst, width, height, channels);
+}
+
+void libmv_distortByte(double focal_length, double principal_x, double principal_y, double k1, double k2, double k3,
+ unsigned char *src, unsigned char *dst, int width, int height, int channels)
+{
+ libmv::CameraIntrinsics intrinsics;
+
+ intrinsics.SetFocalLength(focal_length, focal_length);
+ intrinsics.SetPrincipalPoint(principal_x, principal_y);
+ intrinsics.SetRadialDistortion(k1, k2, k3);
+
+ intrinsics.Distort(src, dst, width, height, channels);
+}
+
+void libmv_distortFloat(double focal_length, double principal_x, double principal_y, double k1, double k2, double k3,
+ float *src, float *dst, int width, int height, int channels)
+{
+ libmv::CameraIntrinsics intrinsics;
+
+ intrinsics.SetFocalLength(focal_length, focal_length);
+ intrinsics.SetPrincipalPoint(principal_x, principal_y);
+ intrinsics.SetRadialDistortion(k1, k2, k3);
+
+ intrinsics.Distort(src, dst, width, height, channels);
+}
+
/* ************ utils ************ */
void libmv_applyCameraIntrinsics(double focal_length, double principal_x, double principal_y, double k1, double k2, double k3,
diff --git a/extern/libmv/libmv-capi.h b/extern/libmv/libmv-capi.h
index cf5b5d09e30..a63cbd02083 100644
--- a/extern/libmv/libmv-capi.h
+++ b/extern/libmv/libmv-capi.h
@@ -71,6 +71,17 @@ int libmv_countCorners(struct libmv_Corners *libmv_corners);
void libmv_getCorner(struct libmv_Corners *libmv_corners, int number, double *x, double *y, double *score, double *size);
void libmv_destroyCorners(struct libmv_Corners *libmv_corners);
+/* dsitortion */
+void libmv_undistortByte(double focal_length, double principal_x, double principal_y, double k1, double k2, double k3,
+ unsigned char *src, unsigned char *dst, int width, int height, int channels);
+void libmv_undistortFloat(double focal_length, double principal_x, double principal_y, double k1, double k2, double k3,
+ float *src, float *dst, int width, int height, int channels);
+
+void libmv_distortByte(double focal_length, double principal_x, double principal_y, double k1, double k2, double k3,
+ unsigned char *src, unsigned char *dst, int width, int height, int channels);
+void libmv_distortFloat(double focal_length, double principal_x, double principal_y, double k1, double k2, double k3,
+ float *src, float *dst, int width, int height, int channels);
+
/* utils */
void libmv_applyCameraIntrinsics(double focal_length, double principal_x, double principal_y, double k1, double k2, double k3,
double x, double y, double *x1, double *y1);
diff --git a/extern/libmv/libmv/simple_pipeline/camera_intrinsics.cc b/extern/libmv/libmv/simple_pipeline/camera_intrinsics.cc
index 40a9459e03f..4e88e1f6a5d 100644
--- a/extern/libmv/libmv/simple_pipeline/camera_intrinsics.cc
+++ b/extern/libmv/libmv/simple_pipeline/camera_intrinsics.cc
@@ -23,7 +23,7 @@
namespace libmv {
-struct Offset { char ix,iy; unsigned char fx,fy; };
+struct Offset { signed char ix,iy; unsigned char fx,fy; };
CameraIntrinsics::CameraIntrinsics()
: K_(Mat3::Identity()),
@@ -42,6 +42,44 @@ CameraIntrinsics::~CameraIntrinsics() {
if(undistort_) delete[] undistort_;
}
+/// Set the entire calibration matrix at once.
+void CameraIntrinsics::SetK(const Mat3 new_k) {
+ K_ = new_k;
+ FreeLookupGrid();
+}
+
+/// Set both x and y focal length in pixels.
+void CameraIntrinsics::SetFocalLength(double focal_x, double focal_y) {
+ K_(0, 0) = focal_x;
+ K_(1, 1) = focal_y;
+ FreeLookupGrid();
+}
+
+void CameraIntrinsics::SetPrincipalPoint(double cx, double cy) {
+ K_(0, 2) = cx;
+ K_(1, 2) = cy;
+ FreeLookupGrid();
+}
+
+void CameraIntrinsics::SetImageSize(int width, int height) {
+ image_width_ = width;
+ image_height_ = height;
+ FreeLookupGrid();
+}
+
+void CameraIntrinsics::SetRadialDistortion(double k1, double k2, double k3) {
+ k1_ = k1;
+ k2_ = k2;
+ k3_ = k3;
+ FreeLookupGrid();
+}
+
+void CameraIntrinsics::SetTangentialDistortion(double p1, double p2) {
+ p1_ = p1;
+ p2_ = p2;
+ FreeLookupGrid();
+}
+
void CameraIntrinsics::ApplyIntrinsics(double normalized_x,
double normalized_y,
double *image_x,
@@ -117,18 +155,11 @@ void CameraIntrinsics::ComputeLookupGrid(Offset* grid, int width, int height) {
int fx = round((warp_x-ix)*256), fy = round((warp_y-iy)*256);
if(fx == 256) { fx=0; ix++; }
if(fy == 256) { fy=0; iy++; }
-#ifdef CLIP
// Use nearest border pixel
if( ix < 0 ) { ix = 0, fx = 0; }
if( iy < 0 ) { iy = 0, fy = 0; }
- if( ix >= width-1 ) { ix = width-1, fx = 0; }
- if( iy >= height-1 ) { iy = height-1, fy = 0; }
-#else
- // No offset: Avoid adding out of bounds to error.
- if( ix < 0 || iy < 0 || ix >= width-1 || iy >= height-1 ) {
- ix = x; iy = y; fx = fy = 0;
- }
-#endif
+ if( ix >= width-2 ) ix = width-2;
+ if( iy >= height-2 ) iy = height-2;
//assert( ix-x > -128 && ix-x < 128 && iy-y > -128 && iy-y < 128 );
Offset offset = { ix-x, iy-y, fx, fy };
grid[y*width+x] = offset;
@@ -152,6 +183,11 @@ static void Warp(const Offset* grid, const T* src, T* dst,
}
}
+void CameraIntrinsics::FreeLookupGrid() {
+ if(distort_) delete distort_, distort_=0;
+ if(undistort_) delete undistort_, undistort_=0;
+}
+
// FIXME: C++ templates limitations makes thing complicated, but maybe there is a simpler method.
struct ApplyIntrinsicsFunction {
ApplyIntrinsicsFunction(CameraIntrinsics* intrinsics, double x, double y,
diff --git a/extern/libmv/libmv/simple_pipeline/camera_intrinsics.h b/extern/libmv/libmv/simple_pipeline/camera_intrinsics.h
index 79d10b93d85..6ff40fb7232 100644
--- a/extern/libmv/libmv/simple_pipeline/camera_intrinsics.h
+++ b/extern/libmv/libmv/simple_pipeline/camera_intrinsics.h
@@ -49,36 +49,18 @@ class CameraIntrinsics {
double p2() const { return p2_; }
/// Set the entire calibration matrix at once.
- void SetK(const Mat3 new_k) {
- K_ = new_k;
- }
+ void SetK(const Mat3 new_k);
/// Set both x and y focal length in pixels.
- void SetFocalLength(double focal_x, double focal_y) {
- K_(0, 0) = focal_x;
- K_(1, 1) = focal_y;
- }
-
- void SetPrincipalPoint(double cx, double cy) {
- K_(0, 2) = cx;
- K_(1, 2) = cy;
- }
-
- void SetImageSize(int width, int height) {
- image_width_ = width;
- image_height_ = height;
- }
-
- void SetRadialDistortion(double k1, double k2, double k3 = 0) {
- k1_ = k1;
- k2_ = k2;
- k3_ = k3;
- }
-
- void SetTangentialDistortion(double p1, double p2) {
- p1_ = p1;
- p2_ = p2;
- }
+ void SetFocalLength(double focal_x, double focal_y);
+
+ void SetPrincipalPoint(double cx, double cy);
+
+ void SetImageSize(int width, int height);
+
+ void SetRadialDistortion(double k1, double k2, double k3 = 0);
+
+ void SetTangentialDistortion(double p1, double p2);
/*!
Apply camera intrinsics to the normalized point to get image coordinates.
@@ -142,6 +124,7 @@ class CameraIntrinsics {
private:
template<typename WarpFunction> void ComputeLookupGrid(Offset* grid, int width, int height);
+ void FreeLookupGrid();
// The traditional intrinsics matrix from x = K[R|t]X.
Mat3 K_;