Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » How do I make something go where my hand goes on the webcam?
- designsquadlover
- Scratcher
59 posts
How do I make something go where my hand goes on the webcam?
So, I'm making a game where you have to use the webcam to control something that hits stuff, and I was wondering how to make it go where my hand goes on the webcam. Please help, bye.
when green flag clicked
forever
say [HELP!!!!!!] for (2) secs
end
- adsuri
- Scratcher
1000+ posts
How do I make something go where my hand goes on the webcam?
when green flag clicked
turn video [on v]
forever
go to (video [motion v] on [this sprite v])
end
Last edited by adsuri (July 31, 2018 13:31:05)
- ScratchDiogoh
- Scratcher
1000+ posts
How do I make something go where my hand goes on the webcam?
when green flag clicked
forever
turn video [on v]
if <(video [video v] on [Stage v]) > (...::grey)> then // hand size
...
end
end
- designsquadlover
- Scratcher
59 posts
How do I make something go where my hand goes on the webcam?
Thanks!
- DerpyHead0
- Scratcher
1000+ posts
How do I make something go where my hand goes on the webcam?
this doesn't work:
and this is literally impossible to do:when green flag clicked
turn video [on v]
forever
go to (video [motion v] on [this sprite v])
end
also, i don't think this is actually possible unless you have a bunch of clones all over the stage, to basically make a grid, and even then, it can only go to motion, not your hand.when green flag clicked
forever
turn video [on v]
if <(video [video v] on [Stage v]) > (...::grey)> then // hand size
...
end
end
Last edited by DerpyHead0 (July 31, 2018 22:01:29)
- mstone326
- Scratcher
1000+ posts
How do I make something go where my hand goes on the webcam?
See if this helps. Wave on the left sensor and and on the right sensor.
https://scratch.mit.edu/projects/237906575/
https://scratch.mit.edu/projects/237906575/
- TheLogFather
- Scratcher
1000+ posts
How do I make something go where my hand goes on the webcam?
Scratch can only detect *motion* on a sprite/clone (or stage). It cannot directly ‘follow’ some specific object.
You can use the motion detected on the stage as a simplistic form of controlling a sprite – something like this, for example:
Note that above is simply detecting *any* motion over the whole of the stage – you can move your head, your hand, or even pick up the laptop and move it around so the whole background moves!
As DerpyHead0 suggested above, it's possible to use the motion-detection across a grid of clones to try to do some very crude following of a slow-moving object (as long as it's the *only* thing moving in that region).
Here's my attempt at head-tracking, for example:
https://scratch.mit.edu/projects/72290026/
Note that it really has no idea if what it's following is your head, or your hand, or some other thing – it's just making huge assumptions that you've followed the ‘rules’, put your head where you're meant to, moving it around not too quickly, and not got anything else moving around there…
One thing to note about motion-detection on a sprite/clone is that it's more expensive for larger costumes because it has to look at motion across the pixels of the costume. (That's why I used very small costumes for the detector clones in my project above.)
Conversely, though, the accuracy of the direction of detected motion becomes bad as the costume gets smaller – since there are fewer pixels for it figure out what's happening. (That's why I ignore the motion direction in the detector clones in the above project – it's unreliable.)
Finally, note that motion-detection is an expensive operation, so it'll slow down the frame-rate of the project – especially so if the lighting is not high. It's a really good idea to tell users of your project to make sure they are very well lit before running the project.
Hope that gives some ideas – and good luck!
You can use the motion detected on the stage as a simplistic form of controlling a sprite – something like this, for example:
when GF clicked
set [Scale v] to [0.4] // this seems to give a reasonable speed for me
set [Tolerance v] to [35] // this stops it moving when motion is small
go to x:(0) y:(0)
turn video [on v]
forever
set [Stop time v] to (timer) // see the "when timer" script below
move by ((Scale)*((video [motion v] on [Stage v])-(Tolerance))) with angle (video [direction v] on [Stage v])
end
define move by (dist) with angle (dir)
if <(dist)>[0]> then // only move if enough motion was detected
change x by ((dist)*([sin v] of (dir)))
change y by ((dist)*([cos v] of (dir)))
end
when [timer v] > ((Stop time) + (0.5)) // A trick to turn off video after stop clicked
turn video [off v]
Note that above is simply detecting *any* motion over the whole of the stage – you can move your head, your hand, or even pick up the laptop and move it around so the whole background moves!
As DerpyHead0 suggested above, it's possible to use the motion-detection across a grid of clones to try to do some very crude following of a slow-moving object (as long as it's the *only* thing moving in that region).
Here's my attempt at head-tracking, for example:
https://scratch.mit.edu/projects/72290026/
Note that it really has no idea if what it's following is your head, or your hand, or some other thing – it's just making huge assumptions that you've followed the ‘rules’, put your head where you're meant to, moving it around not too quickly, and not got anything else moving around there…
One thing to note about motion-detection on a sprite/clone is that it's more expensive for larger costumes because it has to look at motion across the pixels of the costume. (That's why I used very small costumes for the detector clones in my project above.)
Conversely, though, the accuracy of the direction of detected motion becomes bad as the costume gets smaller – since there are fewer pixels for it figure out what's happening. (That's why I ignore the motion direction in the detector clones in the above project – it's unreliable.)
Finally, note that motion-detection is an expensive operation, so it'll slow down the frame-rate of the project – especially so if the lighting is not high. It's a really good idea to tell users of your project to make sure they are very well lit before running the project.
Hope that gives some ideas – and good luck!
Last edited by TheLogFather (Aug. 1, 2018 00:41:05)
- adsuri
- Scratcher
1000+ posts
How do I make something go where my hand goes on the webcam?
I know it was the only idea I could think of then. this doesn't work:and this is literally impossible to do: -snip-also, i don't think this is actually possible unless you have a bunch of clones all over the stage, to basically make a grid, and even then, it can only go to motion, not your hand. -snip-
Last edited by adsuri (Aug. 1, 2018 16:04:11)
- Discussion Forums
- » Help with Scripts
- » How do I make something go where my hand goes on the webcam?