How to kinect Interact with mac Webcam


I have been watching Lewis Lepton’s tutorial on interact lines kinect: openFrameworks tutorial series - episode 049 - interact lines kinect - YouTube

But the source code seems to only work with an external camera.

What would I need to do to control the lines drawn using a webcam from Macbook?

Below is the code:



you can call ofVideoGrabber and use the internal camera. have a look at the example in examples/video/videograbber.

a quick change to @lewislepton 's elegant code will run like this

#include "ofMain.h"

class ofApp : public ofBaseApp{

		void setup();
		void update();
		void draw();

		void keyPressed(int key);
		void keyReleased(int key);
		void mouseMoved(int x, int y );
		void mouseDragged(int x, int y, int button);
		void mousePressed(int x, int y, int button);
		void mouseReleased(int x, int y, int button);
		void mouseEntered(int x, int y);
		void mouseExited(int x, int y);
		void windowResized(int w, int h);
		void dragEvent(ofDragInfo dragInfo);
		void gotMessage(ofMessage msg);
    ofVideoGrabber cam;


#include "ofApp.h"

void ofApp::setup(){
    cam.setup(640, 480);

void ofApp::update(){

void ofApp::draw(){
    cam.draw(0, 0, 640, 480);
      for (int i = 0; i < cam.getWidth(); i += 16) {
        for (int j = 0; j < cam.getHeight(); j += 16) {
          ofColor color = cam.getPixels().getColor(i, j);
            float brightness = color.r; // hack to just use brightness of redchannel
          ofTranslate(i, j);
          ofRotateZDeg(ofMap(brightness, 0, 255, 0, 360));
    //      ofSetLineWidth(ofMap(brightness, 0, 255, 16, 0));
          ofDrawLine(0 - 8, 0, 0 + 8, 0);
          ofDrawLine(0, 0 - 8, 0, 0 + 8);

if you need to select a different camera plugged into your machine you can use


to see what is plugged in (see the example for aan easy way to print these to a console output)

then use


to whatever device number you want to choose.


Hi @danb ! Thanks for the informations!

I tried out the code the way you did.
The problem is when I upload the code and run, the line seems to interact with where I am but it is not showing the camera view. I have attached the photo for clarification. I have deleted my old script and tried out the code you wrote out exactly. Do you know what seems to be the problem? would it be the camera on my mac is not accessible?

maybe check what camera you have - some cameras want to run at a different base resolution ( in the cam.setup ) check if the of/examples work - it may be that you need to give permission to the application to access the camera - but if you are able to get the crosses working then check the cam.draw(x,y) as this just draws the camera view to the screen after the update routine calls cam.update

1 Like