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

overscan.patch « patches « libmv « extern - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c68f36804ec28bee6c790c864c35e64ef76e0bdb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
diff --git a/src/libmv/simple_pipeline/camera_intrinsics.cc b/src/libmv/simple_pipeline/camera_intrinsics.cc
index 110a16d..366129d 100644
--- a/src/libmv/simple_pipeline/camera_intrinsics.cc
+++ b/src/libmv/simple_pipeline/camera_intrinsics.cc
@@ -31,6 +31,7 @@ struct Offset {
 struct Grid {
   struct Offset *offset;
   int width, height;
+  double overscan;
 };
 
 static struct Grid *copyGrid(struct Grid *from)
@@ -42,6 +43,7 @@ static struct Grid *copyGrid(struct Grid *from)
 
     to->width = from->width;
     to->height = from->height;
+    to->overscan = from->overscan;
 
     to->offset = new Offset[to->width*to->height];
     memcpy(to->offset, from->offset, sizeof(struct Offset)*to->width*to->height);
@@ -184,17 +186,19 @@ void CameraIntrinsics::InvertIntrinsics(double image_x,
 
 // TODO(MatthiasF): downsample lookup
 template<typename WarpFunction>
-void CameraIntrinsics::ComputeLookupGrid(Grid* grid, int width, int height) {
-  double aspx = (double)width / image_width_;
-  double aspy = (double)height / image_height_;
+void CameraIntrinsics::ComputeLookupGrid(Grid* grid, int width, int height, double overscan) {
+  double w = (double)width / (1 + overscan);
+  double h = (double)height / (1 + overscan);
+  double aspx = (double)w / image_width_;
+  double aspy = (double)h / image_height_;
 
   for (int y = 0; y < height; y++) {
     for (int x = 0; x < width; x++) {
-      double src_x = x / aspx, src_y = y / aspy;
+      double src_x = (x - 0.5 * overscan * w) / aspx, src_y = (y - 0.5 * overscan * h) / aspy;
       double warp_x, warp_y;
       WarpFunction(this,src_x,src_y,&warp_x,&warp_y);
-      warp_x = warp_x*aspx;
-      warp_y = warp_y*aspy;
+      warp_x = warp_x*aspx + 0.5 * overscan * w;
+      warp_y = warp_y*aspy + 0.5 * overscan * h;
       int ix = int(warp_x), iy = int(warp_y);
       int fx = round((warp_x-ix)*256), fy = round((warp_y-iy)*256);
       if(fx == 256) { fx=0; ix++; }
@@ -264,10 +268,10 @@ struct InvertIntrinsicsFunction {
   }
 };
 
-void CameraIntrinsics::CheckDistortLookupGrid(int width, int height)
+void CameraIntrinsics::CheckDistortLookupGrid(int width, int height, double overscan)
 {
   if(distort_) {
-    if(distort_->width != width || distort_->height != height) {
+    if(distort_->width != width || distort_->height != height || distort_->overscan != overscan) {
       delete [] distort_->offset;
       distort_->offset = NULL;
     }
@@ -278,17 +282,18 @@ void CameraIntrinsics::CheckDistortLookupGrid(int width, int height)
 
   if(!distort_->offset) {
       distort_->offset = new Offset[width*height];
-      ComputeLookupGrid<InvertIntrinsicsFunction>(distort_,width,height);
+      ComputeLookupGrid<InvertIntrinsicsFunction>(distort_,width,height,overscan);
   }
 
   distort_->width = width;
   distort_->height = height;
+  distort_->overscan = overscan;
 }
 
-void CameraIntrinsics::CheckUndistortLookupGrid(int width, int height)
+void CameraIntrinsics::CheckUndistortLookupGrid(int width, int height, double overscan)
 {
   if(undistort_) {
-    if(undistort_->width != width || undistort_->height != height) {
+    if(undistort_->width != width || undistort_->height != height || undistort_->overscan != overscan) {
       delete [] undistort_->offset;
       undistort_->offset = NULL;
     }
@@ -299,15 +304,16 @@ void CameraIntrinsics::CheckUndistortLookupGrid(int width, int height)
 
   if(!undistort_->offset) {
       undistort_->offset = new Offset[width*height];
-      ComputeLookupGrid<ApplyIntrinsicsFunction>(undistort_,width,height);
+      ComputeLookupGrid<ApplyIntrinsicsFunction>(undistort_,width,height,overscan);
   }
 
   undistort_->width = width;
   undistort_->height = height;
+  undistort_->overscan = overscan;
 }
 
-void CameraIntrinsics::Distort(const float* src, float* dst, int width, int height, int channels) {
-  CheckDistortLookupGrid(width, height);
+void CameraIntrinsics::Distort(const float* src, float* dst, int width, int height, double overscan, int channels) {
+  CheckDistortLookupGrid(width, height, overscan);
        if(channels==1) Warp<float,1>(distort_,src,dst,width,height);
   else if(channels==2) Warp<float,2>(distort_,src,dst,width,height);
   else if(channels==3) Warp<float,3>(distort_,src,dst,width,height);
@@ -315,8 +321,8 @@ void CameraIntrinsics::Distort(const float* src, float* dst, int width, int heig
   //else assert("channels must be between 1 and 4");
 }
 
-void CameraIntrinsics::Distort(const unsigned char* src, unsigned char* dst, int width, int height, int channels) {
-  CheckDistortLookupGrid(width, height);
+void CameraIntrinsics::Distort(const unsigned char* src, unsigned char* dst, int width, int height, double overscan, int channels) {
+  CheckDistortLookupGrid(width, height, overscan);
        if(channels==1) Warp<unsigned char,1>(distort_,src,dst,width,height);
   else if(channels==2) Warp<unsigned char,2>(distort_,src,dst,width,height);
   else if(channels==3) Warp<unsigned char,3>(distort_,src,dst,width,height);
@@ -324,8 +330,8 @@ void CameraIntrinsics::Distort(const unsigned char* src, unsigned char* dst, int
   //else assert("channels must be between 1 and 4");
 }
 
-void CameraIntrinsics::Undistort(const float* src, float* dst, int width, int height, int channels) {
-  CheckUndistortLookupGrid(width, height);
+void CameraIntrinsics::Undistort(const float* src, float* dst, int width, int height, double overscan, int channels) {
+  CheckUndistortLookupGrid(width, height, overscan);
        if(channels==1) Warp<float,1>(undistort_,src,dst,width,height);
   else if(channels==2) Warp<float,2>(undistort_,src,dst,width,height);
   else if(channels==3) Warp<float,3>(undistort_,src,dst,width,height);
@@ -333,8 +339,8 @@ void CameraIntrinsics::Undistort(const float* src, float* dst, int width, int he
   //else assert("channels must be between 1 and 4");
 }
 
-void CameraIntrinsics::Undistort(const unsigned char* src, unsigned char* dst, int width, int height, int channels) {
-  CheckUndistortLookupGrid(width, height);
+void CameraIntrinsics::Undistort(const unsigned char* src, unsigned char* dst, int width, int height, double overscan, int channels) {
+  CheckUndistortLookupGrid(width, height, overscan);
        if(channels==1) Warp<unsigned char,1>(undistort_,src,dst,width,height);
   else if(channels==2) Warp<unsigned char,2>(undistort_,src,dst,width,height);
   else if(channels==3) Warp<unsigned char,3>(undistort_,src,dst,width,height);
diff --git a/src/libmv/simple_pipeline/camera_intrinsics.h b/src/libmv/simple_pipeline/camera_intrinsics.h
index f525571..f4bf903 100644
--- a/src/libmv/simple_pipeline/camera_intrinsics.h
+++ b/src/libmv/simple_pipeline/camera_intrinsics.h
@@ -91,7 +91,7 @@ class CameraIntrinsics {
       \note This is the reference implementation using floating point images.
   */
   void Distort(const float* src, float* dst,
-               int width, int height, int channels);
+               int width, int height, double overscan, int channels);
   /*!
       Distort an image using the current camera instrinsics
 
@@ -101,7 +101,7 @@ class CameraIntrinsics {
       \note This version is much faster.
   */
   void Distort(const unsigned char* src, unsigned char* dst,
-               int width, int height, int channels);
+               int width, int height, double overscan, int channels);
   /*!
       Undistort an image using the current camera instrinsics
 
@@ -111,7 +111,7 @@ class CameraIntrinsics {
       \note This is the reference implementation using floating point images.
   */
   void Undistort(const float* src, float* dst,
-                 int width, int height, int channels);
+                 int width, int height, double overscan, int channels);
   /*!
       Undistort an image using the current camera instrinsics
 
@@ -121,12 +121,12 @@ class CameraIntrinsics {
       \note This version is much faster.
   */
   void Undistort(const unsigned char* src, unsigned char* dst,
-                 int width, int height, int channels);
+                 int width, int height, double overscan, int channels);
 
  private:
-  template<typename WarpFunction> void ComputeLookupGrid(struct Grid* grid, int width, int height);
-  void CheckUndistortLookupGrid(int width, int height);
-  void CheckDistortLookupGrid(int width, int height);
+  template<typename WarpFunction> void ComputeLookupGrid(struct Grid* grid, int width, int height, double overscan);
+  void CheckUndistortLookupGrid(int width, int height, double overscan);
+  void CheckDistortLookupGrid(int width, int height, double overscan);
   void FreeLookupGrid();
 
   // The traditional intrinsics matrix from x = K[R|t]X.