Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
7afe608
enable testing again. but cmake does not find check on mac os x
alexlib Sep 1, 2019
010ff0a
frame_init is not init_frame :)
alexlib Sep 1, 2019
7be6232
prepared some structure of what I'd like to do now
alexlib Sep 2, 2019
cb16fcb
ok, i found opentv_batch repository were we already tried to do somet…
alexlib Sep 2, 2019
ae1796c
ok structure gets some shape, follow WORK HERE
alexlib Sep 2, 2019
23b6489
ok we need to learn from read_frame how to fill in the buffers for tr…
alexlib Sep 2, 2019
458d68a
small step forward with run->fb->buf[]
alexlib Sep 2, 2019
2e44bcd
filling the structure is difficult when you don't understand the stru…
alexlib Sep 2, 2019
12a855c
trying to fill in teh buffers on the fly.
alexlib Sep 2, 2019
dfc7b1f
do i keep match_counts[3]?
alexlib Sep 3, 2019
680ac8c
Separate frame-buffer to a base class and child class.
yosefm Sep 6, 2019
18f06b2
Merge pull request #40 from yosefm/framebuf_separate
alexlib Sep 13, 2019
a4743c7
release img later - @yosefm remark
alexlib Sep 20, 2019
130ac76
added two helper functions from tests
alexlib Sep 20, 2019
bf0bbde
ok. it compiles and fails as expected :)
alexlib Sep 20, 2019
84b1c8a
not clear where it fails - i don't manage to read_targets
alexlib Sep 20, 2019
8aa0e13
one obvious bug step - run->seq_par->first is resolved
alexlib Sep 20, 2019
f7ee77a
// we need to push con into the run->fb somehow .
alexlib Sep 20, 2019
0d107f7
got stuck with the structures after corresp_buf
alexlib Sep 21, 2019
e3d0e76
build very complex structure and i think it's very simple, see jw_ptv.c
alexlib Sep 21, 2019
c7f93c8
maybe it's a first prototype
alexlib Sep 21, 2019
c13e89d
at least it compiles
alexlib Sep 21, 2019
38da36c
segfaults
alexlib Sep 21, 2019
0471c72
does not segfaults, but tries to read rt_is
alexlib Sep 21, 2019
9eb37fc
Merge branch 'master' into refactor_fb
alexlib Sep 21, 2019
378f386
maybe without track_forward_start?
alexlib Sep 22, 2019
aba7e2e
Revert "Merge branch 'master' into refactor_fb"
alexlib Sep 22, 2019
037be89
that was an obvious bug - the loop wasn't closed
alexlib Sep 22, 2019
e8c45c8
another loop bug
alexlib Sep 22, 2019
491bd5c
removed annoying print multimed
alexlib Sep 22, 2019
d9ccb0a
"working" means not failing. but not tracking as 3d positions are wrong.
alexlib Sep 23, 2019
bcf466d
small adjustments. smaller tolerance. looking for a bug
alexlib Sep 25, 2019
9641eeb
now the only missing part is tracking buffer. found all bugs in posit…
alexlib Sep 29, 2019
bb63725
got rt_is. quality inside the buffer, hopefully
alexlib Sep 29, 2019
6feef9a
it works !!!
alexlib Sep 29, 2019
e0aeab2
Delete Info.plist
alexlib Sep 29, 2019
fff72cf
Delete main
alexlib Sep 29, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@ liboptv/build
py_bind/optv/*.c
py_bind/build
*.pyc
liboptv/src/main
liboptv/src/main
4 changes: 2 additions & 2 deletions liboptv/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ set (CMAKE_INSTALL_RPATH "$ORIGIN/../lib:$ORIGIN/")

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/CMakeModules/")
project(OpenPTV)
# enable_testing()
enable_testing()
add_subdirectory(src)
# add_subdirectory(tests)
add_subdirectory(tests)

INSTALL(DIRECTORY include/ DESTINATION include/optv/)

Expand Down
28 changes: 28 additions & 0 deletions liboptv/include/main.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#ifndef main_h

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <dirent.h>
#include <math.h>
#include <string.h>
#include <inttypes.h>
#include "tiffio.h"

#include "parameters.h"
#include "track.h"
#include "image_processing.h"
#include "segmentation.h"
#include "tracking_frame_buf.h"
#include "calibration.h"
#include "vec_utils.h"
#include "imgcoord.h"
#include "trafo.h"
#include "correspondences.h"



#define main_h


#endif /* main_h */
Binary file added liboptv/src/main
Binary file not shown.
275 changes: 275 additions & 0 deletions liboptv/src/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,275 @@
/* main.c
I need this file to start preparing some structure in my head. Alex
*/

#define MAXTARGETS 2048
#define BUFFER_LENGTH 4 // we do something very simple and studpid here
#include "main.h"

// These functions are part of the a test suite, see under /tests

