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.
Page Index Toggle Pages: 1
Capture+contrast+mask+blur (Read 1391 times)
Capture+contrast+mask+blur
Jun 14th, 2009, 6:16pm
 
Hi!
I'm pretty new to Processing and I'm doing my first project after playing around with examples for a while.

I want to add contrast to a live video capture and then apply a blur that is masked so that the middle of the image appear sharp.

I've succeeded in adding contrast and creating the masked blur effect but the problem is that I want to apply the contrast to the live input only and not the whole comp.

Link to image displaying the problem:
wdr.se/processing/problem01/mask+contrast_problem.jpg
(Sorry, I'm not allowed to post active links yet)

This is the code I'm using:

import processing.video.*;

Capture cam;

void setup() {
 size(640, 480);
 cam = new Capture(this, 640, 480);
 cam.frameRate(12);
}

void draw() {
 if (cam.available() == true) {
   cam.read();
   filter(BLUR,5);
   PImage maskImg = loadImage("hardmask_big.jpg");
   cam.mask(maskImg);
   image(cam, 0, 0);

 }
}

Ideas on how to make this work like frame 2 in the linked image and tips on how to make the code faster would be much appreciated.  

* Dr. Strangecode
Re: Capture+contrast+mask+blur
Reply #1 - Jun 15th, 2009, 3:59am
 
Problem is: you're masking on a loop, so the mask stays on, incrementally.
There is probably a better way to do this, but from the top of my head I would create 2 masks, one of them white (that would be a fake unmask) and do the following:

void draw(){
 if(cam.available()){
   cam.read();
   PImage maskImg = loadImage("unmask.jpg");
   cam.mask(maskImg);
   image(cam,0,0);
   filter(BLUR,5);
   maskImg = loadImage("mask.jpg");
   cam.mask(maskImg);
   image(cam,0,0);
 }
}

It is very slow,though, you'd gain extra speed by reading the cam on the capture event function:

void captureEvent(Capture cam){
 cam.read();
}

but you'd gain extra problems because captureEvent can occur mid-draw, between the two image calls.

I can't think of other simple solutions at the moment, only very elaborate and twisted ones, but I'll give this some extra thought as soon as I have some free time.
Re: Capture+contrast+mask+blur
Reply #2 - Jun 15th, 2009, 9:40am
 
Awesome!
I'll do a test and stay tuned.
* Dr. Strangecode
Page Index Toggle Pages: 1