We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › Png Frame on top of OpenCV Blobs
Page Index Toggle Pages: 1
Png Frame on top of OpenCV Blobs (Read 1780 times)
Png Frame on top of OpenCV Blobs
Apr 29th, 2010, 11:41pm
 
I am trying to make a concept where the program detects Movement and creates farmed video parts .

As far as now I was able to have the movement detection and video .

Used OpenCV and ControlCP5 libraries .

So any ideas how i can make the blobs stay a bit longer and generate a frame png on top of them

I tried to change the scale and the size of the png but i run in an error of null point or Coordinate out of bounds!

Any ideas

...

here is the code:

Quote:
import hypermedia.video.*;
import java.awt.*;
import controlP5.*;

OpenCV opencv;

int w =640;
int h = 480;
public int threshold = 15;
public int r=255;
public int g=255;
public int b=255;
public int blurLvl=20;
public int contrast_value=2;


public int amountOfBlobs = 20;

PImage[] imgArray = new PImage[amountOfBlobs];
PImage copyimg;



ControlP5 controlP5;

int myColorBackground = color(0,0,0);

ControlWindow controlWindow;




void setup() {
 
 

   size(w, h);
   
   //control
   controlP5 = new ControlP5(this);
 controlP5.setAutoDraw(false);
 controlWindow = controlP5.addControlWindow("controlP5window",100,100,400,200);
 controlWindow.hideCoordinates();
 
 controlWindow.setBackground(color(40));
 //BLOBS-THRESHOLD
 Controller mySlider = controlP5.addSlider("amountOfBlobs",0,20,40,40,100,10);
 mySlider.setWindow(controlWindow);
 Controller mySlider2 = controlP5.addSlider("threshold",0,50,40,50,100,10);
 mySlider2.setWindow(controlWindow);
 //RGB
   Controller mySlider3 = controlP5.addSlider("r",0,255,40,60,100,10);
 mySlider3.setWindow(controlWindow);
   Controller mySlider4 = controlP5.addSlider("g",0,255,40,70,100,10);
 mySlider4.setWindow(controlWindow);
   Controller mySlider5 = controlP5.addSlider("b",0,255,40,80,100,10);
 mySlider5.setWindow(controlWindow);
 //Blur Level
  Controller mySlider6 = controlP5.addSlider("blurLvl",0,255,40,90,100,10);
 mySlider6.setWindow(controlWindow);
 //contrast
 Controller mySlider7 = controlP5.addSlider("contrast_value",0,255,40,100,100,10);
 mySlider7.setWindow(controlWindow);

 //controlP5.addSlider("amountOfBlobs1",0,20,40,40,100,10);
 
 controlWindow.setTitle("Controll");
 
 //end controll

   opencv = new OpenCV( this );
   opencv.capture(w,h);
   opencv.loadImage( "frontwall-small-resized.jpg", width, height );
   

   PImage copyimg = new PImage(w,h);
}

void draw() {

   background(0);
   
    controlP5.draw();
   
   opencv.read();
   opencv.flip(OpenCV.FLIP_HORIZONTAL);

   //copyimg.copy(opencv.image(),0,0,w,h,0,0,w,h);
   copyimg = opencv.image();
 
   
   noTint();
  //image( opencv.image(), 0, 0 );
 //Background image
   image( loadImage("frontwall-small-resized.jpg"), 0, 0);

     opencv.convert( OpenCV.GRAY);
     opencv.contrast( contrast_value );  
     copyimg = opencv.image();
     opencv.absDiff();
     opencv.blur(OpenCV.BLUR, blurLvl);    
     opencv.threshold(threshold);
   //image(opencv.image(),0,0);
   
   Blob[] blobs = opencv.blobs( 80, w*h/3, amountOfBlobs, false);
   
   for( int i=0; i<blobs.length; i++ ) {

       Rectangle bounding_rect      = blobs[i].rectangle;
     
       imgArray[i] = createImage(bounding_rect.width, bounding_rect.height, RGB);
       imgArray[i].copy(copyimg,bounding_rect.x, bounding_rect.y, bounding_rect.width, bounding_rect.height, 0, 0, bounding_rect.width, bounding_rect.height);
       
       
       tint(r,g,b);
       image(imgArray[i],bounding_rect.x, bounding_rect.y);
       
   }

   //frame differencing, remember last frame
   opencv.remember();
   
   //  flipped the image earlier, we need to flip it here too.
   opencv.remember(OpenCV.SOURCE, OpenCV.FLIP_HORIZONTAL);
}




void keyPressed() {
 if(key==',') controlP5.window("controlP5window").hide();
 if(key=='.') controlP5.window("controlP5window").show();
 // controlWindow = controlP5.addControlWindow("controlP5window2",600,100,400,200);
 // controlP5.controller("sliderValue1").moveTo(controlWindow);
}

public void stop() {
   opencv.stop();
   super.stop();
}
Re: Png Frame on top of OpenCV Blobs
Reply #1 - May 2nd, 2010, 12:25am
 
I was able to load the image on top of the blobs but i can not change the size of it to it the blob.