void read_all_calibration(Calibration *calib[4], control_par *cpar)
{
char ori_tmpl[] = "cal/cam%d.tif.ori";
char added_name[] = "cal/cam1.tif.addpar";
char ori_name[40];
int cam;

for (cam = 0; cam < cpar->num_cams; cam++)
{
sprintf(ori_name, ori_tmpl, cam + 1);
calib[cam] = read_calibration(ori_name, added_name, NULL);
}
}

/* correct_frame() performs the transition from pixel to metric to flat
coordinates and x-sorting as required by the correspondence code.

Arguments:
frame *frm - target information for all cameras.
control_par *cpar - parameters of image size, pixel size etc.
tol - tolerance parameter for iterative flattening phase, see
trafo.h:correct_brown_affine_exact().
*/
coord_2d **correct_frame(frame *frm, Calibration *calib[], control_par *cpar,
double tol)
{
coord_2d **corrected, **tmp;
int cam, part;

corrected = (coord_2d **)malloc(cpar->num_cams * sizeof(coord_2d *));
tmp = (coord_2d **)malloc(cpar->num_cams * sizeof(coord_2d *));
for (cam = 0; cam < cpar->num_cams; cam++)
{
corrected[cam] = (coord_2d *)malloc(
frm->num_targets[cam] * sizeof(coord_2d));
tmp[cam] = (coord_2d *)malloc(frm->num_targets[cam] * sizeof(coord_2d));
if (corrected[cam] == NULL)
{
/* roll back allocations and fail */
for (cam -= 1; cam >= 0; cam--)
free(corrected[cam]);
free(corrected);
return NULL;
}

for (part = 0; part < frm->num_targets[cam]; part++)
{
pixel_to_metric(&tmp[cam][part].x, &tmp[cam][part].y,
frm->targets[cam][part].x, frm->targets[cam][part].y,
cpar);

dist_to_flat(tmp[cam][part].x, tmp[cam][part].y,
calib[cam], &corrected[cam][part].x, &corrected[cam][part].y,
tol);
corrected[cam][part].pnr = frm->targets[cam][part].pnr;
}

/* This is expected by find_candidate() */
quicksort_coord2d_x(corrected[cam], frm->num_targets[cam]);
}
return corrected;
}

