optv 0.2.9__tar.gz → 0.3.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- optv-0.3.0/MANIFEST.in +6 -0
- optv-0.3.0/PKG-INFO +47 -0
- optv-0.3.0/README.md +36 -0
- optv-0.3.0/liboptv/include/calibration.h +84 -0
- optv-0.3.0/liboptv/include/glass.h +11 -0
- {optv-0.2.9/liboptv/include/optv → optv-0.3.0/liboptv/include}/parameters.h +2 -2
- {optv-0.2.9/liboptv/include/optv → optv-0.3.0/liboptv/include}/ray_tracing.h +1 -11
- {optv-0.2.9/liboptv/include/optv → optv-0.3.0/liboptv/include}/track.h +11 -0
- {optv-0.2.9 → optv-0.3.0}/liboptv/src/calibration.c +11 -17
- {optv-0.2.9 → optv-0.3.0}/liboptv/src/orientation.c +34 -12
- {optv-0.2.9 → optv-0.3.0}/liboptv/src/trafo.c +114 -50
- optv-0.3.0/optv/__init__.py +4 -0
- optv-0.3.0/optv/calibration.c +16774 -0
- {optv-0.2.9 → optv-0.3.0}/optv/calibration.pxd +8 -2
- optv-0.3.0/optv/correspondences.c +16004 -0
- {optv-0.2.9 → optv-0.3.0}/optv/correspondences.pxd +3 -0
- optv-0.3.0/optv/epipolar.c +11563 -0
- {optv-0.2.9 → optv-0.3.0}/optv/epipolar.pxd +2 -6
- optv-0.3.0/optv/image_processing.c +11796 -0
- {optv-0.2.9 → optv-0.3.0}/optv/image_processing.pxd +3 -0
- optv-0.3.0/optv/imgcoord.c +12884 -0
- {optv-0.2.9 → optv-0.3.0}/optv/imgcoord.pxd +3 -0
- optv-0.3.0/optv/orientation.c +17217 -0
- {optv-0.2.9 → optv-0.3.0}/optv/orientation.pxd +3 -0
- optv-0.3.0/optv/parameters.c +36868 -0
- {optv-0.2.9 → optv-0.3.0}/optv/parameters.pxd +38 -5
- optv-0.3.0/optv/segmentation.c +11724 -0
- {optv-0.2.9 → optv-0.3.0}/optv/segmentation.pxd +4 -1
- optv-0.3.0/optv/tracker.c +13844 -0
- {optv-0.2.9 → optv-0.3.0}/optv/tracker.pxd +3 -0
- optv-0.3.0/optv/tracking_framebuf.c +18509 -0
- {optv-0.2.9 → optv-0.3.0}/optv/tracking_framebuf.pxd +3 -1
- optv-0.3.0/optv/transforms.c +34041 -0
- {optv-0.2.9 → optv-0.3.0}/optv/transforms.pxd +2 -0
- optv-0.3.0/optv/version.py +1 -0
- optv-0.3.0/optv.egg-info/PKG-INFO +47 -0
- {optv-0.2.9 → optv-0.3.0}/optv.egg-info/SOURCES.txt +23 -18
- optv-0.3.0/optv.egg-info/requires.txt +2 -0
- optv-0.3.0/pyproject.toml +30 -0
- optv-0.3.0/setup.py +105 -0
- {optv-0.2.9 → optv-0.3.0}/test/test_corresp.py +11 -11
- {optv-0.2.9 → optv-0.3.0}/test/test_epipolar.py +2 -2
- {optv-0.2.9 → optv-0.3.0}/test/test_orientation.py +14 -14
- {optv-0.2.9 → optv-0.3.0}/test/test_parameters_bindings.py +25 -26
- {optv-0.2.9 → optv-0.3.0}/test/test_tracker.py +39 -7
- {optv-0.2.9 → optv-0.3.0}/test/test_trafo_bindings.py +4 -4
- optv-0.3.0/test/test_version.py +15 -0
- optv-0.2.9/PKG-INFO +0 -10
- optv-0.2.9/liboptv/include/optv/calibration.h +0 -78
- optv-0.2.9/optv/__init__.py +0 -0
- optv-0.2.9/optv/calibration.c +0 -9784
- optv-0.2.9/optv/correspondences.c +0 -10378
- optv-0.2.9/optv/epipolar.c +0 -7183
- optv-0.2.9/optv/image_processing.c +0 -7308
- optv-0.2.9/optv/imgcoord.c +0 -8091
- optv-0.2.9/optv/orientation.c +0 -11494
- optv-0.2.9/optv/parameters.c +0 -21081
- optv-0.2.9/optv/segmentation.c +0 -7289
- optv-0.2.9/optv/tracker.c +0 -5105
- optv-0.2.9/optv/tracking_framebuf.c +0 -11385
- optv-0.2.9/optv/transforms.c +0 -9195
- optv-0.2.9/optv.egg-info/PKG-INFO +0 -10
- optv-0.2.9/optv.egg-info/requires.txt +0 -3
- optv-0.2.9/pyproject.toml +0 -16
- optv-0.2.9/setup.py +0 -165
- {optv-0.2.9 → optv-0.3.0}/README.txt +0 -0
- {optv-0.2.9/liboptv/include/optv → optv-0.3.0/liboptv/include}/correspondences.h +0 -0
- {optv-0.2.9/liboptv/include/optv → optv-0.3.0/liboptv/include}/epi.h +0 -0
- {optv-0.2.9/liboptv/include/optv → optv-0.3.0/liboptv/include}/image_processing.h +0 -0
- {optv-0.2.9/liboptv/include/optv → optv-0.3.0/liboptv/include}/imgcoord.h +0 -0
- {optv-0.2.9/liboptv/include/optv → optv-0.3.0/liboptv/include}/lsqadj.h +0 -0
- {optv-0.2.9/liboptv/include/optv → optv-0.3.0/liboptv/include}/multimed.h +0 -0
- {optv-0.2.9/liboptv/include/optv → optv-0.3.0/liboptv/include}/orientation.h +0 -0
- {optv-0.2.9/liboptv/include/optv → optv-0.3.0/liboptv/include}/segmentation.h +0 -0
- {optv-0.2.9/liboptv/include/optv → optv-0.3.0/liboptv/include}/sortgrid.h +0 -0
- {optv-0.2.9/liboptv/include/optv → optv-0.3.0/liboptv/include}/tracking_frame_buf.h +0 -0
- {optv-0.2.9/liboptv/include/optv → optv-0.3.0/liboptv/include}/tracking_run.h +0 -0
- {optv-0.2.9/liboptv/include/optv → optv-0.3.0/liboptv/include}/trafo.h +0 -0
- {optv-0.2.9/liboptv/include/optv → optv-0.3.0/liboptv/include}/vec_utils.h +0 -0
- {optv-0.2.9 → optv-0.3.0}/liboptv/src/correspondences.c +0 -0
- {optv-0.2.9 → optv-0.3.0}/liboptv/src/epi.c +0 -0
- {optv-0.2.9 → optv-0.3.0}/liboptv/src/image_processing.c +0 -0
- {optv-0.2.9 → optv-0.3.0}/liboptv/src/imgcoord.c +0 -0
- {optv-0.2.9 → optv-0.3.0}/liboptv/src/lsqadj.c +0 -0
- {optv-0.2.9 → optv-0.3.0}/liboptv/src/multimed.c +0 -0
- {optv-0.2.9 → optv-0.3.0}/liboptv/src/parameters.c +0 -0
- {optv-0.2.9 → optv-0.3.0}/liboptv/src/ray_tracing.c +0 -0
- {optv-0.2.9 → optv-0.3.0}/liboptv/src/segmentation.c +0 -0
- {optv-0.2.9 → optv-0.3.0}/liboptv/src/sortgrid.c +0 -0
- {optv-0.2.9 → optv-0.3.0}/liboptv/src/track.c +0 -0
- {optv-0.2.9 → optv-0.3.0}/liboptv/src/tracking_frame_buf.c +0 -0
- {optv-0.2.9 → optv-0.3.0}/liboptv/src/tracking_run.c +0 -0
- {optv-0.2.9 → optv-0.3.0}/liboptv/src/vec_utils.c +0 -0
- {optv-0.2.9 → optv-0.3.0}/optv/vec_utils.pxd +0 -0
- {optv-0.2.9 → optv-0.3.0}/optv.egg-info/dependency_links.txt +0 -0
- {optv-0.2.9 → optv-0.3.0}/optv.egg-info/top_level.txt +0 -0
- {optv-0.2.9 → optv-0.3.0}/setup.cfg +0 -0
- {optv-0.2.9 → optv-0.3.0}/test/test_burgers.py +0 -0
- {optv-0.2.9 → optv-0.3.0}/test/test_calibration_binding.py +0 -0
- {optv-0.2.9 → optv-0.3.0}/test/test_framebuf.py +0 -0
- {optv-0.2.9 → optv-0.3.0}/test/test_image_processing.py +0 -0
- {optv-0.2.9 → optv-0.3.0}/test/test_img_coord.py +0 -0
- {optv-0.2.9 → optv-0.3.0}/test/test_segmentation.py +0 -0
optv-0.3.0/MANIFEST.in
ADDED
optv-0.3.0/PKG-INFO
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: optv
|
|
3
|
+
Version: 0.3.0
|
|
4
|
+
Summary: OpenPTV Python bindings
|
|
5
|
+
Author-email: OpenPTV Community <openptv@googlegroups.com>
|
|
6
|
+
License: LGPL-3.0-or-later
|
|
7
|
+
Requires-Python: >=3.10
|
|
8
|
+
Description-Content-Type: text/markdown
|
|
9
|
+
Requires-Dist: numpy==1.26.4
|
|
10
|
+
Requires-Dist: pyyaml
|
|
11
|
+
|
|
12
|
+
# OpenPTV Python Bindings
|
|
13
|
+
|
|
14
|
+
Python bindings for the OpenPTV library.
|
|
15
|
+
|
|
16
|
+
## Installation
|
|
17
|
+
|
|
18
|
+
Simple installation via pip:
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
pip install openptv
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Building from Source
|
|
25
|
+
|
|
26
|
+
1. Install dependencies:
|
|
27
|
+
```bash
|
|
28
|
+
pip install numpy cython setuptools
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
2. Build the package:
|
|
32
|
+
```bash
|
|
33
|
+
python setup.py prepare
|
|
34
|
+
python setup.py build
|
|
35
|
+
python setup.py install
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Testing
|
|
39
|
+
|
|
40
|
+
Run the test suite:
|
|
41
|
+
```bash
|
|
42
|
+
pytest test/
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## License
|
|
46
|
+
|
|
47
|
+
LGPL-3.0-or-later
|
optv-0.3.0/README.md
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# OpenPTV Python Bindings
|
|
2
|
+
|
|
3
|
+
Python bindings for the OpenPTV library.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Simple installation via pip:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pip install openptv
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Building from Source
|
|
14
|
+
|
|
15
|
+
1. Install dependencies:
|
|
16
|
+
```bash
|
|
17
|
+
pip install numpy cython setuptools
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
2. Build the package:
|
|
21
|
+
```bash
|
|
22
|
+
python setup.py prepare
|
|
23
|
+
python setup.py build
|
|
24
|
+
python setup.py install
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Testing
|
|
28
|
+
|
|
29
|
+
Run the test suite:
|
|
30
|
+
```bash
|
|
31
|
+
pytest test/
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## License
|
|
35
|
+
|
|
36
|
+
LGPL-3.0-or-later
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/* Objects related to calibration: exterior and interior parameters, glass
|
|
2
|
+
parameters. A Calibration object to rule them all and find them.
|
|
3
|
+
|
|
4
|
+
References:
|
|
5
|
+
[1] Th. Dracos (editor). Three-Dimensional Velocity and Vorticity Measuring
|
|
6
|
+
and Image Analysis Techniques. Kluwer Academic Publishers. 1996.
|
|
7
|
+
pp.165-168
|
|
8
|
+
*/
|
|
9
|
+
#ifndef CALIBRATION_H
|
|
10
|
+
#define CALIBRATION_H
|
|
11
|
+
|
|
12
|
+
#include "vec_utils.h"
|
|
13
|
+
|
|
14
|
+
#ifdef __cplusplus
|
|
15
|
+
extern "C" {
|
|
16
|
+
#endif
|
|
17
|
+
|
|
18
|
+
typedef double Dmatrix[3][3];
|
|
19
|
+
|
|
20
|
+
/* Define Glass structure first */
|
|
21
|
+
typedef struct Glass_t {
|
|
22
|
+
double vec_x, vec_y, vec_z;
|
|
23
|
+
double n1, n2, n3;
|
|
24
|
+
double d;
|
|
25
|
+
} Glass;
|
|
26
|
+
|
|
27
|
+
/* Then the rest of the structs */
|
|
28
|
+
typedef struct Exterior_t {
|
|
29
|
+
double x0, y0, z0;
|
|
30
|
+
double omega, phi, kappa;
|
|
31
|
+
Dmatrix dm;
|
|
32
|
+
} Exterior;
|
|
33
|
+
|
|
34
|
+
typedef struct Interior_t {
|
|
35
|
+
double xh, yh;
|
|
36
|
+
double cc;
|
|
37
|
+
} Interior;
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
typedef struct {
|
|
41
|
+
double k1, k2, k3;
|
|
42
|
+
double p1, p2;
|
|
43
|
+
double scx, she;
|
|
44
|
+
int field;
|
|
45
|
+
} ap_52;
|
|
46
|
+
|
|
47
|
+
typedef struct {
|
|
48
|
+
vec3d origin;
|
|
49
|
+
int nr, nz, rw;
|
|
50
|
+
double *data;
|
|
51
|
+
} mmlut;
|
|
52
|
+
|
|
53
|
+
typedef struct {
|
|
54
|
+
Exterior ext_par;
|
|
55
|
+
Interior int_par;
|
|
56
|
+
Glass glass_par;
|
|
57
|
+
ap_52 added_par;
|
|
58
|
+
mmlut mmlut;
|
|
59
|
+
} Calibration;
|
|
60
|
+
|
|
61
|
+
/* Function declarations - now all structs are defined */
|
|
62
|
+
int write_ori(Exterior Ex, Interior interior, Glass glass, ap_52 ap,
|
|
63
|
+
char *filename, char *add_file);
|
|
64
|
+
int read_ori(Exterior Ex[], Interior interior[], Glass glass[], char *ori_file,
|
|
65
|
+
ap_52 addp[], char *add_file, char *add_fallback);
|
|
66
|
+
void rotation_matrix(Exterior *ex);
|
|
67
|
+
|
|
68
|
+
/* Compare two calibration objects for equality */
|
|
69
|
+
int compare_calib(Calibration *c1, Calibration *c2);
|
|
70
|
+
|
|
71
|
+
/* Compare individual calibration components */
|
|
72
|
+
int compare_exterior(Exterior *e1, Exterior *e2);
|
|
73
|
+
int compare_interior(Interior *i1, Interior *i2);
|
|
74
|
+
int compare_glass(Glass *g1, Glass *g2);
|
|
75
|
+
int compare_addpar(ap_52 *a1, ap_52 *a2);
|
|
76
|
+
|
|
77
|
+
Calibration* read_calibration(char *ori_file, char *add_file, char *fallback_file);
|
|
78
|
+
int write_calibration(Calibration *cal, char *filename, char *add_file);
|
|
79
|
+
|
|
80
|
+
#ifdef __cplusplus
|
|
81
|
+
}
|
|
82
|
+
#endif
|
|
83
|
+
|
|
84
|
+
#endif
|
|
@@ -20,13 +20,13 @@ sequence_par* new_sequence_par(int num_cams);
|
|
|
20
20
|
void free_sequence_par(sequence_par * sp);
|
|
21
21
|
int compare_sequence_par(sequence_par *sp1, sequence_par *sp2);
|
|
22
22
|
|
|
23
|
-
typedef struct
|
|
24
|
-
{
|
|
23
|
+
typedef struct {
|
|
25
24
|
double dacc, dangle, dvxmax, dvxmin;
|
|
26
25
|
double dvymax, dvymin, dvzmax, dvzmin;
|
|
27
26
|
int dsumg, dn, dnx, dny, add;
|
|
28
27
|
} track_par;
|
|
29
28
|
|
|
29
|
+
/* Function declarations */
|
|
30
30
|
track_par* read_track_par(char *filename);
|
|
31
31
|
int compare_track_par(track_par *t1, track_par *t2);
|
|
32
32
|
|
|
@@ -16,17 +16,7 @@
|
|
|
16
16
|
#include "tracking_frame_buf.h"
|
|
17
17
|
#include "lsqadj.h"
|
|
18
18
|
|
|
19
|
-
void ray_tracing
|
|
20
|
-
, double y
|
|
21
|
-
, Calibration* cal
|
|
22
|
-
, mm_np mm
|
|
23
|
-
, double X[3]
|
|
24
|
-
, double a[3]);
|
|
25
|
-
|
|
26
|
-
void old_ray_tracing (double x, double y, Exterior Ex, Interior I, Glass G,\
|
|
27
|
-
mm_np mm, double *Xb2, double *Yb2, double *Zb2, \
|
|
28
|
-
double *a3, double *b3,double *c3);
|
|
29
|
-
|
|
19
|
+
void ray_tracing(double x, double y, Calibration* cal, mm_np mm, double X[3], double a[3]);
|
|
30
20
|
|
|
31
21
|
#endif
|
|
32
22
|
|
|
@@ -58,4 +58,15 @@ void trackcorr_c_loop (tracking_run *run_info, int step);
|
|
|
58
58
|
void trackcorr_c_finish(tracking_run *run_info, int step);
|
|
59
59
|
double trackback_c(tracking_run *run_info);
|
|
60
60
|
|
|
61
|
+
/* add_particle() inserts a particle at a given position to the end of the
|
|
62
|
+
* frame, along with associated targets.
|
|
63
|
+
*
|
|
64
|
+
* Arguments:
|
|
65
|
+
* frame *frm - the frame to store the particle.
|
|
66
|
+
* vec3d pos - position of inserted particle in the global coordinates.
|
|
67
|
+
* int cand_inds[][MAX_CANDS] - indices of candidate targets for association
|
|
68
|
+
* with this particle.
|
|
69
|
+
*/
|
|
70
|
+
void add_particle(frame *frm, vec3d pos, int cand_inds[][MAX_CANDS]);
|
|
71
|
+
|
|
61
72
|
#endif
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
* char *add_file - path of file to contain added (distortions) parameters.
|
|
23
23
|
*/
|
|
24
24
|
|
|
25
|
-
int write_ori (Exterior Ex, Interior
|
|
25
|
+
int write_ori (Exterior Ex, Interior interior, Glass glass, ap_52 ap,
|
|
26
26
|
char *filename, char *add_file){
|
|
27
27
|
FILE *fp;
|
|
28
28
|
int i, success = 0;
|
|
@@ -37,8 +37,8 @@ int write_ori (Exterior Ex, Interior I, Glass G, ap_52 ap, \
|
|
|
37
37
|
Ex.x0, Ex.y0, Ex.z0, Ex.omega, Ex.phi, Ex.kappa);
|
|
38
38
|
for (i=0; i<3; i++) fprintf (fp, " %10.7f %10.7f %10.7f\n",
|
|
39
39
|
Ex.dm[i][0], Ex.dm[i][1], Ex.dm[i][2]);
|
|
40
|
-
fprintf (fp,"\n %8.4f %8.4f\n %8.4f\n",
|
|
41
|
-
fprintf (fp,"\n %20.15f %20.15f %20.15f\n",
|
|
40
|
+
fprintf (fp,"\n %8.4f %8.4f\n %8.4f\n", interior.xh, interior.yh, interior.cc);
|
|
41
|
+
fprintf (fp,"\n %20.15f %20.15f %20.15f\n", glass.vec_x, glass.vec_y, glass.vec_z);
|
|
42
42
|
|
|
43
43
|
fclose (fp);
|
|
44
44
|
fp = NULL;
|
|
@@ -78,24 +78,18 @@ finalize:
|
|
|
78
78
|
* values.
|
|
79
79
|
*/
|
|
80
80
|
|
|
81
|
-
int read_ori
|
|
82
|
-
ap_52 addp[], char *add_file, char *add_fallback)
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
81
|
+
int read_ori(Exterior Ex[], Interior I[], Glass G[], char *ori_file,
|
|
82
|
+
ap_52 addp[], char *add_file, char *add_fallback)
|
|
83
|
+
{
|
|
84
|
+
FILE *fp;
|
|
85
|
+
int i, scan_res;
|
|
86
86
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
if (!(fp = fopen_r(ori_file))) return 0;
|
|
91
|
-
*/
|
|
92
|
-
|
|
93
|
-
fp = fopen (ori_file, "r");
|
|
94
|
-
if (! fp) {
|
|
87
|
+
fp = fopen(ori_file, "r");
|
|
88
|
+
if (!fp) {
|
|
95
89
|
printf("Can't open ORI file: %s\n", ori_file);
|
|
96
90
|
goto handle_error;
|
|
97
91
|
}
|
|
98
|
-
|
|
92
|
+
|
|
99
93
|
/* Exterior */
|
|
100
94
|
scan_res = fscanf (fp, "%lf %lf %lf %lf %lf %lf",
|
|
101
95
|
&(Ex->x0), &(Ex->y0), &(Ex->z0),
|
|
@@ -713,46 +713,68 @@ int read_man_ori_fix(vec3d fix4[4], char* calblock_filename,
|
|
|
713
713
|
char* man_ori_filename, int cam)
|
|
714
714
|
{
|
|
715
715
|
FILE* fpp;
|
|
716
|
-
int dummy, pnr, nr[4],i;
|
|
716
|
+
int dummy, pnr, nr[4], i;
|
|
717
717
|
int num_fix, num_match;
|
|
718
718
|
vec3d *fix = NULL;
|
|
719
|
+
int ret;
|
|
719
720
|
|
|
720
|
-
fpp = fopen(man_ori_filename,"r");
|
|
721
|
-
if (!
|
|
721
|
+
fpp = fopen(man_ori_filename, "r");
|
|
722
|
+
if (!fpp) {
|
|
722
723
|
printf("Can't open manual orientation file %s\n", man_ori_filename);
|
|
723
724
|
goto handle_error;
|
|
724
725
|
}
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
726
|
+
printf("Opened %s\n", man_ori_filename);
|
|
727
|
+
|
|
728
|
+
/* Skip cameras before the one we're interested in */
|
|
729
|
+
for (i = 0; i < cam; i++) {
|
|
730
|
+
ret = fscanf(fpp, "%d %d %d %d \n", &dummy, &dummy, &dummy, &dummy);
|
|
731
|
+
if (ret != 4) {
|
|
732
|
+
printf("Error reading dummy values for camera %d\n", i);
|
|
733
|
+
goto handle_error;
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
printf("Skipped %d cameras\n", cam);
|
|
737
|
+
|
|
738
|
+
/* Read the point numbers for our camera */
|
|
739
|
+
ret = fscanf(fpp, "%d %d %d %d \n", &nr[0], &nr[1], &nr[2], &nr[3]);
|
|
740
|
+
if (ret != 4) {
|
|
741
|
+
printf("Error reading point numbers\n");
|
|
742
|
+
goto handle_error;
|
|
743
|
+
}
|
|
744
|
+
printf("Looking for points: %d %d %d %d\n", nr[0], nr[1], nr[2], nr[3]);
|
|
745
|
+
|
|
746
|
+
fclose(fpp);
|
|
730
747
|
|
|
731
748
|
/* read the id and positions of the fixed points, assign the pre-defined to fix4 */
|
|
732
749
|
fix = read_calblock(&num_fix, calblock_filename);
|
|
733
750
|
if (num_fix < 4) {
|
|
734
|
-
printf("Too few points or incompatible file: %s\n",
|
|
751
|
+
printf("Too few points or incompatible file: %s (got %d points)\n",
|
|
752
|
+
calblock_filename, num_fix);
|
|
735
753
|
goto handle_error;
|
|
736
754
|
}
|
|
755
|
+
printf("Read %d points from calblock\n", num_fix);
|
|
737
756
|
|
|
738
757
|
num_match = 0; /* count matches to needed numbers */
|
|
739
758
|
for (pnr = 0; pnr < num_fix; pnr++) {
|
|
759
|
+
printf("Checking point %d\n", pnr);
|
|
740
760
|
for (i = 0; i < 4; i++) {
|
|
741
761
|
if (pnr == nr[i] - 1) {
|
|
742
762
|
vec_copy(fix4[i], fix[pnr]);
|
|
743
763
|
num_match++;
|
|
764
|
+
printf("Found match %d: point %d matches needed point %d\n",
|
|
765
|
+
num_match, pnr, nr[i]);
|
|
744
766
|
break;
|
|
745
767
|
}
|
|
746
768
|
}
|
|
747
|
-
if (num_match >=
|
|
769
|
+
if (num_match >= 4) break;
|
|
748
770
|
}
|
|
749
771
|
|
|
750
772
|
free(fix);
|
|
773
|
+
printf("Found %d matches total\n", num_match);
|
|
751
774
|
return num_match;
|
|
752
775
|
|
|
753
776
|
handle_error:
|
|
754
|
-
if (
|
|
755
|
-
free(fix);
|
|
777
|
+
if (fix) free(fix);
|
|
756
778
|
return 0;
|
|
757
779
|
}
|
|
758
780
|
|
|
@@ -166,30 +166,81 @@ void metric_to_pixel(double * x_pixel
|
|
|
166
166
|
ap_52 ap - distortion parameters struct.
|
|
167
167
|
double *x1, *y1 - output metric distorted parameters.
|
|
168
168
|
*/
|
|
169
|
-
void distort_brown_affin (double x, double y, ap_52 ap, double *x1, double *y1){
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
x += x * (ap.k1*r*r + ap.k2*r*r*r*r + ap.k3*r*r*r*r*r*r)
|
|
177
|
-
+ ap.p1 * (r*r + 2*x*x) + 2*ap.p2*x*y;
|
|
178
|
-
|
|
179
|
-
y += y * (ap.k1*r*r + ap.k2*r*r*r*r + ap.k3*r*r*r*r*r*r)
|
|
180
|
-
+ ap.p2 * (r*r + 2*y*y) + 2*ap.p1*x*y;
|
|
181
|
-
|
|
182
|
-
*x1 = ap.scx * x - sin(ap.she) * y; *y1 = cos(ap.she) * y;
|
|
169
|
+
void distort_brown_affin (double x, double y, ap_52 ap, double *x1, double *y1) {
|
|
170
|
+
double r = sqrt(x*x + y*y);
|
|
171
|
+
|
|
172
|
+
if (r < 1e-10) {
|
|
173
|
+
*x1 = 0;
|
|
174
|
+
*y1 = 0;
|
|
175
|
+
return;
|
|
183
176
|
}
|
|
177
|
+
|
|
178
|
+
// Apply radial distortion
|
|
179
|
+
double r2 = r*r;
|
|
180
|
+
double r4 = r2*r2;
|
|
181
|
+
double r6 = r4*r2;
|
|
182
|
+
double radial_factor = 1.0 + ap.k1*r2 + ap.k2*r4 + ap.k3*r6;
|
|
183
|
+
|
|
184
|
+
// Apply decentering distortion
|
|
185
|
+
double x_dist = x * radial_factor + ap.p1 * (r2 + 2*x*x) + 2*ap.p2*x*y;
|
|
186
|
+
double y_dist = y * radial_factor + ap.p2 * (r2 + 2*y*y) + 2*ap.p1*x*y;
|
|
187
|
+
|
|
188
|
+
// Apply affine transformation more stably
|
|
189
|
+
double sin_she = sin(ap.she);
|
|
190
|
+
double cos_she = cos(ap.she);
|
|
191
|
+
|
|
192
|
+
// Scale first, then shear to maintain better numerical precision
|
|
193
|
+
*x1 = ap.scx * (x_dist - sin_she * y_dist);
|
|
194
|
+
*y1 = ap.scx * cos_she * y_dist; // Apply same scale to maintain aspect ratio
|
|
184
195
|
}
|
|
185
196
|
|
|
186
197
|
/* correct distorted to flat-image coordinates, see correct_brown_affine_exact(),
|
|
187
198
|
this one is the same except it ensures only one iteration for backward
|
|
188
199
|
compatibility.
|
|
189
200
|
*/
|
|
190
|
-
void correct_brown_affin (double x, double y, ap_52 ap, double *x1, double *y1)
|
|
191
|
-
|
|
192
|
-
|
|
201
|
+
void correct_brown_affin (double x, double y, ap_52 ap, double *x1, double *y1) {
|
|
202
|
+
// Use a more stable iteration scheme with better initial guess
|
|
203
|
+
const double sin_she = sin(ap.she);
|
|
204
|
+
const double cos_she = cos(ap.she);
|
|
205
|
+
const double inv_scx = 1.0/ap.scx;
|
|
206
|
+
|
|
207
|
+
// Initial guess: inverse affine transformation
|
|
208
|
+
double xq = x * inv_scx;
|
|
209
|
+
double yq = y * inv_scx / cos_she; // Corrected for scale
|
|
210
|
+
xq += yq * sin_she; // Apply shear correction
|
|
211
|
+
|
|
212
|
+
const int MAX_ITER = 20;
|
|
213
|
+
const double DAMPING = 0.7; // Adjusted damping factor
|
|
214
|
+
const double TOL = 1e-8; // Tight tolerance for convergence
|
|
215
|
+
|
|
216
|
+
for (int i = 0; i < MAX_ITER; i++) {
|
|
217
|
+
// Store previous values for convergence check
|
|
218
|
+
double xq_old = xq;
|
|
219
|
+
double yq_old = yq;
|
|
220
|
+
|
|
221
|
+
// Calculate distorted position for current guess
|
|
222
|
+
double xt, yt;
|
|
223
|
+
distort_brown_affin(xq, yq, ap, &xt, &yt);
|
|
224
|
+
|
|
225
|
+
// Calculate error
|
|
226
|
+
double dx = (x - xt) * inv_scx;
|
|
227
|
+
double dy = (y - yt) * inv_scx;
|
|
228
|
+
|
|
229
|
+
// Update estimate with damping
|
|
230
|
+
xq += dx * DAMPING;
|
|
231
|
+
yq += dy * DAMPING;
|
|
232
|
+
|
|
233
|
+
// Check convergence using relative error
|
|
234
|
+
double change = sqrt((xq - xq_old)*(xq - xq_old) +
|
|
235
|
+
(yq - yq_old)*(yq - yq_old));
|
|
236
|
+
double pos_magnitude = sqrt(xq*xq + yq*yq);
|
|
237
|
+
if (pos_magnitude > 1e-10 && change/pos_magnitude < TOL) {
|
|
238
|
+
break;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
*x1 = xq;
|
|
243
|
+
*y1 = yq;
|
|
193
244
|
}
|
|
194
245
|
|
|
195
246
|
/* correct_brown_affine_exact() attempts to iteratively solve the inverse
|
|
@@ -207,44 +258,57 @@ void correct_brown_affin (double x, double y, ap_52 ap, double *x1, double *y1)
|
|
|
207
258
|
void correct_brown_affine_exact(double x, double y, ap_52 ap,
|
|
208
259
|
double *x1, double *y1, double tol)
|
|
209
260
|
{
|
|
210
|
-
double
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
261
|
+
const double r_init = sqrt(x*x + y*y);
|
|
262
|
+
|
|
263
|
+
if (r_init < 1e-10) {
|
|
264
|
+
*x1 = 0;
|
|
265
|
+
*y1 = 0;
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
// Pre-compute trig values
|
|
270
|
+
const double sin_she = sin(ap.she);
|
|
271
|
+
const double cos_she = cos(ap.she);
|
|
272
|
+
const double inv_scx = 1.0/ap.scx;
|
|
214
273
|
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
xq = x; yq = y;
|
|
274
|
+
// Initial guess: inverse affine transformation
|
|
275
|
+
double xq = (x + y*sin_she)*inv_scx;
|
|
276
|
+
double yq = y/cos_she;
|
|
219
277
|
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
278
|
+
const int MAX_ITER = 50; // Increased for large shear angles
|
|
279
|
+
const double DAMPING = 0.5; // More conservative damping
|
|
280
|
+
|
|
281
|
+
for (int i = 0; i < MAX_ITER; i++) {
|
|
282
|
+
double r2 = xq*xq + yq*yq;
|
|
283
|
+
double r4 = r2*r2;
|
|
284
|
+
double r6 = r4*r2;
|
|
285
|
+
|
|
286
|
+
// Calculate distortion factors
|
|
287
|
+
double radial_factor = ap.k1*r2 + ap.k2*r4 + ap.k3*r6;
|
|
288
|
+
|
|
289
|
+
// Calculate correction terms
|
|
290
|
+
double dx = xq * radial_factor + ap.p1 * (r2 + 2*xq*xq) + 2*ap.p2*xq*yq;
|
|
291
|
+
double dy = yq * radial_factor + ap.p2 * (r2 + 2*yq*yq) + 2*ap.p1*xq*yq;
|
|
229
292
|
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
*/
|
|
234
|
-
if (rq > 1.2*r) rq = 0.5*r;
|
|
293
|
+
// Calculate new estimates
|
|
294
|
+
double xq_new = (x + y*sin_she)*inv_scx - dx;
|
|
295
|
+
double yq_new = y/cos_she - dy;
|
|
235
296
|
|
|
236
|
-
|
|
237
|
-
|
|
297
|
+
// Apply damping
|
|
298
|
+
double dx_change = xq_new - xq;
|
|
299
|
+
double dy_change = yq_new - yq;
|
|
300
|
+
|
|
301
|
+
xq += DAMPING * dx_change;
|
|
302
|
+
yq += DAMPING * dy_change;
|
|
303
|
+
|
|
304
|
+
// Check convergence
|
|
305
|
+
if (sqrt(dx_change*dx_change + dy_change*dy_change) < tol) {
|
|
306
|
+
break;
|
|
307
|
+
}
|
|
308
|
+
}
|
|
238
309
|
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
r = rq;
|
|
242
|
-
*x1 = (x + yq*sin(ap.she))/ap.scx
|
|
243
|
-
- xq * (ap.k1*r*r + ap.k2*r*r*r*r + ap.k3*r*r*r*r*r*r)
|
|
244
|
-
- ap.p1 * (r*r + 2*xq*xq) - 2*ap.p2*xq*yq;
|
|
245
|
-
*y1 = y/cos(ap.she)
|
|
246
|
-
- yq * (ap.k1*r*r + ap.k2*r*r*r*r + ap.k3*r*r*r*r*r*r)
|
|
247
|
-
- ap.p2 * (r*r + 2*yq*yq) - 2*ap.p1*xq*yq;
|
|
310
|
+
*x1 = xq;
|
|
311
|
+
*y1 = yq;
|
|
248
312
|
}
|
|
249
313
|
|
|
250
314
|
|