Loading...
Logo
Processing Forum
I figured out signing Applets. Hooray! Also compiling in 32-bit mode. Hip, hip!

--BUT--

[EDIT]

My code won't run in any of my browsers. (Chrome, Firefox, Safari) It prompts me to allow script access, and then prompts me for a file (that's what the example app does) but then doesn't display the image I pick to the screen. Just sits there...

My machine: MacBook Pro, 10.6.4. Everything runs fine locally.

The code is below...  Just to clarify, this sketch does not load any local data, like what you'd need to put in a /data/ folder.

Replies(11)

Maybe you should post the code of your other sketch then. The problem might be not the signing after all.

Andreas
(Code posted below. I think at this point it *isn't* the signing, as I've gotten the test app to work at


This one, though (uploaded version of code posted below) does not:

Maybe I need to do something special to handle Minim / openCV in an online situation?

)
Check out the latest (1.2.1) version of Processing. In the changelog: " Added requestFocusInWindow() call to replace Apple's broken requestFocus(), which should return the previous behavior of sketches getting focus immediately when loaded in a web browser." Not sure if it solves your issue (lot of people already reported this error in the old forum) but it is worth trying...
Thanks! I dl'd and it fixes the windowing problem on Chrome but not Safari... worth updating anyway.
Good point, Andreas. Here 'tis:

Copy code
  1. import processing.video.*;
  2. import ddf.minim.analysis.*;
  3. import ddf.minim.*;
  4. import hypermedia.video.*;

  5. Minim minim;
  6. AudioInput in;
  7. OpenCV opencv;
  8. PImage bkgdImg;
  9. PImage trailsImg;
  10. PImage camImage;
  11. int hCycle;

  12. float audioAmp = 0.0;
  13. float sampleAmp;
  14. int numPixels;
  15. int[] backgroundPixels;
  16. int IMG_WIDTH = 640;
  17. int IMG_HEIGHT = 480;
  18. int COLOR_SPACE = OpenCV.RGB;
  19. int vidFactor = 1;
  20. color currColor;

  21. void setup() {
  22.   size(640, 480, P3D);
  23.   background(0);
  24.   opencv = new OpenCV(this);
  25.   minim = new Minim(this);
  26.   minim.debugOn();
  27.   in = minim.getLineIn(Minim.STEREO, 512);
  28.   opencv.capture(IMG_WIDTH, IMG_HEIGHT);
  29.   trailsImg = new PImage(IMG_WIDTH, IMG_HEIGHT);
  30.   bkgdImg = new PImage(IMG_WIDTH, IMG_HEIGHT);
  31. }

  32. void draw() {
  33.   // AUDIO ANALYSIS
  34.   audioAmp *= 0.8;
  35.   for(int i = 0; i < in.bufferSize() - 1; i++) {
  36.     sampleAmp = abs(in.mix.get(i));
  37.     audioAmp += sampleAmp;
  38.   }
  39.   if(audioAmp > 255) {
  40.     audioAmp = 255;
  41.   }
  42.   vidFactor = int(audioAmp);
  43.   // VIDEO ANALYSIS
  44.   alphize();
  45.   blend(camImage, 0, 0, IMG_WIDTH, IMG_HEIGHT, 0, 0, IMG_WIDTH, IMG_HEIGHT, SCREEN);
  46.   fill(0, 255-vidFactor);
  47.   rect(0, 0, 640, 480);

  48.   blend(bkgdImg, 0, 0, IMG_WIDTH, IMG_HEIGHT, 0, 0, IMG_WIDTH, IMG_HEIGHT, SCREEN);
  49.   trails();
  50. }

  51. void alphize() {
  52.   opencv.read();
  53.   opencv.flip(OpenCV.FLIP_HORIZONTAL);
  54.   camImage = opencv.image();
  55.   loadPixels();
  56.   for (int i = 0; i < IMG_HEIGHT * IMG_WIDTH; i++) {
  57.     currColor = camImage.pixels[i];
  58.     //clear alpha channel since it comes in as FF:
  59.     currColor = 0x00FFFFFF & currColor;
  60.     pixels[i] = 0x00000000 | (vidFactor << 24) | currColor;
  61.   }
  62.   updatePixels();
  63.   println(hex(pixels[1]) + " " + vidFactor + " " + hex(currColor));
  64. }

  65. void trails() {
  66.   opencv.read();
  67.   //opencv.flip(OpenCV.FLIP_HORIZONTAL);
  68.   PImage movImage;                
  69.   movImage = opencv.image();     

  70.   opencv.absDiff();              
  71.   opencv.convert( OpenCV.GRAY ); 
  72.   opencv.blur( OpenCV.BLUR, 3 );
  73.   opencv.threshold( 30 ); //was 20 originally

  74.   colorMode(HSB);                 
  75.   tint(color(hCycle, 100, 100));  
  76.   blend(trailsImg, 0, 0, IMG_WIDTH, IMG_HEIGHT, 0, 0, IMG_WIDTH, IMG_HEIGHT, SCREEN);
  77.   noTint();                      
  78.   colorMode(RGB);                 

  79.   trailsImg.blend(opencv.image(), 0, 0, IMG_WIDTH, IMG_HEIGHT, 0, 0, IMG_WIDTH, IMG_HEIGHT, SCREEN);

  80.   //handles fading the trails over time
  81.   opencv.copy( trailsImg );       
  82.   opencv.blur( OpenCV.BLUR, 4 );  
  83.   opencv.brightness( -20 );      
  84.   trailsImg = opencv.image();

  85.   opencv.remember();

  86.   hCycle++;
  87.   if (hCycle > 255) {
  88.     hCycle = 0;
  89.   }
  90. }

  91. void keyPressed() {
  92.   //println(keyCode);
  93.   switch(keyCode) {
  94.   case 8:
  95.     bkgdImg.loadPixels();
  96.     for (int i = 0; i < IMG_HEIGHT * IMG_WIDTH; i++) {
  97.       bkgdImg.pixels[i] = 0;
  98.     }
  99.     updatePixels();
  100.     break;
  101.   case 157:
  102.     break;
  103.   default:
  104.     opencv.read();
  105.     opencv.restore(COLOR_SPACE);
  106.     opencv.flip(OpenCV.FLIP_HORIZONTAL);
  107.     bkgdImg = opencv.image();
  108.   }
  109. }

  110. public void stop() {
  111.   in.close();
  112.   minim.stop();
  113.   opencv.stop();
  114.   super.stop();
  115. }