// int main(int argc, const char *argv[])
int main()
{
// initialize variables

int i, cam, ntargets, step, lstep, geo_id;
coord_2d **corrected;
int match_counts[4];
n_tupel *corresp_buf;
tracking_run *run;
vec3d res;
vec2d targ[4],tmp;
framebuf *frm;

// temporary variables will be replaced per particle
corres t_corres = { 3, {96, 66, 26, 26} };
P t_path = {
.x = {45.219, -20.269, 25.946},
.prev = -1,
.next = -2,
.prio = 4,
.finaldecis = 1000000.0,
.inlist = 0.
};

// read parameters from the working directory
// for simplicity all names are default and hard coded (sorry)

// 1. process inputs: directory, first frame, last frame

// printf("This program was called with \"%s\".\n", argv[0]);

// argc = 4;

// argv[1] = '../tests/testing_fodder/test_cavity/';
// argv[2] = 10001;
// argv[3] = 10004;

// if (argc != 2 && argc != 4)
// {
// printf("Wrong number of inputs, expecting: \n");
// printf(" ./main ../tests/testing_fodder/test_cavity/ 10001 10004 \n");
// return 0;
// }

// argv[1] = '../tests/testing_fodder/test_cavity/';
// argv[2] = 10001;
// argv[3] = 10004;

// change directory to the user-supplied working folder
// chdir(argv[1]);

// chdir("../tests/testing_fodder/test_cavity/");
chdir("/Users/alex/Documents/OpenPTV/test_cavity");
// chdir("/Users/alex/Documents/OpenPTV/one-dot-example/working_folder");

// printf("changed directory to %s\n", argv[1]);

// 2. read parameters and calibrations
Calibration *calib[4]; // sorry only for 4 cameras now

control_par *cpar = read_control_par("parameters/ptv.par");
read_all_calibration(calib, cpar);
free_control_par(cpar);

run = tr_new_legacy("parameters/sequence.par",
"parameters/track.par", "parameters/criteria.par",
"parameters/ptv.par", calib);


// if (argc == 4)
// {
// run->seq_par->first = atoi(argv[2]);
// run->seq_par->last = atoi(argv[3]);
// }
run->seq_par->first = 10000;
run->seq_par->last = 10004;

// printf("from frame %d to frame %d \n", run->seq_par->first, run->seq_par->last);

// for each camera and for each time step the images are processed
for (step = run->seq_par->first; step < run->seq_par->last + 1; step++)
{
lstep = step - run->seq_par->first; // local step

for (cam = 0; cam < run->cpar->num_cams; cam++)
{
// we decided to focus camust on the _targets, so we will read them from the
// test directory test_cavity

run->fb->buf[lstep]->num_targets[cam] = read_targets(
run->fb->buf[lstep]->targets[cam], run->fb->target_file_base[cam], step);

quicksort_target_y(run->fb->buf[lstep]->targets[cam], run->fb->buf[lstep]->num_targets[cam]);

for (i = 0; i < run->fb->buf[lstep]->num_targets[cam]; i++)
run->fb->buf[lstep]->targets[cam][i].pnr = i;


} // inner loop is per camera
corrected = correct_frame(run->fb->buf[lstep], run->cal, run->cpar, 0.00001);
corresp_buf = correspondences(run->fb->buf[lstep], corrected, run->vpar, run->cpar, run->cal, match_counts);

run->fb->buf[lstep]->num_parts = match_counts[0];

// first we need to create 3d points after correspondences and fill it into the buffer
// use point_position and loop through the num_parts
// probably feed it directly into the buffer

// so we split into two parts:
// first i copy the code from correspondences.pyx
// and create the same types of arrays in C
// then we will convert those to 3D using similar approach to what is now in Python


// shortcut
int p[4];
double x,y;
float skew_dist;

//printf("looks like rt_is.%d\n",step);

for (i=0; i<run->fb->buf[lstep]->num_parts; i++) {
for (cam = 0; cam < run->cpar->num_cams; cam++) {
if (corresp_buf[i].p[cam] > -1){
p[cam] = corrected[cam][corresp_buf[i].p[cam]].pnr;
x = run->fb->buf[lstep]->targets[cam][p[cam]].x;
y = run->fb->buf[lstep]->targets[cam][p[cam]].y;

pixel_to_metric(&x, &y, x, y, run->cpar);
dist_to_flat(x, y,run->cal[cam], &x, &y,0.00001);

targ[cam][0] = x;
targ[cam][1] = y;
}else{
targ[cam][0] = 1e-10;
targ[cam][1] = 1e-10;
}

t_corres.p[cam] = p[cam];
}

t_corres.nr = i+1; // identical to what I see in rt_is.10004 file
run->fb->buf[lstep]->correspond[i] = t_corres;





skew_dist = point_position(targ, run->cpar->num_cams, run->cpar->mm, run->cal, res);

// printf("%d \t ",run->fb->buf[lstep]->correspond[i].nr);
// printf("%f,\t %f,\t %f\t ",res[0],res[1],res[2]);
// for (cam=0;cam<run->cpar->num_cams; cam++) {
// printf("%d\t ",run->fb->buf[lstep]->correspond[i].p[cam]);
// }
// printf("\n");


t_path.x[0] = res[0];
t_path.x[1] = res[1];
t_path.x[2] = res[2];

run->fb->buf[lstep]->path_info[i] = t_path;
//}
}

} // external loop is through frames

run->tpar->add = 0;
// we do not need to read frames - it's all in memory now
// track_forward_start(run);

// for (step = run->seq_par->first + 1 ; step < run->seq_par->last; step++)
// // for (step = run->seq_par->first + 1; step < run->seq_par->last; step++)
// {
// trackcorr_c_loop(run, step);
// }
// trackcorr_c_finish(run, run->seq_par->last);

trackcorr_c_loop(run, run->seq_par->first);

// probably here we need to send something to plot it
// or store in some memory for the next chunk?
// basically we have a human in the loop here - his/her brain
// will simply follow the velocity values in time like a movie
// and we will store it to binary files. Later if someone wants to do
// tracking, our simmple solution is not good enough. we kind of doing 3D-PIV here
// of 4 frames and show the vectors. The quasi-vectors are not really connected. if we
// will create nice animation - then the user will build tracamectories him/herself.

for (cam -= 1; cam >= 0; cam--)
free(corrected[cam]);

free(corrected);
free(corresp_buf);
free(run->vpar);
free_control_par(run->cpar);

return 0;

} // should be end of main now
2 changes: 1 addition & 1 deletion liboptv/src/multimed.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ double multimed_r_nlay (Calibration *cal, mm_np *mm, vec3d pos) {


if (it >= n_iter) {
printf ("multimed_r_nlay stopped after %d iterations\n", n_iter);
//printf ("multimed_r_nlay stopped after %d iterations\n", n_iter);
return (1.0);
}

Expand Down
4 changes: 2 additions & 2 deletions liboptv/src/tracking_frame_buf.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ int read_targets(target buffer[], char* file_base, int frame_num) {
strncpy(filein, file_base, STR_MAX_LEN);
strncat(filein, "_targets", STR_MAX_LEN);
}

FILEIN = fopen (filein, "r");
if (! FILEIN) {
printf("Can't open ascii file: %s\n", filein);
Expand Down Expand Up @@ -423,7 +423,7 @@ int write_path_frame(corres *cor_buf, P *path_buf, int num_parts,\
return success;
}

/* init_frame() initializes a frame object, allocates its arrays and sets up
/* frame_init() initializes a frame object, allocates its arrays and sets up
* the frame data.
*
* Arguments:
Expand Down