aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAntoine Villeret <avilleret@users.sourceforge.net>2012-09-22 15:13:20 +0000
committerAntoine Villeret <avilleret@users.sourceforge.net>2012-09-22 15:13:20 +0000
commitbd63dd253353ebadcc06438140ee909d9f3703ee (patch)
tree71482d66e864042dd12bc860708670f33a812a96
parent1e9ae4b922bc09ba5954a7817dfb963a4ba90a3d (diff)
add example 05 for perspective correction
svn path=/trunk/externals/pix_opencv/; revision=16268
-rw-r--r--examples/05_perspective_correction/05_perspective_correction.pd327
-rw-r--r--examples/05_perspective_correction/pattern.pngbin0 -> 22255 bytes
-rw-r--r--examples/05_perspective_correction/subprocess.pd73
3 files changed, 400 insertions, 0 deletions
diff --git a/examples/05_perspective_correction/05_perspective_correction.pd b/examples/05_perspective_correction/05_perspective_correction.pd
new file mode 100644
index 0000000..27a5eb9
--- /dev/null
+++ b/examples/05_perspective_correction/05_perspective_correction.pd
@@ -0,0 +1,327 @@
+#N canvas 745 86 900 736 10;
+#X declare -path ../../;
+#X obj 180 76 gemhead;
+#X obj 180 96 pix_share_read 666 640 480 1;
+#X obj 297 186 pix_opencv_findchessboardcorners;
+#X obj 17 13 declare -path ../../;
+#X obj 548 6 loadbang;
+#X msg 587 56 \; pd dsp 1;
+#X obj 567 106 pd~ -ninsig 0 -noutsig 0 -fifo 10;
+#X msg 567 86 pd~ start -open ./subprocess.pd;
+#X obj 100 396 pix_texture;
+#X obj 100 416 rectangle 5.333 4;
+#X obj 548 166 gemwin;
+#X msg 590 166 destroy;
+#X msg 297 26 patternSize 9 6;
+#X obj 180 116 pix_rgba;
+#X text 238 118 <-- switch to color just;
+#X text 262 128 to see openCV drawing;
+#X obj 526 323 unpack;
+#X floatatom 526 343 5 0 0 0 - - -;
+#X floatatom 559 343 5 0 0 0 - - -;
+#X obj 624 304 unpack;
+#X floatatom 624 343 5 0 0 0 - - -;
+#X floatatom 657 343 5 0 0 0 - - -;
+#X obj 526 223 unpack;
+#X floatatom 526 244 5 0 0 0 - - -;
+#X floatatom 559 244 5 0 0 0 - - -;
+#X obj 624 223 unpack;
+#X floatatom 624 243 5 0 0 0 - - -;
+#X floatatom 657 243 5 0 0 0 - - -;
+#X text 510 270 contrary to OpenGL \, OpenCV coordinates are always
+positives;
+#X text 102 152 needed to fix;
+#X obj 297 7 loadbang;
+#X text 309 42 patternSize should match the number;
+#X text 309 52 of inner corners in each direction;
+#X text 510 280 and the origin (0 \, 0) is the upper left corner;
+#X msg 624 203 \$17 \$18;
+#X msg 486 303 \$107 \$108;
+#X msg 525 203 \$1 \$2;
+#X msg 472 323 \$91 \$92;
+#X text 25 694 2012 - Antoine Villeret - tested on Ubuntu with pd 0.43.1
+\, gem 0.93.git 1482ffb;
+#X obj 548 26 t b b b;
+#X text 512 359 the 4 extrem corners' coordinates;
+#X obj 70 658 mesh_square 10 10;
+#X obj 113 537 /;
+#X obj 189 537 /;
+#X obj 113 493 loadbang;
+#X obj 70 579 GEMglMultTransposeMatrixf;
+#X obj 70 639 translateXYZ 1 1 0;
+#X obj 70 559 scaleXYZ 0.003 0.003 0;
+#X obj 70 599 scaleXYZ 639 479 0;
+#X obj 70 468 translateXYZ -5.33333 -4 0;
+#X obj 70 619 scaleXYZ 0.5 0.5 0;
+#X msg 113 517 5.3333 320;
+#X msg 189 517 4 240;
+#N canvas 3 79 450 300 format 0;
+#X obj 93 7 inlet;
+#X obj 118 140 outlet;
+#X msg 108 68 \$1 \$4 0 \$7 \$2 \$5 0 \$8 0 0 1 0 \$3 \$6 0 \$9;
+#X connect 0 0 2 0;
+#X connect 2 0 1 0;
+#X restore 253 529 pd format;
+#N canvas 3 79 643 318 mapMatrix 0;
+#X obj 110 263 pack 0 0 0 0 0 0 0 0 0;
+#X floatatom 110 121 5 0 0 0 - - -;
+#X floatatom 160 121 5 0 0 0 - - -;
+#X floatatom 210 121 5 0 0 0 - - -;
+#X floatatom 110 141 5 0 0 0 - - -;
+#X floatatom 160 141 5 0 0 0 - - -;
+#X floatatom 210 141 5 0 0 0 - - -;
+#X floatatom 110 161 5 0 0 0 - - -;
+#X floatatom 160 161 5 0 0 0 - - -;
+#X floatatom 210 161 5 0 0 0 - - -;
+#X obj 110 285 outlet;
+#X obj 110 29 inlet;
+#X obj 110 59 unpack 0 0 0 0 0 0 0 0 0;
+#X obj 146 195 t b f;
+#X obj 189 196 t b f;
+#X obj 231 196 t b f;
+#X obj 273 195 t b f;
+#X obj 316 195 t b f;
+#X obj 362 195 t b f;
+#X obj 406 195 t b f;
+#X obj 456 195 t b f;
+#X connect 0 0 10 0;
+#X connect 1 0 0 0;
+#X connect 2 0 13 0;
+#X connect 3 0 14 0;
+#X connect 4 0 15 0;
+#X connect 5 0 16 0;
+#X connect 6 0 17 0;
+#X connect 7 0 18 0;
+#X connect 8 0 19 0;
+#X connect 9 0 20 0;
+#X connect 11 0 12 0;
+#X connect 12 0 1 0;
+#X connect 12 1 2 0;
+#X connect 12 2 3 0;
+#X connect 12 3 4 0;
+#X connect 12 4 5 0;
+#X connect 12 5 6 0;
+#X connect 12 6 7 0;
+#X connect 12 7 8 0;
+#X connect 12 8 9 0;
+#X connect 13 0 0 0;
+#X connect 13 1 0 1;
+#X connect 14 0 0 0;
+#X connect 14 1 0 2;
+#X connect 15 0 0 0;
+#X connect 15 1 0 3;
+#X connect 16 0 0 0;
+#X connect 16 1 0 4;
+#X connect 17 0 0 0;
+#X connect 17 1 0 5;
+#X connect 18 0 0 0;
+#X connect 18 1 0 6;
+#X connect 19 0 0 0;
+#X connect 19 1 0 7;
+#X connect 20 0 0 0;
+#X connect 20 1 0 8;
+#X coords 0 -1 1 1 150 80 1 100 100;
+#X restore 253 445 pd mapMatrix;
+#X obj 100 375 pix_opencv_warpperspective;
+#X obj 306 246 list prepend srcMatrix;
+#X obj 306 265 list trim;
+#X text 312 528 <-- transform into a 4x4;
+#X text 337 538 openGL transpose matrix;
+#X text 194 620 <-- some stuff to convert;
+#X text 219 630 between OpenCV and OpenGL;
+#X text 213 640 coordinates system;
+#X text 186 599 |;
+#X text 186 608 |;
+#X text 186 617 |;
+#X text 186 626 |;
+#X text 186 635 |;
+#X text 501 502 pix_opencv_wapperspective finds the transformation
+matrix between srcMatrix and dstMatrix;
+#X text 502 594 pix_opencv_findchessboardcorners finds chessboard corners
+in the incomming image stream and send out corners coordinates as a
+list trought its second outlet;
+#N canvas 743 388 715 644 generates_coords 1;
+#X obj 58 2 inlet;
+#X obj 78 251 until;
+#X obj 78 358 f;
+#X msg 96 335 0;
+#X obj 91 118 unpack;
+#X obj 82 462 pack;
+#X obj 78 188 f;
+#X obj 178 251 until;
+#X obj 210 358 f;
+#X msg 228 335 0;
+#X obj 178 287 t b b;
+#X obj 178 188 f;
+#X obj 91 143 t b f;
+#X obj 82 501 list;
+#X obj 58 521 list;
+#X obj 82 482 list prepend;
+#X obj 58 585 outlet;
+#X text 321 358 generates source coordinates to find homography;
+#X obj 58 89 t b l b;
+#X obj 78 208 t f b;
+#X obj 178 208 t f b;
+#X obj 106 358 + 0.25;
+#X obj 238 358 + 0.25;
+#X obj 58 545 list prepend dstMatrix;
+#X obj 58 565 route list;
+#X obj 58 21 route patternSize;
+#X floatatom 327 253 5 0 0 0 - - -;
+#X obj 291 296 t b f;
+#X obj 210 427 + 4;
+#X obj 82 425 +;
+#X floatatom 254 392 5 0 0 0 - - -;
+#X floatatom 112 394 5 0 0 0 - - -;
+#X msg 337 229 17;
+#X msg 389 228 320;
+#X msg 423 226 240;
+#X obj 337 152 t b b;
+#X obj 346 118 loadbang;
+#X text 262 53 the position of the grid had been choose jsut to fit
+in the Gem window \, but you can enter the real coordinates of the
+grid and place the virtual camera to see it \, this is usefull when
+merging with some other localisation data is needeed.;
+#X obj 57 56 list;
+#X connect 0 0 25 0;
+#X connect 1 0 2 0;
+#X connect 2 0 21 0;
+#X connect 2 0 29 0;
+#X connect 3 0 2 1;
+#X connect 4 0 12 0;
+#X connect 4 1 11 1;
+#X connect 5 0 15 0;
+#X connect 6 0 19 0;
+#X connect 7 0 10 0;
+#X connect 8 0 22 0;
+#X connect 8 0 28 0;
+#X connect 9 0 8 1;
+#X connect 10 0 6 0;
+#X connect 10 1 8 0;
+#X connect 11 0 20 0;
+#X connect 12 0 11 0;
+#X connect 12 1 6 1;
+#X connect 13 0 14 1;
+#X connect 13 0 15 1;
+#X connect 14 0 23 0;
+#X connect 15 0 13 0;
+#X connect 18 0 14 0;
+#X connect 18 1 4 0;
+#X connect 18 2 15 1;
+#X connect 19 0 1 0;
+#X connect 19 1 3 0;
+#X connect 20 0 7 0;
+#X connect 20 1 9 0;
+#X connect 21 0 2 1;
+#X connect 22 0 8 1;
+#X connect 23 0 24 0;
+#X connect 24 0 16 0;
+#X connect 25 0 38 0;
+#X connect 26 0 27 0;
+#X connect 27 0 38 0;
+#X connect 27 1 22 1;
+#X connect 27 1 21 1;
+#X connect 28 0 5 1;
+#X connect 29 0 5 0;
+#X connect 30 0 28 1;
+#X connect 31 0 29 1;
+#X connect 32 0 26 0;
+#X connect 33 0 31 0;
+#X connect 34 0 30 0;
+#X connect 35 0 32 0;
+#X connect 35 1 33 0;
+#X connect 35 1 34 0;
+#X connect 36 0 35 0;
+#X connect 38 0 18 0;
+#X restore 100 355 pd generates_coords;
+#X msg 548 135 reset \, title 05_perspective_correction \, dimen 640
+480 \, create \, 1;
+#X obj 70 448 pix_texture;
+#X obj 70 317 spigot;
+#X obj 142 317 spigot 1;
+#X obj 80 273 == 0;
+#X obj 80 229 vradio 15 1 0 2 empty empty empty 0 -8 0 10 -262144 -1
+-1 0;
+#X text 97 229 CPU;
+#X text 97 244 GPU;
+#X text 502 529 it sends through its second outlet the 3x3 transformation
+matrix;
+#X text 501 556 it also apply the tansformation matrix on incomming
+image stream but you can apply it in OpenGL \, result is even better
+;
+#X text 502 643 it also draws found corners on the image stream;
+#X text 504 666 here the coordinates of found corners are used as a
+scrMatrix for pix_opencv_warpperspective;
+#X obj 493 390 cnv 15 370 100 empty empty empty 20 12 0 14 -261234
+-66577 0;
+#X text 508 399 this patch demonstrates how to correct perspective
+with pix_opencv_warpperspective and pix_opencv_findchessboardcorners
+;
+#X text -18 0 declare path to be sure externals were found...;
+#X text 508 440 use the other patch to move the chessboard;
+#X text 354 95 <-- receive image from subprocess.pd;
+#X obj 207 159 pix_flip;
+#X text 102 162 the flip flag;
+#X text 102 172 this is a bug;
+#X text 184 159 -->;
+#X obj 180 136 t a a;
+#X connect 0 0 1 0;
+#X connect 1 0 13 0;
+#X connect 2 0 74 0;
+#X connect 2 0 73 0;
+#X connect 2 1 37 0;
+#X connect 2 1 35 0;
+#X connect 2 1 36 0;
+#X connect 2 1 34 0;
+#X connect 2 1 56 0;
+#X connect 4 0 39 0;
+#X connect 7 0 6 0;
+#X connect 8 0 9 0;
+#X connect 11 0 10 0;
+#X connect 12 0 2 0;
+#X connect 12 0 70 0;
+#X connect 13 0 92 0;
+#X connect 16 0 17 0;
+#X connect 16 1 18 0;
+#X connect 19 0 20 0;
+#X connect 19 1 21 0;
+#X connect 22 0 23 0;
+#X connect 22 1 24 0;
+#X connect 25 0 26 0;
+#X connect 25 1 27 0;
+#X connect 30 0 12 0;
+#X connect 34 0 25 0;
+#X connect 35 0 19 0;
+#X connect 36 0 22 0;
+#X connect 37 0 16 0;
+#X connect 39 0 71 0;
+#X connect 39 1 7 0;
+#X connect 39 2 5 0;
+#X connect 42 0 47 1;
+#X connect 43 0 47 2;
+#X connect 44 0 51 0;
+#X connect 44 0 52 0;
+#X connect 45 0 48 0;
+#X connect 46 0 41 0;
+#X connect 47 0 45 0;
+#X connect 48 0 50 0;
+#X connect 49 0 47 0;
+#X connect 50 0 46 0;
+#X connect 51 0 42 0;
+#X connect 52 0 43 0;
+#X connect 53 0 45 1;
+#X connect 54 0 53 0;
+#X connect 55 0 8 0;
+#X connect 55 1 54 0;
+#X connect 56 0 57 0;
+#X connect 57 0 55 0;
+#X connect 70 0 55 0;
+#X connect 71 0 10 0;
+#X connect 72 0 49 0;
+#X connect 73 0 72 0;
+#X connect 74 0 55 0;
+#X connect 75 0 74 1;
+#X connect 76 0 75 0;
+#X connect 76 0 73 1;
+#X connect 92 0 2 0;
+#X connect 92 1 88 0;
diff --git a/examples/05_perspective_correction/pattern.png b/examples/05_perspective_correction/pattern.png
new file mode 100644
index 0000000..5227c91
--- /dev/null
+++ b/examples/05_perspective_correction/pattern.png
Binary files differ
diff --git a/examples/05_perspective_correction/subprocess.pd b/examples/05_perspective_correction/subprocess.pd
new file mode 100644
index 0000000..55b53ac
--- /dev/null
+++ b/examples/05_perspective_correction/subprocess.pd
@@ -0,0 +1,73 @@
+#N canvas 745 670 837 384 10;
+#X obj 313 153 gemhead;
+#X obj 313 198 pix_image;
+#X msg 374 162 open pattern.png;
+#X obj 313 218 pix_texture;
+#X obj 374 142 loadbang;
+#X obj 313 288 translateXYZ;
+#X obj 313 308 rotateXYZ;
+#X obj -60 342 gemwin;
+#X obj 313 328 scaleXYZ;
+#X obj -61 72 t b a;
+#X obj -61 122 pix_grey;
+#X obj -61 53 gemhead 100;
+#X obj 313 238 pix_info ________;
+#X obj 313 348 rectangle 1 1;
+#X obj -61 142 pix_share_write 666 640 480 1;
+#X obj -60 222 loadbang;
+#X msg -33 264 \; pd dsp 1;
+#X obj -60 241 t b b;
+#X text 27 268 <- dsp must always be ON;
+#X text 44 278 inside a pd~;
+#X obj 327 264 /;
+#X text 351 264 <-- keep image ratio;
+#X obj -61 102 pix_snap 0 0 640 480;
+#X msg -18 342 destroy;
+#X msg -60 311 reset \, color 1 1 1 \, title subprocess \, dimen 640
+480 \, create \, 1;
+#X text -60 32 readback and send to host;
+#X text 334 54 the chessboard should be big enougth and not too warp
+in order to detect corners;
+#X text 334 16 move the chessboard in the subprocess wiev it shouldn't
+move in the 05_perspective_correction window;
+#X obj 577 105 nbx 5 14 -1e+37 1e+37 0 1 empty empty posX 0 -8 0 10
+-262144 -1 -1 0.01 256;
+#X obj 637 105 nbx 5 14 -1e+37 1e+37 0 1 empty empty posY 0 -8 0 10
+-262144 -1 -1 -0.77 256;
+#X obj 609 177 nbx 5 14 -1e+37 1e+37 0 1 empty empty scale 0 -8 0 10
+-262144 -1 -1 2.22 256;
+#X obj 547 142 nbx 5 14 -1e+37 1e+37 0 1 empty empty rotX 0 -8 0 10
+-262144 -1 -1 26.62 256;
+#X obj 607 142 nbx 5 14 -1e+37 1e+37 0 1 empty empty rotY 0 -8 0 10
+-262144 -1 -1 12.15 256;
+#X obj 667 141 nbx 5 14 -1e+37 1e+37 0 1 empty empty rotZ 0 -8 0 10
+-262144 -1 -1 -157.27 256;
+#X connect 0 0 1 0;
+#X connect 1 0 3 0;
+#X connect 2 0 1 0;
+#X connect 3 0 12 0;
+#X connect 4 0 2 0;
+#X connect 5 0 6 0;
+#X connect 6 0 8 0;
+#X connect 8 0 13 0;
+#X connect 9 0 22 0;
+#X connect 9 1 22 0;
+#X connect 10 0 14 0;
+#X connect 11 0 9 0;
+#X connect 12 0 5 0;
+#X connect 12 1 20 0;
+#X connect 12 2 20 1;
+#X connect 15 0 17 0;
+#X connect 17 0 24 0;
+#X connect 17 1 16 0;
+#X connect 20 0 13 1;
+#X connect 22 0 10 0;
+#X connect 23 0 7 0;
+#X connect 24 0 7 0;
+#X connect 28 0 5 1;
+#X connect 29 0 5 2;
+#X connect 30 0 8 2;
+#X connect 30 0 8 1;
+#X connect 31 0 6 1;
+#X connect 32 0 6 2;
+#X connect 33 0 6 3;