Focussing a webcam on two specific points

Mar 24, 2008 at 10:39pm

Focussing a webcam on two specific points

Hi, I’m going to have a good search of the forum for help after this so apologies if it has already been covered but it’s very important so I wanted to get a post up early!

I am working on a part of a group project for my Masters and need a little help getting a game (similar to pong) working.

I have most things sorted but the thing I need help with is how to tell my webcam to focus in on two different specified regions onscreen at the same time.

Basically it is so that it can monitor two opposite rectangles (represented in real life by two coloured rectangles on the floor) in which the two players of the game will stand. The patch will then read the movement of the player up and down in their rectangle which will perform a variety of functions.

I assume there is some simple object that allows you to focus a window on just one part of the cams view, or at least I hope so!

I was originally going to use colour tracking to focus on them (which works to an extent) but then I realised that since the colours it was tracking were always static there must be a better way (to avoid flickering etc when using colour tracking).

Thanks in advance for any help:)

#36493
Mar 25, 2008 at 1:12am

Sounds like jit.scissors would do the trick, if you just need to work with two separate areas from your webcam.

cv.jit.blobs externals would be good if you need to be specific with tracking the movements within the separated areas.

http://www.iamas.ac.jp/~jovan02/cv/download.html

#125305
Mar 25, 2008 at 2:00am

This might help. You could even use jit.findbounds to give you the
coordinates of your coloured rectangles, then enter them into the
number boxes in the patch below. hope that helps

max v2;
#N vpatcher 34 89 679 661;
#P window setfont “Sans Serif” 9.;
#P window linecount 1;
#P message 145 51 33 196617 close;
#P comment 370 224 100 196617 bottom right corner;
#P comment 267 223 76 196617 top left corner;
#P user jit.pwindow 35 136 82 62 0 1 0 0 1 0;
#P user jit.pwindow 255 395 82 62 0 1 0 0 1 0;
#P user jit.pwindow 43 391 82 62 0 1 0 0 1 0;
#P number 203 246 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 162 246 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 100 249 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 57 248 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 163 269 52 196617 pak 0 0;
#P newex 56 275 54 196617 pak 0 0;
#P message 163 296 86 196617 srcdimend $1 $2;
#P message 56 297 94 196617 srcdimstart $1 $2;
#P number 414 248 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 373 248 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 311 251 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 268 250 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 374 271 52 196617 pak 0 0;
#P newex 267 277 54 196617 pak 0 0;
#P message 374 298 86 196617 srcdimend $1 $2;
#P message 267 299 94 196617 srcdimstart $1 $2;
#P newex 255 332 121 196617 jit.matrix @usesrcdim 1;
#P newex 44 330 121 196617 jit.matrix @usesrcdim 1;
#P newex 47 72 52 196617 metro 30;
#P toggle 47 43 15 0;
#P message 108 52 30 196617 open;
#P newex 47 99 56 196617 jit.qt.grab;
#P comment 65 203 100 196617 rectangle 1;
#P comment 269 201 100 196617 rectangle 2;
#P comment 59 226 79 196617 top left corner;
#P comment 160 223 100 196617 bottom right corner;
#P window linecount 4;
#P comment 185 134 100 196617 enter the x , y coordinates of your
rectangles into the number boxes;
#P connect 5 0 29 0;
#P connect 5 0 9 0;
#P fasten 20 0 9 0 168 321 49 321;
#P fasten 19 0 9 0 61 322 49 322;
#P connect 9 0 27 0;
#P connect 7 0 8 0;
#P fasten 32 0 5 0 150 93 52 93;
#P fasten 6 0 5 0 113 93 52 93;
#P connect 8 0 5 0;
#P connect 23 0 21 0;
#P connect 21 0 19 0;
#P connect 24 0 21 1;
#P connect 25 0 22 0;
#P connect 22 0 20 0;
#P connect 26 0 22 1;
#P fasten 5 0 10 0 52 124 260 124;
#P fasten 12 0 10 0 379 320 260 320;
#P connect 11 0 10 0;
#P connect 10 0 28 0;
#P connect 15 0 13 0;
#P connect 13 0 11 0;
#P connect 16 0 13 1;
#P connect 17 0 14 0;
#P connect 14 0 12 0;
#P connect 18 0 14 1;
#P pop;

On Mar 24, 2008, at 10:39 PM, Ben Thompson wrote:

>
> Hi, I’m going to have a good search of the forum for help after
> this so apologies if it has already been covered but it’s very
> important so I wanted to get a post up early!
>
> I am working on a part of a group project for my Masters and need a
> little help getting a game (similar to pong) working.
>
> I have most things sorted but the thing I need help with is how to
> tell my webcam to focus in on two different specified regions
> onscreen at the same time.
>
> Basically it is so that it can monitor two opposite rectangles
> (represented in real life by two coloured rectangles on the floor)
> in which the two players of the game will stand. The patch will
> then read the movement of the player up and down in their rectangle
> which will perform a variety of functions.
>
> I assume there is some simple object that allows you to focus a
> window on just one part of the cams view, or at least I hope so!
>
> I was originally going to use colour tracking to focus on them
> (which works to an extent) but then I realised that since the
> colours it was tracking were always static there must be a better
> way (to avoid flickering etc when using colour tracking).
>
> Thanks in advance for any help:)

#125306
Mar 26, 2008 at 1:05am

jit.submatrix might be useful too…

#125307
Mar 26, 2008 at 2:36am

awesome thanks guys! I’m working with jit.scissors at the moment and seems to be going well. I basically cut the screen into 4 rows of 6 columns and then just took the left and right most columns as my “player areas” and applied motion detection on each square.

Basically meaning that the patch can read in where the player is in 4 different zones within his column and then relay this data to the Open GL part which sends a ball bouncing back and forth between the players (a bit like pong).

Thanks again for your quick responses guys, i’m extremely grateful!

#125308

You must be logged in to reply to this topic.