Quantcast
Channel: Processing Forum
Viewing all 1768 articles
Browse latest View live

creating a capture button

$
0
0
I've got a webcam sketch, but I was wanting to make a mouse click save the image from the webcam, any help would be appreciated. I've shown my sketch bellow in case its not a good starting point.
Thanks

import processing.video.*;
 
int w = 640;  
int h = 480; 
int fps = 25;  
Capture cam;  
 
void setup()
{
  size(w, h, P3D);  
   
  frameRate(fps);    
   
  cam = new Capture(this, w, h);  
}
 
void draw()
{
  if (cam.available() == true) {  
      cam.read();                  
  }
   
  image(cam, 0, 0, w, h); 
  tint(17);             
  noTint();                                                    
}

Movie.speed()

$
0
0
Hi,

I am working on a project that requires a variable speed in video playback.  This can be achieved with Movie.speed().  I have two questions regarding it that I was hoping someone would shed a light on:

- What limits the maximum speed?  For my HD video I see no speed difference once I go over speed(2).  I can go from -2 up to 2 but anything outside that range does not do anything.  Is this a CPU thing so smaller videos could go faster?

- What codec is best for a video that should play backwards and forwards at speeds up to maybe 10x.  ( Matroska x264? )

Best,
Sammi

Re : Trying to trigger video Filters with a touch of several buttons Need Urgent Help

$
0
0
Why have you started a new thread?
Maybe it is because you have different problems than in the old thread. If so, that's OK.
But I don't see a question in your message, actually.

Re : creating a capture button

$
0
0
I started with one of the examples that comes with Processing added the G4P library (Select Sketch | Import Library | Add Library | G4P from the menu). I added a G4P button to the sketch, an event handler for the button and I end up with the code below.

BTW it works and saves a numbered image every time the button is clicked.


  1. /**
  2.  * Getting Started with Capture.
  3.  *
  4.  * Reading and displaying an image from an attached Capture device.
  5.  */
  6. import processing.video.*;
  7. import g4p_controls.*;

  8. Capture cam;
  9. GButton btnSave;
  10. int n = 1;

  11. void setup() {
  12.   size(640, 480, P2D);
  13.   btnSave = new GButton(this, width-44, height-30, 38, 24);
  14.   btnSave.setText("SAVE");
  15.   String[] cameras = Capture.list();
  16.   if (cameras.length == 0) {
  17.     println("There are no cameras available for capture.");
  18.     exit();
  19.   }
  20.   else {
  21.     println("Available cameras:");
  22.     for (int i = 0; i < cameras.length; i++) {
  23.       println(cameras[i]);
  24.     }
  25.     // The camera can be initialized directly using an element
  26.     // from the array returned by list():
  27.     cam = new Capture(this, cameras[0]);
  28.     cam.start();
  29.   }
  30. }

  31. void draw() {
  32.   if (cam.available() == true) {
  33.     cam.read();
  34.   }
  35.   image(cam, 0, 0);
  36.   // The following does the same, and is faster when just drawing the image
  37.   // without any additional resizing, transformations, or tint.
  38.   //set(0, 0, cam);
  39. }

  40. public void handleButtonEvents(GButton button, GEvent event) {
  41.   if (button == btnSave) {
  42.     saveFrame("frame_" + n + ".jpg");
  43.     n++;
  44.   }
  45. }

Re : Trying to trigger video Filters with a touch of several buttons Need Urgent Help

$
0
0
Yeh it was a new question I got the buttons working now I needed help with video filters and like you said before you haven't really worked with video

Re : Trying to trigger video Filters with a touch of several buttons Need Urgent Help

$
0
0
Sure, but "help with video filters" is a bit vague.
What kind of filters?

Re : How to use pgl.drawElement ?

$
0
0
Hello All !

I'm far from my initial question but I found the solution I was looking for ! :)