Alright. Still working on this one. I uploaded applets of the Minim and Video grabbing examples (elimination by one variable at a time), and both of those run in Firefox (but not Chrome or Safari).

Could it be OpenCV? Anyone gotten an OpenCV sketch running as an applet?

I have not tried to run OpenCV sketches as applets. However, looking at older posts I cannot find anyone reporting success on that issue, so you might be right about that. I am sorry but I cannot help you with that.

Andreas
Just found this: Someone mentions using the standard Processing video capture routines, and then moving each frame into OpenCV using copy...

Trying to figure out how that's done, exactly. If you know... I'd love to get pointed in the right direction.

thanks!
Charlie

The copying should be easy I think. Try this:

Copy code
  1. import hypermedia.video.*;
  2. import processing.video.*;
  3. int w=600;
  4. int h=480;
  5. OpenCV opencv;
  6. Capture cam;
  7. void setup() {
  8.   opencv = new OpenCV(this);
  9.   opencv.allocate(w,h);
  10.   cam=new Capture(this,w,h);
  11. }
  12. void draw(){
  13.    cam.read();
  14.    opencv.copy(cam.get(),0, 0,w,h,0,0,w,h);
  15. }

Don't know whether that helps though.

Andreas
Brilliant! Exactly what I was looking for. It was the cam.get() syntax that I was missing.

A few things to clean up in the code, as opencv.absDiff() breaks now that I'm reinserting a frame to opencv every time draw() runs. But, as soon as I get it sorted I'll post the sketch and a link here.

Cheers, Andreas!
Went through, starting from the example sketch, adding code line by line. 

It's OpenCV that breaks it. 

If anyone has a workaround, I'd love to hear it. Otherwise I guess it's try to do the same thing using the Processing inbuilt video capability...

C