Forums > Jitter

Trapezoidal deformation ?

February 8, 2008 | 9:24 am

Hello all,

Does anyone know how it would be possible to produce a _trapezoidal_
deformation (not pin / barrel) with jit.repos or jt.mxform2d (or a
shader…) ?

The reason is : my camera isn’t absolutely in the front axis of the
object I want to capture, and I need to compensate this deformation
of perspective. I browsed the helps and documentations but perhaps
does it exceed my knowledge in maths ;-)

Thank you very much…

Thierry

—————————————-
Thierry Fournier

http://www.thierryfournier.net


February 8, 2008 | 12:36 pm

hello thierry,

i think the most interesting way to achieve this performance-wise is
to move this processing into OpenGL. There geometry transform gives
you all trapeze-correction practically for free. when combining this
with a nurbs type surface you end up having an extremely flexible lens-
correction. moving individual points of the nurb controlgrid lets you
manipulate parts of the image independantly. the whole trick is to
capture the nurb in a texture for further processing.

see patch below

hth

/*j

save as:

OpenGL_lens_correction

#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P comment 582 41 85 196617 jasch 20080208;
#P comment 1074 480 23 196617 2 1;
#P comment 1074 494 23 196617 2 0;
#P comment 1074 466 26 196617 2 2;
#P comment 1050 494 23 196617 1 0;
#P comment 1050 480 23 196617 1 1;
#P comment 1050 466 23 196617 1 2;
#P comment 1025 494 23 196617 0 0;
#P comment 1025 480 23 196617 0 1;
#P comment 1025 466 23 196617 0 2;
#P outlet 237 363 15 0;
#P comment 429 204 79 196617 show ctlmatrix;
#P comment 985 203 85 196617 stored ctlmatrix;
#P comment 819 203 100 196617 ctlmatrix dimension;
#P comment 661 205 73 196617 nurbs position;
#P comment 1063 420 14 196617 6;
#P comment 1063 434 14 196617 9;
#P comment 1063 406 14 196617 3;
#P comment 1044 434 14 196617 8;
#P comment 1044 420 14 196617 5;
#P comment 1044 406 14 196617 2;
#P comment 1026 434 14 196617 7;
#P comment 1026 420 14 196617 4;
#P comment 1026 406 14 196617 1;
#P toggle 45 327 15 0;
#P newex 45 366 47 196617 gate 1 1;
#P comment 897 221 46 196617 gridsize;
#P newex 819 246 27 196617 pak;
#P message 819 295 83 196617 dim $1 $2 , bang;
#P number 819 221 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P objectname gridsize[0];
#P number 857 221 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P objectname gridsize[1];
#N vpatcher 20 74 626 633;
#P window setfont "Sans Serif" 9.;
#N vpatcher 353 195 953 595;
#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P newex 140 78 22 196617 b 1;
#P inlet 140 40 15 0;
#P outlet 76 215 15 0;
#P newex 76 183 62 196617 prepend set;
#P newex 96 154 62 196617 prepend set;
#N counter 0 1 100000;
#X flags 0 0;
#P newobj 96 113 101 196617 counter 0 1 100000;
#P window linecount 0;
#P newex 96 78 22 196617 b 1;
#P inlet 76 40 15 0;
#P fasten 0 0 4 0 81 119 81 119;
#P connect 3 0 4 0;
#P connect 4 0 5 0;
#P connect 0 0 1 0;
#P connect 1 0 2 0;
#P connect 2 0 3 0;
#P connect 6 0 7 0;
#P connect 7 0 2 2;
#P pop;
#P newobj 122 359 40 196617 p index;
#P newex 122 89 58 196617 unpack 0 0;
#P inlet 92 13 15 0;
#P window linecount 1;
#P newex 190 180 27 196617 – 1;
#P newex 160 204 27 196617 !- 3;
#N coll index_to_cell 1;
#T flags 1 0;
#T 1 0 4;
#T 2 1 4;
#T 3 2 4;
#T 4 3 4;
#T 5 4 4;
#T 6 0 3;
#T 7 1 3;
#T 8 2 3;
#T 9 3 3;
#T 10 4 3;
#T 11 0 2;
#T 12 1 2;
#T 13 2 2;
#T 14 3 2;
#T 15 4 2;
#T 16 0 1;
#T 17 1 1;
#T 18 2 1;
#T 19 3 1;
#T 20 4 1;
#T 21 0 0;
#T 22 1 0;
#T 23 2 0;
#T 24 3 0;
#T 25 4 0;
#P newobj 122 410 99 196617 coll index_to_cell 1;
#P window linecount 0;
#P message 182 384 33 196617 clear;
#P newex 92 38 100 196617 t b l b b;
#P newex 122 311 48 196617 pack 0 0;
#P window linecount 1;
#P newex 122 274 27 196617 – 1;
#P newex 160 174 27 196617 – 1;
#P newex 92 244 40 196617 uzi 4;
#P window linecount 0;
#P newex 92 140 40 196617 uzi 4;
#P connect 10 0 5 0;
#P connect 5 0 0 0;
#P connect 0 0 1 0;
#P connect 5 1 11 0;
#P connect 11 1 0 1;
#P connect 11 0 1 1;
#P connect 1 2 3 0;
#P connect 3 0 4 0;
#P connect 4 0 12 0;
#P connect 6 0 7 0;
#P connect 12 0 7 0;
#P connect 5 2 12 1;
#P connect 0 2 2 0;
#P connect 2 0 8 0;
#P connect 8 0 4 1;
#P connect 9 0 8 1;
#P connect 5 3 6 0;
#P connect 11 1 9 0;
#P pop;
#P newobj 831 271 86 196617 p make_indexlist;
#P newex 531 378 114 196617 r lenscorrection.mouse;
#P newex 355 670 114 196617 s lenscorrection.mouse;
#P newex 514 329 127 196617 jit.gencoord 3 float32 5 5;
#P newex 514 350 300 196617 jit.expr @expr "snorm[0]*1.1"
"snorm[1]*0.825" "in[0]*0.0";
#B color 5;
#P comment 892 444 20 196617 16;
#P comment 873 444 20 196617 15;
#P comment 854 444 20 196617 14;
#P comment 836 444 20 196617 13;
#P comment 892 416 14 196617 8;
#P comment 892 430 20 196617 12;
#P comment 892 402 14 196617 4;
#P comment 909 464 23 196617 3 3;
#P comment 885 464 23 196617 2 3;
#P comment 861 464 23 196617 1 3;
#P comment 836 464 23 196617 0 3;
#P comment 909 493 23 196617 3 1;
#P comment 909 507 23 196617 3 0;
#P comment 909 479 23 196617 3 2;
#P comment 873 416 14 196617 7;
#P comment 873 430 20 196617 11;
#P comment 873 402 14 196617 3;
#P comment 854 430 20 196617 10;
#P comment 854 416 14 196617 6;
#P comment 854 402 14 196617 2;
#P comment 836 430 14 196617 9;
#P comment 836 416 14 196617 5;
#P comment 836 402 14 196617 1;
#P comment 885 493 23 196617 2 1;
#P comment 885 507 23 196617 2 0;
#P comment 885 479 26 196617 2 2;
#P comment 861 507 23 196617 1 0;
#P comment 861 493 23 196617 1 1;
#P comment 861 479 23 196617 1 2;
#P comment 836 507 23 196617 0 0;
#P comment 836 493 23 196617 0 1;
#P comment 836 479 23 196617 0 2;
#P newex 531 559 22 196617 b 1;
#P message 999 236 33 196617 write;
#P message 989 219 57 196617 read , bang;
#P comment 1035 237 95 196617 read/write matrix;
#P newex 571 498 34 196617 * -1.;
#P number 645 406 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#N coll index_to_cell 1;
#T flags 1 0;
#T 1 0 4;
#T 2 1 4;
#T 3 2 4;
#T 4 3 4;
#T 5 4 4;
#T 6 0 3;
#T 7 1 3;
#T 8 2 3;
#T 9 3 3;
#T 10 4 3;
#T 11 0 2;
#T 12 1 2;
#T 13 2 2;
#T 14 3 2;
#T 15 4 2;
#T 16 0 1;
#T 17 1 1;
#T 18 2 1;
#T 19 3 1;
#T 20 4 1;
#T 21 0 0;
#T 22 1 0;
#T 23 2 0;
#T 24 3 0;
#T 25 4 0;
#P newobj 645 440 99 196617 coll index_to_cell 1;
#P newex 572 443 36 196617 – 120;
#P newex 532 444 36 196617 – 160;
#P flonum 531 489 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P flonum 571 518 51 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 572 467 40 196617 / 120.;
#P newex 531 467 40 196617 / 120.;
#P newex 531 424 58 196617 unpack 0 0;
#P newex 531 403 65 196617 route mouse;
#P newex 531 599 27 196617 t b l;
#P newex 531 580 122 196617 pack setcell 0 0 val 0. 0.;
#P message 67 193 34 196617 reset;
#P window linecount 2;
#P newex 67 210 110 196617 jit.gl.handle pupitre @inherit_transform 1;
#P window linecount 1;
#P newex 514 665 118 196617 jit.matrix 3 float32 5 5;
#P toggle 449 222 15 0;
#P message 449 243 60 196617 ctlshow $1;
#P newex 514 689 89 196617 prepend ctlmatrix;
#P newex 516 149 53 196617 autopattr;
#X prestore gridsize[0] 1 0 5;
#X prestore gridsize[1] 1 0 5;
#X prestore position[0] 1 0 -0.04;
#X prestore position[1] 1 0 0.04;
#X prestore position[2] 1 0 0.24;
#X prestore rotate[0] 1 0 2.;
#X prestore rotate[1] 1 0 7.;
#X prestore rotate[2] 1 0 0.;
#P objectname u066000017;
#P flonum 706 222 45 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P objectname position[1];
#P flonum 752 222 45 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P objectname position[2];
#P flonum 607 222 45 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P objectname rotate[2];
#P flonum 660 222 45 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P objectname position[0];
#P flonum 515 222 45 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P objectname rotate[0];
#P flonum 561 222 45 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P objectname rotate[1];
#P newex 661 240 99 196617 pak position 0. 0. 0.;
#P newex 515 240 109 196617 pak rotatexyz 0. 0. 0.;
#P user jit.pwindow 44 417 322 242 0 1 0 0 1 0;
#P newex 45 394 129 196617 jit.matrix 4 char 320 240;
#P newex 237 317 228 196617 jit.gl.texture pupitre @name RX @dim 1280
960;
#P window linecount 3;
#P newex 254 271 154 196617 jit.gl.nurbs pupitre @texture TX @capture
RX @color 1. 1. 1. 1. @dim 5 5 @order 4 4;
#P window linecount 1;
#P newex 254 241 153 196617 jit.gl.texture pupitre @name TX;
#P newex 237 216 27 196617 t b l;
#P newex 237 124 41 196617 r pulse;
#P newex 68 166 41 196617 s pulse;
#P message 295 126 30 196617 read;
#P newex 237 163 63 196617 jit.qt.movie;
#P toggle 44 90 15 0;
#P newex 44 143 58 196617 t b b erase;
#P newex 44 112 57 196617 qmetro 33;
#P newex 43 279 93 196617 jit.window pupitre;
#P newex 44 249 100 196617 jit.gl.render pupitre;
#P comment 683 408 89 196617 select point index;
#P comment 64 326 131 196617 preview corrected texture;
#P comment 515 203 74 196617 nurbs rotation;
#P comment 251 402 189 196617 click in window to change selected point;
#P window setfont "Sans Serif" 18.;
#P comment 19 29 558 196626 lenscorrection in OpenGL using a nurbs and
capture to texture;
#P connect 9 0 7 0;
#P connect 7 0 8 0;
#P connect 33 0 5 0;
#P connect 8 2 5 0;
#P connect 8 0 5 0;
#P connect 95 0 94 0;
#P connect 94 0 18 0;
#P connect 18 0 19 0;
#P connect 34 0 33 0;
#P connect 8 1 12 0;
#P connect 17 0 94 1;
#P connect 13 0 10 0;
#P connect 11 0 10 0;
#P connect 10 0 14 0;
#P connect 14 0 17 0;
#P connect 17 0 109 0;
#P connect 14 1 15 0;
#P fasten 29 0 16 0 519 711 507 711 507 267 259 267;
#P lcolor 16;
#P fasten 30 0 16 0 454 264 259 264;
#P fasten 20 0 16 0 520 264 259 264;
#P fasten 21 0 16 0 666 264 259 264;
#P connect 19 1 86 0;
#P connect 31 0 30 0;
#P connect 91 0 85 0;
#P connect 85 0 84 0;
#P fasten 91 0 32 0 824 658 519 658;
#P connect 84 0 32 0;
#P connect 36 1 32 0;
#P connect 36 0 32 0;
#P fasten 49 0 32 0 994 658 519 658;
#P fasten 50 0 32 0 1004 658 519 658;
#P connect 32 0 29 0;
#P connect 87 0 37 0;
#P connect 37 0 38 0;
#P connect 43 0 39 0;
#P connect 39 0 42 0;
#P connect 42 0 51 0;
#P connect 41 0 51 0;
#P connect 51 0 35 0;
#P fasten 35 0 36 0 536 602 536 602;
#P connect 38 0 43 0;
#P connect 23 0 20 1;
#P fasten 45 0 35 1 650 574 558 574;
#P connect 40 0 47 0;
#P connect 47 0 41 0;
#P connect 38 1 44 0;
#P connect 44 0 40 0;
#P connect 22 0 20 2;
#P connect 25 0 20 3;
#P fasten 42 0 35 4 536 542 624 542;
#P fasten 41 0 35 5 576 537 646 537;
#P connect 46 0 45 0;
#P connect 24 0 21 1;
#P connect 27 0 21 2;
#P connect 26 0 21 3;
#P connect 90 0 92 0;
#P connect 92 0 91 0;
#P connect 92 0 88 0;
#P connect 89 0 92 1;
#P window clipboard copycount 120;


February 8, 2008 | 1:58 pm


Viewing 3 posts - 1 through 3 (of 3 total)