Motion tracking a marker using a webcam

36 views (last 30 days)
Alysia
Alysia on 19 Nov 2025 at 12:13
Commented: William Rose on 23 Nov 2025 at 5:52
I have absolutely no coding experience. I am making interactive artwork for a uni project and plan on using a paintbrush's movement to compose music. It would act somewhat similar to a theremin with x coordinates being the notes and y being the dynamics.
I need to motion capture a marker on a paintbrush and get the x and y coordinates. I am also wondering if its possible to track the speed of the movement? I'd like to use this as a parameter for perhaps changing the tonality of the instrument with faster being harsher? I'm unsure at this poin in the project. I have a very limited budget so im just using a normal camera.
Any advice would be greatly appreciated, thank you!

Answers (2)

Image Analyst
Image Analyst on 22 Nov 2025 at 23:30
@Alysia, see attached demo where I track a green Sharpie marker in a video. You'll have to adapt it to use getsnapshot to get live video instead of a previously recorded video. You'll need lots of other customization for your particular use case so I recommend you learn MATLAB.
To learn fundamental concepts, invest 2 hours of your time here:
  1 Comment
William Rose
William Rose on 23 Nov 2025 at 5:52
This is impressive. I have learned a lot from @Image Analyst's posts and File Exchange contributions.

Sign in to comment.


William Rose
William Rose on 19 Nov 2025 at 15:21
Edited: William Rose on 20 Nov 2025 at 3:30
Alysia,
[Edit: correct typos.]
This sounds like a great project!
Tracking the x-y coordinates of the paintbrush will be the hard part. Once you have that data, the rest will be relatively easy, including computing the velocity. As you know, a theramin has two antennas: one for volume and one for pitch. Your proposal to use x,y in a similar way makes sense. You suggest using velocity to control the "tonality of the instrument" or "harshness". No doubt you know more about music than I. Your use of "tonality" to refer to a single instrument is different than what I'm used to. I think of tonality as referring to the use, or not, of a diatonic scale or mode (major, minor, phrygian, locrian), or to the greater use of tones that are not part of a diatonic scale (chromaticism). But I think I know what you mean by harshness. Some people consider the oboe to be more harsh than the clarinet. You could try to achieve different "harshnesses" by using velocity to adjust the overtones associated with each pitch.
To track the x,y coordinates of the brush using a cell phone video, you'll want a marker on the brush that stands out so it is trackable. Maybe a white dot painted on the brush, or a small white sphere glued onto the brush. But if the canvas is white, it will still be hard to track. I suggest you have the painter wear black, darken their painting hand, and paint on a black canvas with a dark tarp hung behind the easel, so that the only bright thing in the video is the white dot on the brush. This will make it easier to track the brush marker in the video. If you or a friend is facile with electronics, you could attach a bright LED (such as this) to the brush to make it stand out in a more normal painting environment. Power the LED with 4 AA batteries in series (6V), two wires running to the LED, and a 150 ohm resistor to get ~20 mA through the LED {(6V-3.2V forward drop)/150 ohm = 0.019 amps.}
  4 Comments
Alysia
Alysia on 21 Nov 2025 at 9:26
This is so incredibly helpful! Thank you so much, I can definitely try using an LED marker. And yes I think i'll refrain from making this a live project. Would you mind if I used these graphs you made in my planning essay? I'd cite you of course but no worries if not. Again thank you!
William Rose
William Rose on 22 Nov 2025 at 5:33
@Alysia, you're welcome. You are welcome to use what isposted above, and thank you for citing. If you want to discuss it further offline, click the "WR" next to my postings, then click the envelope icon to send a secure message. I have some motion capture experience.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!