any idea?

here is the code

Quote:
import hypermedia.video.*;
import java.awt.*;
import controlP5.*;

OpenCV opencv;

int w =640;
int h = 480;
public int threshold = 15;
public int r=255;
public int g=255;
public int b=255;
public int blurLvl=20;
public int contrast_value=2;


public int amountOfBlobs = 20;

PImage[] imgArray = new PImage[amountOfBlobs];
PImage copyimg;



ControlP5 controlP5;

int myColorBackground = color(0,0,0);

ControlWindow controlWindow;




void setup() {
 
 

   size(w, h);
   
   //control
   controlP5 = new ControlP5(this);
 controlP5.setAutoDraw(false);
 controlWindow = controlP5.addControlWindow("controlP5window",100,100,400,200);
 controlWindow.hideCoordinates();
 
 controlWindow.setBackground(color(40));
 //BLOBS-THRESHOLD
 Controller mySlider = controlP5.addSlider("amountOfBlobs",0,20,40,40,100,10);
 mySlider.setWindow(controlWindow);
 Controller mySlider2 = controlP5.addSlider("threshold",0,50,40,50,100,10);
 mySlider2.setWindow(controlWindow);
 //RGB
   Controller mySlider3 = controlP5.addSlider("r",0,255,40,60,100,10);
 mySlider3.setWindow(controlWindow);
   Controller mySlider4 = controlP5.addSlider("g",0,255,40,70,100,10);
 mySlider4.setWindow(controlWindow);
   Controller mySlider5 = controlP5.addSlider("b",0,255,40,80,100,10);
 mySlider5.setWindow(controlWindow);
 //Blur Level
  Controller mySlider6 = controlP5.addSlider("blurLvl",0,255,40,90,100,10);
 mySlider6.setWindow(controlWindow);
 //contrast
 Controller mySlider7 = controlP5.addSlider("contrast_value",0,255,40,100,100,10);
 mySlider7.setWindow(controlWindow);

 //controlP5.addSlider("amountOfBlobs1",0,20,40,40,100,10);
 
 controlWindow.setTitle("Controll");
 
 //end controll

   opencv = new OpenCV( this );
   opencv.capture(w,h);
   opencv.loadImage( "frontwall-small-resized.jpg", width, height );
   opencv.loadImage("frame.png",width,height);
   

   PImage copyimg = new PImage(w,h);
}

void draw() {

   background(0);
   
    controlP5.draw();
   
   opencv.read();
   opencv.flip(OpenCV.FLIP_HORIZONTAL);

   //copyimg.copy(opencv.image(),0,0,w,h,0,0,w,h);
   copyimg = opencv.image();
 
   
   noTint();
  //image( opencv.image(), 0, 0 );
   image( loadImage("frontwall-small-resized.jpg"), 0, 0);

   

     opencv.convert( OpenCV.GRAY);
     opencv.contrast( contrast_value );  
     copyimg = opencv.image();
     opencv.absDiff();
     opencv.blur(OpenCV.BLUR, blurLvl);    
     opencv.threshold(threshold);
   //image(opencv.image(),0,0);
   
   Blob[] blobs = opencv.blobs( 80, w*h/3, amountOfBlobs, false);
   
   for( int i=0; i<blobs.length; i++ ) {

       Rectangle bounding_rect      = blobs[i].rectangle;
           
     
       imgArray[i] = createImage(bounding_rect.width, bounding_rect.height, RGB);
       imgArray[i].copy(copyimg,bounding_rect.x, bounding_rect.y, bounding_rect.width, bounding_rect.height, 0, 0, bounding_rect.width, bounding_rect.height);
       
       //Frame
       image( loadImage("frame.png"), bounding_rect.x, bounding_rect.y);
       
       tint(r,g,b);
       image(imgArray[i],bounding_rect.x, bounding_rect.y);
       noTint();
       image( loadImage("frame.png"), bounding_rect.x, bounding_rect.y);
       
   }

   //frame differencing, remember last frame
   opencv.remember();
   
   //  flipped the image earlier, we need to flip it here too.
   opencv.remember(OpenCV.SOURCE, OpenCV.FLIP_HORIZONTAL);
}




void keyPressed() {
 if(key==',') controlP5.window("controlP5window").hide();
 if(key=='.') controlP5.window("controlP5window").show();
 // controlWindow = controlP5.addControlWindow("controlP5window2",600,100,400,200);
 // controlP5.controller("sliderValue1").moveTo(controlWindow);
}

public void stop() {
   opencv.stop();
   super.stop();
}
Re: Png Frame on top of OpenCV Blobs
Reply #2 - May 10th, 2010, 2:52pm
 
pass a loop through your blobs and you can get the width and the height of each blob. pretty easy from there:

Code:

for( int blob_num = 0; blob_num < blobs.length; blob_num++ ) {

Rectangle bounding_box = blobs[blob_num].rectangle;
noFill();
stroke(0,128,0);
this.rect( bounding_box.x, bounding_box.y, bounding_box.width, bounding_box.height);
}


Page Index Toggle Pages: 1