It's actually possible to add custom attributes that affect Vertex & Fragment shader, and it's very easy to do !
Here is an exemple based on the 'TextureQuad' example :

  1. import java.nio.*;

  2. PImage img;
  3. PShader testShader;
  4. PGL pgl;

  5. float[] scales;
  6. float[] colors;

  7. FloatBuffer scaleData;
  8. FloatBuffer colorData;

  9. int scaleLoc;
  10. int colorLoc;

  11. void setup() {
  12.   size(640, 360, P3D);
  13.   img = loadImage("Desert.jpg");
  14.   testShader = loadShader("fragment.glsl","vertex.glsl");
  15.   
  16.   scales = new float[16];
  17.   scales[0] = scales[1] = scales[2] = scales[3] = scales[4] = scales[5] = scales[6] = scales[7] = scales[8] = scales[9] = scales[10] = scales[11] = scales[12] = scales[13] = scales[14] = scales[15] = 0.5;
  18.   
  19.   colors = new float[16];
  20.   colors[0] = colors[4] = colors[8] = colors[12] = 1;
  21.   colors[1] = colors[5] = colors[9] = colors[13] = 0;
  22.   colors[2] = colors[6] = colors[10] = colors[14] = 0;
  23.   colors[3] = colors[7] = colors[11] = colors[15] = 1;
  24.   
  25.   
  26.   scaleData = allocateDirectFloatBuffer(16);
  27.   scaleData.put(scales);
  28.   scaleData.position(0);  
  29.   
  30.   
  31.   colorData = allocateDirectFloatBuffer(16);
  32.   colorData.put(colors);
  33.   colorData.position(0);  
  34.   
  35.   noStroke();
  36.  
  37. }

  38. void draw() {
  39.   background(0);
  40.   translate(width / 2, height / 2);
  41.   rotateY(map(mouseX, 0, width, -PI, PI));
  42.   rotateZ(PI/6);
  43.   
  44.   pgl = beginPGL();
  45.   
  46.   scaleLoc = pgl.getAttribLocation(testShader.glProgram, "inScale");
  47.   pgl.enableVertexAttribArray(scaleLoc);
  48.   pgl.vertexAttribPointer(scaleLoc, 4, PGL.FLOAT, false, 0, scaleData);
  49.   
  50.   colorLoc = pgl.getAttribLocation(testShader.glProgram, "inColour");
  51.   pgl.enableVertexAttribArray(colorLoc);
  52.   pgl.vertexAttribPointer(colorLoc, 4, PGL.FLOAT, false, 0, colorData);
  53.   
  54.   endPGL();
  55.   
  56.   shader(testShader);
  57.   
  58.   beginShape();
  59.   
  60.   texture(img);
  61.   vertex(-100, -100, 0, 0, 0);
  62.   vertex(100, -100, 0, img.width, 0);
  63.   vertex(100, 100, 0, img.width, img.height);
  64.   vertex(-100, 100, 0, 0, img.height);
  65.   
  66.   endShape();
  67.   
  68.   
  69.   resetShader();
  70. }

  71. FloatBuffer allocateDirectFloatBuffer(int n) {
  72.   return ByteBuffer.allocateDirect(n * Float.SIZE/8).order(ByteOrder.nativeOrder()).asFloatBuffer();
  73. }

My vertexShader 
  1. uniform mat4 projmodelviewMatrix;

  2. //custom attributes
  3. attribute vec4 inScale;
  4. attribute vec4 inColour; //inColor cannot be overrided (it always a white color)
  5.                          //so I renamed it 'colour' for the test.                         
  6. attribute vec4 inVertex;
  7. attribute vec2 inTexcoord;

  8. varying vec2 vertTexcoord;
  9. varying vec4 vertColor;

  10. void main() {
  11.   // Vertex in clip coordinates
  12.   vec4 pos = projmodelviewMatrix * inVertex;
  13.   pos.xy *= inScale.xy;
  14.   gl_Position = pos;
  15.   
  16.   vertTexcoord = inTexcoord;
  17.   vertColor = inColour;
  18. }
and my fragmentShader
  1. #ifdef GL_ES
  2. precision mediump float;
  3. precision mediump int;
  4. #endif

  5. uniform sampler2D textureSampler;
  6. varying vec2 vertTexcoord;
  7. varying vec4 vertColor;

  8. void main() {
  9.   vec4 texture = texture2D(textureSampler, vertTexcoord);
  10.   texture.xyz *= vertColor.xyz;
  11.   gl_FragColor = texture;
  12. }


The whole code draw a textured-colorTransformed-scaled quad. The color used in the colorTransform operation come from the 'fill' instruction. 

It's much more easy than Flash, I'm impressed ! :)


EDIT : I have an error "OpenGL error 1281 at top endDraw(): invalid value" but all works fine. Other people already had these error but they didn't know why (all works fine for them too)

How to use PShader.bind / PShader.unbind ?

$
0
0
Hello !

Someone know what the functions PShader.bind and PShader.unbind are supposed to do ?
I don't know at all... All works fine if I don't use it, and if I do nothing changed... I probably don't use it as expected...

Thanks !

Re : How to use PShader.bind / PShader.unbind ?

$
0
0
You don't normally need to use bin/unbind methods in PShader, since Processing takes care of doing that automatically. But if you are calling low-level OpenGL functions, then bind/unbind become useful, take a look at the LowLevelGL example included in Topics|Shaders in 2.0b6

Re : choose your own adventure game with video transition

$
0
0
Hi again,

Hope im not bugging anyone much with all these questions. Just, this project is due tomorrow and I'm getting kind of stumped. I made a method for nameMovie and this is how I made it look:

