Processing + OpenCV trouble
in
Contributed Library Questions
•
2 years ago
Hi Processers,
First of all I am a complete noob, so sorry if my question seems really stupid or hard to answer.
What am I trying to do is the following:
For my gradutation project I am working with my own music, I want to make an original graphical application or something really fun to do. So I stumbled on Reactivision and the recognition of fiducials with a lot of possibilities.
Currently I am trying something very basic which doesn't seem to work at all, no matter what I try: the fiducials will be recognized through Processing, starting up an image. If I'll be able to do this, I can work with sound and movies. An image just seemed something very easy to start with. I found this tutorial online of people who used the same principal in a presentation.
So I adjusted the code to what I'm trying to do and came up with this:
But as they say in the tutorial, the code is made up very quick in one afternoon because they didn't have enough time. Therefore the code is very difficult and confusing, which doesn't make it easier for me. As I expected my code doesn't work, the only thing I can do is show my fiducials through the webcam on Reactivision and Processing at the same time, Reactivision recognizes them but Processing doesn't do anything.
Does anybody know what I'm doing wrong?
Thanks in advance, Caroline
First of all I am a complete noob, so sorry if my question seems really stupid or hard to answer.
What am I trying to do is the following:
For my gradutation project I am working with my own music, I want to make an original graphical application or something really fun to do. So I stumbled on Reactivision and the recognition of fiducials with a lot of possibilities.
Currently I am trying something very basic which doesn't seem to work at all, no matter what I try: the fiducials will be recognized through Processing, starting up an image. If I'll be able to do this, I can work with sound and movies. An image just seemed something very easy to start with. I found this tutorial online of people who used the same principal in a presentation.
So I adjusted the code to what I'm trying to do and came up with this:
- import ddf.minim.*;
- import ddf.minim.signals.*;
- import ddf.minim.analysis.*;
- import ddf.minim.effects.*;
- import hypermedia.video.*;
- import processing.video.*;
- import TUIO.*;
- import java.util.*;
- //Capture myCapture;
- OpenCV opencv;
- Minim minim;
- AudioPlayer s7;
- PImage p0;
- int W = 640;
- int H = 480;
- float wmax;
- float hmax;
- Hashtable playing;
- TuioProcessing tuioClient;
- void setup(){
- size(W,H);
- wmax = W/2;
- hmax = H/2;
- frameRate(30);
- playing = new Hashtable();
- minim = new Minim(this);
- tuioClient = new TuioProcessing(this);
- initContent();
- opencv = new OpenCV( this );
- opencv.capture( width, height );
- //myCapture = new Capture(this, width, height, 30);
- p0 = loadImage("p0.jpg");
- }
- void captureEvent(Capture myCapture) {
- //myCapture.read();
- }
- void draw(){
- //image(myCapture, 0, 0);
- opencv.read();
- image( opencv.image(), 0, 0 );
- Vector tuioObjectList = tuioClient.getTuioObjects();
- for (int i=0;i<tuioObjectList.size();i++) {
- TuioObject tobj = (TuioObject)tuioObjectList.elementAt(i);
- String sid = "" + tobj.getSymbolID();
- if(playing.get( sid )==null ){
- playing.put(sid,"N");
- }
- String pstate = (String) playing.get( sid );
- if(pstate.equals("S")){
- float ww;
- float hh;
- float p = 1;
- float p2 = 1;
- if( sid.equals("0") ){
- ww = p0.width;
- hh = p0.height;
- if(ww>wmax){
- p = ww/wmax;
- }
- if(hh>hmax){
- p2 = hh/hmax;
- if(p2>p){
- p = p2;
- }
- }
- ww = ww/p;
- hh = hh/p;
- image(p0,tobj.getScreenX(width)-ww/2,tobj.getScreenY(height)-hh/2,ww,hh);
- }
- }
- }
- }
- void addTuioObject(TuioObject tobj){
- String sid = "" + tobj.getSymbolID();
- if(playing.get( sid )==null ){
- playing.put(sid,"N");
- }
- String pstate = (String) playing.get( sid );
- if(pstate.equals("N")){
- playing.put(sid,"S");
- if(sid.equals("0")){
- }
- }
- }
- void removeTuioObject(TuioObject tobj){
- String sid = "" + tobj.getSymbolID();
- if(playing.get( sid )==null ){
- playing.put(sid,"N");
- }
- String pstate = (String) playing.get( sid );
- if(pstate.equals("S")){
- playing.put(sid,"N");
- if(sid.equals("0")){
- } else if(sid.equals("1")){
- }
- }
- }
- void updateTuioObject(TuioObject tobj){
- }
- void refresh(TuioTime bundleTime){
- }
- void stop(){
- opencv.stop();
- s7.close();
- minim.stop();
- super.stop();
- }
- void addTuioCursor(TuioCursor tcur){}
- void removeTuioCursor(TuioCursor tcur) {}
- void updateTuioCursor(TuioCursor tcur) {}
- void initContent(){
- s7 = minim.loadFile("7.wav", 2048);
- //s7.loop();
- //s7.setVolume(0);
- }
- void movieEvent(Movie m) {
- m.read();
- }
But as they say in the tutorial, the code is made up very quick in one afternoon because they didn't have enough time. Therefore the code is very difficult and confusing, which doesn't make it easier for me. As I expected my code doesn't work, the only thing I can do is show my fiducials through the webcam on Reactivision and Processing at the same time, Reactivision recognizes them but Processing doesn't do anything.
Does anybody know what I'm doing wrong?
Thanks in advance, Caroline
1