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
Polar co-ordinate distortion and video (Read 1890 times)
Polar co-ordinate distortion and video
Mar 21st, 2009, 5:24pm
 
Hi guys,

I am a new processing user from a standard motion graphics background and I need some help getting started with a processing project.

What I would like to do is to do a reverse polar coordinates warp on some live video.

What I am doing is a variation of a 360 degree video project described on my video project blog here:
http://videothing.blogspot.com/2005/05/my-ghetto-360-video-experiment.html

Currently the setup is to shoot video pointing up at the underside of a reflective ball, and then 'unwrap' the video in after effects using polar coordinates.

What I would like to do is to unwrap the video on the fly.

As icing it might be also awesome to somehow use Picture Transfer Protocol (PTP) so that a still camera could be used, for higher resolution. I don't know if anyone has worked out any support for that in processing though.

Thanks!

Re: Polar co-ordinate distortion and video
Reply #1 - Mar 23rd, 2009, 12:14am
 
That looks fun- here's one that will render your sample image:

Quote:
void setup()
{
  PImage img = loadImage("panobefore.jpg");
  size( int(TWO_PI*(img.width/2)), img.height/2 );
  
  loadPixels();
  for( int y=0; y<height; y++ )
  {
    for( int x=0; x<width; x++ )
    {
      float theta = map(x, 0, width, 0, TWO_PI);
      float radius = map(y, 0, height, 0, img.width/2.0);
      
      int imgX = int( cos(theta) * radius + img.width/2.0 );
      int imgY = int( sin(theta) * radius + img.height/2.0 );
      
      pixels[ (height-1-y)*width + x ] = img.pixels[ imgY*img.width + imgX ];
    }
  }
  updatePixels();
}



I'm afraid I don't know anything about Picture Transfer Protocol, but this will work on any still camera image you pass in (and it should be easy enough to extend it to accessing the video's pixels[] instead of a PImage's)

edit: the width in the size() command assumes that you want the outer circumference, which causes that distortion at the bottom. size( int(PI*(img.width/2)), img.height/2 ); gives you a smaller image with less distortion.
Re: Polar co-ordinate distortion and video
Reply #2 - Mar 23rd, 2009, 5:29am
 
Now, with video!

Quote:
import processing.video.*;
Capture video;

void setup()
{
  int w = 800;
  size(int(PI*(w/2.0)), w/2, P2D);
  video = new Capture(this, w, w, 12);
}

void draw()

  if (video.available())
  {
    video.read();
    video.loadPixels();
    
    loadPixels();
    for( int y=0; y<height; y++ )
    {
      for( int x=0; x<width; x++ )
      {
        float theta = map(x, 0, width, 0, TWO_PI);
        float radius = map( (height-1-y), 0, height, 0, video.width/2.0);
        //float radius = sin( (y/float(height))*HALF_PI ) * video.width/2.0;
        
        int imgX = int( cos(theta) * radius + video.width/2.0 );
        int imgY = int( sin(theta) * radius + video.height/2.0 );
        
        pixels[ y*width + x ] = video.pixels[ imgY*video.width + imgX ];
      }
    }
    updatePixels();
  }
}

void keyPressed()
{
  if (key==' ')
  {
    saveFrame("polar###.png");
  }
}


I've been trying to dangle a christmas ornament over the webcam in my macbook to see if this works properly but the laptop fills the whole view- hopefully it works better with your setup.

It does produce some pretty awesome distortions without the ball though!
http://www.flickr.com/photos/noelb/3377566617/
Re: Polar co-ordinate distortion and video
Reply #3 - Mar 23rd, 2009, 5:32am
 
huzzah! amazing how fast stuff happens in the processing world.
Re: Polar co-ordinate distortion and video
Reply #4 - Mar 23rd, 2009, 5:34am
 
I haven't tried it out yet, but one possible modification might be some user facing controls to tweak the distortion slightly to make up for the size of the ball or the orientation of the camera.

I'll try this out and report back!
Re: Polar co-ordinate distortion and video
Reply #5 - Jun 24th, 2009, 8:41am
 
I'm brand new to the world of Processing and am experimenting with panoramic video.

I'm finding it very difficult to find a cost effective solution to unwrapping the recorded footage.

Would it be possible to have something like this open a video file then work through frame by frame unwrapping the image and rendering it out to a new file?
Re: Polar co-ordinate distortion and video
Reply #6 - Jun 28th, 2009, 11:56am
 
Hi,

I just created this article which describes how to create a HD video from your application. It's based on openFrameworks but it is almost identical for processing..

See:  http://openframeworks.info/prog_tech/creating-hd-video-from-application-for-vime...
Re: Polar co-ordinate distortion and video
Reply #7 - Oct 13th, 2009, 11:50am
 
I´m experimenting with weevil´s christmas ball invention (actually with a mirror covered light bulb, which makes an almost perfect mirror sphere) and it works fine, but I can barely see what´s happening in there (i.e: the acting of the actors in the scene). I need some kind of a real time monitor to see what I´m filming. Do you think it´s possible  to make a real time spherical viewer in processing? Something like this
(sorry, I am not allowed to post web addreses, please google

luis lopez navarro camara360
)
but taking an DV or HDV video input where we would film a mirror ball
Thanks a lot
Luis
Page Index Toggle Pages: 1