Quantcast
Channel: Arduino - Processing 2.x and 3.x Forum
Viewing all articles
Browse latest Browse all 747

Moving a servo with camera motion detection.

$
0
0

Hello there, I follow the community since a couple of year, I usually found all the answers to my questions just lookin up for them, but this time I needed to write my first post. :) I'm workin on a university project in which I need to move a camera on x and y axes through two servos, one axis each, following the movement the camera detect...

I basically used the LiveCam example from OpenCV Github https://github.com/atduskgreg/opencv-processing/tree/master/examples/LiveCamTest

which does face recognition and tells the X position in the frame (I dont know why, but gives just 0-1 as Y position) I linked the values of faces[i].x and faces[i].y to the servo rotation angle (quite randomly, just for testing the connection to Arduino).

import gab.opencv.*;

import processing.video.*;

import java.awt.*;

import processing.serial.*;

import cc.arduino.*;

Capture video;

OpenCV opencv;

Arduino arduino;

void setup() {

size(640, 480);

arduino = new Arduino(this, Arduino.list()[0], 57600);

arduino.pinMode(4, Arduino.SERVO);

video = new Capture(this, 640/2, 480/2,30);

opencv = new OpenCV(this, 640/2, 480/2);

opencv.loadCascade(OpenCV.CASCADE_FRONTALFACE);

video.start();

}

void draw() {

scale(2);

opencv.loadImage(video);

image(video, 0, 0 );

noFill();

stroke(0, 255, 0);

strokeWeight(3);

Rectangle[] faces = opencv.detect();

println(faces.length);

for (int i = 0; i < faces.length; i++) {

println(faces[i].x + "," + faces[i].y);

rect(faces[i].x, faces[i].y, faces[i].width, faces[i].height);

arduino.servoWrite(4, constrain(180 - faces[i].x, 0, 180));

arduino.servoWrite(5, constrain(faces[i].y, 180, 0)); }

}

void captureEvent(Capture c) {

c.read(); }

My main question is: How to interface the detection on the 180º on x and y... I mean, it would be quite easy to calibrate it on a static frame, the problem comes when the camera is moving following the "target" movement and has to continue following it through the 180º. (Probably telling it to keep the subject centered?)

the secondary questions are: Face detection is a s**t for my purpose... I mean, if the face is not watching to the camera, it doesn't detect it. So I think I'll need to use something like Blob detection, based on movement and here comes others complication: First of all, I can't link other examples to live camera but face detection... then: Using some kind of Motion detection, will it get confuse having a moving camera?

Hope that everything is quite clear... thanks for your time. :)


Viewing all articles
Browse latest Browse all 747

Latest Images

Trending Articles



Latest Images