Flip Webcam opencv

edited June 2017 in Kinect

Hi, as you can see from the code I was able to reverse the webcam, but how do I make the opencv with the webcam flipped? I would like to do face detection on the flip webcam

`import processing.video.*; import gab.opencv.*; import java.awt.Rectangle;

Capture cam; OpenCV opencv;

void setup() { size(640, 480);

cam = new Capture(this, width, height, 30); opencv = new OpenCV(this, width, height); opencv.loadCascade(OpenCV.CASCADE_FRONTALFACE);
cam.start(); }

void draw() { if (cam.available() == true) { cam.read(); }

pushMatrix(); scale(-1, 1); translate(-cam.width, 0); image(cam, 0, 0); popMatrix();

opencv.loadImage(cam); Rectangle[] faces = opencv.detect();

noFill(); stroke(0, 255, 0); strokeWeight(3); for (int i = 0; i < faces.length; i++) { rect(faces[i].x, faces[i].y, faces[i].width, faces[i].height); } }`

Answers

  • Your faces[i].x values run from 0 to width. You want then to run from width to 0.

    cam.width - faces[i].x
    

    Further, you want to indicate the left corner of the rectangle -- but if you flip it, you are now indicating the right corner instead, so you also need to adjust by faces[i].width.

    cam.width - faces[i].x - faces[i].width
    

    So something like this (untested):

    rect(cam.width - faces[i].x - faces[i].width, faces[i].y, faces[i].width, faces[i].height);
    
  • Edit your post (gear icon in the top right corner of your post), select your code and hit ctrl+o to format your code. Make sure there is an empty line above and below your code

    Kf

Sign In or Register to comment.