void nameMovie(int[] myMovie){
    Movie = new int[myMovie.length];
    arrayCopy(myMovie,Movie);

getting error message- The method nameMovie(int[]) in the type sketch_dec04a.Page is not applicable for the arguments (int) on line:

       Movie myMovie = new Movie (this, pages[currentPage].nameMovie(0) );

Re : choose your own adventure game with video transition

$
0
0

No,

nameMovie is just a String you have to add to your class.


Re : choose your own adventure game with video transition

$
0
0
Glad to hear!

I did make it as a string in my classPage but it is still not working.

This is how my Class page looks now.

class Page{
  import processing.video.*;
  Movie myMovie;
  String bodyText; //string used for displaying the text
  PImage backImg;
  int[] options;
  int[] nameMovie;
  
Page( String nameMovie_, String nameImage){
     //  bodyText = theString;
     nameMovie = nameMovie_;
     backImg = loadImage(nameImage);
     myMovie = new Movie (this, nameMovie);
     myMovie.play(); 
  }
  
              
  void setBodyText(String theString){// sets a string for the bodytext object
   bodyText = theString;
  }
  
  void setOptions(int[] theOptions){
    options = new int[theOptions.length];
    arrayCopy(theOptions,options);
  }
  
  void nameMovie(int[] myMovie){
    Movie = new int[myMovie.length];
    arrayCopy(myMovie,Movie);

  }
  

  
  void display(){ //sets display option for text to be centered and have a buffer zone of 20 pixels.
   image(backImg,0,0);
    textAlign(CENTER);
    fill(#03FF00);
    text(bodyText,20,20,width-20,height-20);
  }
  
  void chooseOption(int theNum, int name){
    if(theNum < options.length){
      currentPage = options[theNum];
    }
  }
}

can show my setup page if you'd like as well

Re : choose your own adventure game with video transition

$
0
0


in Page:

don't have this:
     myMovie = new Movie (this, nameMovie);
     myMovie.play();

have it in draw() or in keyPressed()

and you don't have a String nameMovie in your class

Re : choose your own adventure game with video transition

$
0
0


here



  1. class Page {
  2.   String bodyText; //string used for displaying the text
  3.   PImage backImg;
  4.   int[] options;
  5.   String nameMovie;
  6.   Page( String nameMovie_, String nameImage) {
  7.     //  bodyText = theString;
  8.     nameMovie = nameMovie_;
  9.     backImg = loadImage(nameImage);
  10.   }
  11.   void setBodyText(String theString) {// sets a string for the bodytext object
  12.     bodyText = theString;
  13.   }
  14.   void setOptions(int[] theOptions) {
  15.     options = new int[theOptions.length];
  16.     arrayCopy(theOptions, options);
  17.   }
  18.   void display() { //sets display option for text to be centered and have a buffer zone of 20 pixels.
  19.     image(backImg, 0, 0);
  20.     textAlign(CENTER);
  21.     fill(#03FF00);
  22.     text(bodyText, 20, 20, width-20, height-20);
  23.   }
  24.   void chooseOption(int theNum, int name) {
  25.     if (theNum < options.length) {
  26.       currentPage = options[theNum];
  27.     }
  28.   }
  29. }

Re : choose your own adventure game with video transition

$
0
0

now you have to put the rest accordingly...



Re : choose your own adventure game with video transition

$
0
0
its now saying found one too many { characters without a } to match it.

Re : choose your own adventure game with video transition

$
0
0
its now saying found one too many { characters without a } to match it which doesn't make too much sense since all the brackets are there and when i add another it says cant find classPage

Re : choose your own adventure game with video transition

$
0
0
never mind, fixed the problem with the bracket. but in keyPressed() I am getting the error The method chooseOption(int, int) in the type test.Page is not applicable for the arguments (int). My sketch is called test.

Here the code i have now on the main page:

int currentPage = 0;
Page[] pages = new Page[11]; //state how many pages there are.
PFont font;

int timelength = 8000;
boolean playing1, playing2;

void setup() {
  size(864, 468, P3D);
  background(0);    
 font = loadFont("TimesNewRomanPS-BoldMT-48.vlw"); //type of font.
  textFont(font,24);  //size of font.
  for(int i = 0; i < pages.length; i++){
    pages[i] = new Page(i+".mov", i+".jpg");
    
  }
  
  {
  pages[0].setBodyText("You wake up in a forest. Cold, confused, alone. You have no idea how you ended up here. A dark presence raises the hairs on the back of your neck. Find a way to escape… with your life.\n\n\nup) travel down path    right) walk into the trees"); // text for different pages set by BodyTExt string.
  int[] options0 = {8,0,2};//set page number to go to with the corresponding variable in the keyPressed utilizing the chooseOption object.
  pages[0].setOptions(options0);

  pages[1].setBodyText("An icy river flows before you. Attempting to cross it could prove fatal; however, the presence you have been sensing seems to be drawing nearer…\n\n\nup) Cross river     down) Go back");
  int[] options1 = {8,8};
  pages[1].setOptions(options1);
  
  pages[2].setBodyText("As you journey deeper into the woods you feel more lost than ever before. A weathered cardboard box rests beside a tree. Your curiosity is overpowering, but your urge to flee increases by the second…\n\n\nup) Travel Deeper     down) Open box");
  int[] options2 = {8,3};
  pages[2].setOptions(options2);
  
  pages[3].setBodyText("The mysterious map reveals your precise location, as though someone, or something, is playing a game with you. With four directions to choose from surely one must lead to safety, but the others may lead to your demise…\n\n\nup) North     down) South     left) East     right)West");
  int[] options3 = {4,8,8,8};
  pages[3].setOptions(options3);
  
  pages[4].setBodyText("Hours of walking has resulted in sore feet and shortness of breath. Fatigue sets in like a disease, sapping you of strength. The road before you offers a glimmer of hope, but an abandoned car intensifies your suspicion that a pursuer is not far behind…\n\n\nup) Walk along a road     down) Try door     right) Check for key");
  int[] options4 = {5,9,7};
  pages[4].setOptions(options4);
  
  pages[5].setBodyText("Traveling along the road has proven to be rewarding. A skateboard resting in the ditch might be the answer to your problems, however walking has brought you success thus far…\n\n\nup) Keep walking     left) Examine bike");
  int[] options5 = {8,5,5,8};
  pages[5].setOptions(options5);
  
  pages[6].setBodyText("The car appears empty. Fresh tire tracks mark the soft ground. Your impulse to escape overpowers your moral obligations, and it is clear that this vehicle is your only option left…\n\n\ndown) Try door     up) Check for key");
  int[] options6 = {3,2};
  pages[6].setOptions(options6);
  
  pages[7].setBodyText("As you sit in the driver’s seat you feel certain that you are not alone. Your adventure has left you parched, and an unknown beverage sitting in the cup holder could offer quick relief. The rear view mirror is adjusted incorrectly, however the thought of viewing whatever has been following you is petrifying…\n\n\ndown) Try the drink     up) Check rear view mirror     right) Start car");
  int[] options7 = {8,8,10};
  pages[7].setOptions(options7);
  
  pages[8].setBodyText("\n\n\n Press any arrow key to restart");
  int[] options8 = {0,0,0,0};
  pages[8].setOptions(options8);
  
  pages[9].setBodyText("Locked\n\n\n up)go backwards");
  int[] options9 = {4};
  pages[9].setOptions(options9);
  
  pages[10].setBodyText("Shady man win? \n\n CONGRADULATIONS              Press any arrow key to restart");
  int[] options10 = {0,0,0,0};
  pages[10].setOptions(options10);
  }

  
/*  // First movie is playing.
  mov1 = new Movie(this, "backseatpsycho.mov");
  mov1.play();
  playing1 = true;
  
  // Second movie is paused.
  mov2 = new Movie(this, "0.mov");
  mov2.pause();
  playing2 = false;*/
}

void keyPressed() { // sets up different keys to choose different options when on a certian page.
  if (key == CODED) {
    if (keyCode == UP) {
      pages[currentPage].chooseOption(0);
    }else if (keyCode == DOWN) {
      pages[currentPage].chooseOption(1);
    }else if(keyCode == RIGHT){
      pages[currentPage].chooseOption(2);
    }else if(keyCode == LEFT){
      pages[currentPage].chooseOption(3);
    }
  }
}

void movieEvent(Movie mov) {
  mov.read();
}

void draw() {
  background(0);
  pages[currentPage].display();
  myMovie = new Movie (this, nameMovie);
  myMovie.play();
}

Re : choose your own adventure game with video transition

$
0
0
I think im having this error because now there is the int name in the void chooseOption on the classPage

Re : How to use PShader.bind / PShader.unbind ?

$
0
0
Hello Andres !

Thank you for your message !
I'm using custom attributes, then I need to use openGl function to enable and define the FloatBuffers.
Something like that 
  1.   pgl = beginPGL();
  2.   scaleLoc = pgl.getAttribLocation(testShader.glProgram, "inScale");
  3.   pgl.enableVertexAttribArray(scaleLoc);
  4.   pgl.vertexAttribPointer(scaleLoc, 3, PGL.FLOAT, false, 0, scaleData);
Do I have to use bind before 'beginPGL()' and unbind after 'endPGL()' ?

I checked your blog a lot of time... 
Thanks a lot for your work (and your help) !




Viewing all 1768 articles
Browse latest View live




Latest Images