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

Can't play video with my webcam on.

$
0
0
Hello,

For my school project I need to create an exhibition. My exhibition is about spinal hernia. I want my visitors to see themself lifting up a box(a light one) in the correct way. If they lift it the wrong way they can go past a certain value. If they do, the sides will go red and a sound will play. After the sound I want my webcam to stop capturing and start playing a video with an animation showing how to lift the box the correct way. My problem here is that I can not get my video to work. Here is my code:

  1. import processing.video.*;
  2. import ddf.minim.*;

  3. Capture cam;
  4. Movie myMovie;
  5. Minim minim;
  6. AudioPlayer player;

  7. int cx = 160, cy = 400, radius = 200;
  8. color target = color(0, 0, 200);

  9. PImage spiegel;

  10. void setup() {

  11.   size(1024, 680, P2D);
  12.   cam = new Capture(this, width, height, 24);
  13.   spiegel = createImage(width, height, RGB);
  14.  
  15.   minim = new Minim(this);
  16.   player = minim.loadFile("Wrenched.wav", 512);
  17.  
  18.   myMovie = new Movie (this, "test.mov"); 

  19. }

  20. void draw() {
  21.   if (cam.available()) {
  22.     cam.read();
  23.     image(cam, 0, 0);
  24.     cam.loadPixels();
  25.     for (int i = 0; i <cam.pixels.length; i++) {
  26.       spiegel.pixels[i] = cam.pixels[cam.width + (cam.width*(i/cam.width)) - 1 - i%cam.width];
  27.     }

  28.     spiegel.updatePixels();
  29.    
  30.     image(spiegel, 0, 0);
  31.     int drempel = 120;
  32.     int loc;
  33.     int teller = 0;
  34.     int pixelDrempel = 10;
  35.     noFill();

  36. // 5 regels van @Alwin de Rooij
  37.     for(int x=0; x<cam.width; x++) {
  38.       for(int y=0; y<cam.height; y++) {
  39.         loc = x + (y*cam.width);
  40.         if(dist(red(cam.pixels[loc]), green(cam.pixels[loc]), blue(cam.pixels[loc]), red(target), green(target), blue(target)) < drempel) {
  41.           if(dist(cx, cy, x, y) < radius/2) {
  42.             teller++;
  43.           }
  44.         }
  45.       }
  46.     }
  47.    
  48.     rect(0, 0, 256, 680);
  49.     rect(768, 0, 256, 680);
  50.    
  51.     myMovie.stop();
  52.     if(teller > pixelDrempel){
  53.       fill(255,0 ,0);
  54.       rect(0, 0, 256, 680);
  55.      
  56.       player.play();
  57.      
  58.       myMovie.play();   
  59.       image(myMovie, 0, 0);
  60.     
  61.     }
  62.    
  63.     if(teller > pixelDrempel){
  64.       fill(255,0 ,0);
  65.       rect(768, 0, 256, 680);
  66.       player.play();
  67.     }
  68.    
  69.     if(player.position() == 2630){
  70.       player.rewind();
  71.     }
  72.     //player.position();
  73.     //println(player.position());
  74.        
  75.   }
  76. }
  77. void movieEvent(Movie m){
  78.   m.read();
  79. }



If you move a blue object near the sides, the sides go red and you hear a sound. For 1 second you see a video pop up and then it stops. How can I get this to play?

- Sasmaz

Re : Can't play video with my webcam on.

$
0
0
In draw() you need to place different states. So you have the interaction state and the show movie state. In your example the show movie starts but gets in the interaction state right away.
Anyway, you can find here a example. You just need to find out if the movie reaches the full length, and then put it in the interaction state again. 

Re : Controlling Video

$
0
0
Have you looked at the the processing.movie library?  http://processing.org/reference/libraries/video/index.html

This simple example loads a video and pauses it when the mouse is pressed which can be modified to the keyboard.  There are also functions to change the speed of the video but I am not sure about reverse play.


import processing.video.*;
Movie myMovie;

void setup() {
  size(200, 200);
  background(0);
  myMovie = new Movie(this, "totoro.mov");
  myMovie.play();
}

void draw() {
  background(255);
  image(myMovie, 0, 0);
}

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

// Pause the movie playback when the mouse pressed
void mousePressed() {
  myMovie.pause();}

GLModel() support in 2.0b7? (Newbie Question)

$
0
0
I'm porting a Sketch that used Andres' OpenGL implementation in Processing 1.5.  This sketch used the GLModel() call (cut/paste below) using TRIANGLE_FAN mode and DYNAMIC usage.  Is there core support for this now?  Any suggestions on porting this to 2.0b7?

     //GLModel(processing.core.PApplet parent, int numVert, int mode, int usage) 
     //This class holds a 3D model composed of vertices, normals, colors (per vertex) 
     //and texture coordinates (also per vertex). All this data is stored in 
     //Vertex Buffer Objects (VBO) for fast access. 
     //
     //Creates an instance of GLModel with the specified parameters: 
     //       number of vertices, 
     //       mode to draw the vertices (as points, sprites, lines, etc) and 
     //       usage (dynamic if they will change frequently or stream if they will change at every frame).

Low Level GL Example - 2.0b7

$
0
0
I'm looking for an example that uses the core OpenGL support.  I started trying to use the LowLevelGL example on the code.google site (link at the bottom), but it seems to have some issues with 2.0b7.  (all user issues?).

When I try to run the sketch as-is, I get the error 
      Cannot find anything named "PShader.FLAT"
which is thrown by line 25:
       shader = pg.getShader(PShader.FLAT);
I tried changing that call to loadShader(), but that produces the same error.  Just to keep going, I grabbed a blur shader and loaded that shader,  

That gets me by that error, but then throws the error:
      The mehod allocateDirectFloatBuffer(int) from the type PGL is not visible
which comes from line 28:
       vertData = PGL.allocateDirectFloatBuffer(12);

I assume the example and the implementation in 2.0b7 have drifted??  I couldn't find an updated example.  Could someone help me out here with either 1) pointers to fix these specific issues or 2) a pointer to a low level example?

The sample code is here:


Thank you!!


Decent Pitch Detector

$
0
0
Hey guys,

I'm trying to make a pitch detector for acoustic guitars on processing.

I'm very new at audio and having a little trouble for detecting the pitch of each strings of the guitar. I'm using minim but I don't know how to get info out of the frequency spectrum and detect the exact pitch of that string.

For a regular guitar the frequency range goes from 82Hz (E) to 330Hz (e). For each string it goes like this:

E      82 Hz
A      110 Hz
D      147 Hz
G      196 Hz
B      247 Hz
e      330 Hz

My starting point was this FFT example of Linear Logaritmic Averages, but I still don't know how to work with this frequency spectrum neither how to detect the pitch accurately.

I'm reading some stuff on the subject right now, but if anybody here has a hint ou a better approach to this problem I would be very greatful.

Thanks! :)

Re : Decent Pitch Detector

$
0
0
Do you mean that you want to get the notes from a audio file? Because i tried to look for such a program for a long time, but it seems that it is impossible. Or do you mean the BPM?

Re : Decent Pitch Detector

$
0
0
gidday,
Perhaps this can help, LiveSpectrogram_window example in these forums is good start.
I have used it to make a level trigger and also to detect at particular frequencies.
This example may help ,

look for this value,  sgram[i][col] =
at this point it is the current i=(freqnumber) level
to work out freq if int bufferSize = 2048; then scale is 3000/256 = 11.71hz per step so 330hz/11.71 = 28.
so look for siglevel when i=28.
if int bufferSize =4096; then scale is 1500/256 = 5.8hz per step so 330hz/11.71 = 56.8.
so look for siglevel when i=56 or 57

this listens to audio line in so may work in real time?

kind regards algwat


Re : Controlling Video

$
0
0
Ahhhh great thank you Richard, that helped out a lot with getting started, and the video library link you provided helped too :)

Since then I have decided to take it a step further and use Osculator and GSVideo to control the video with a Wii remote.

I have managed to get quite far, but I am having a couple of issues, one of which involves a 'switch' which I thought you may be able to help with.

Here's a link to my new post if you have a chance to take a look please!


Thanks

OpenGL doesnt work

$
0
0
Hello,
the code

import processing.opengl.*;

void setup()
{
  size( 640, 480, OPENGL );
}

produce message

no framebuffer objects available

how to fix it?

displaying text from serial port

$
0
0
hey guyz... i am a bit new with processing so i am a bit stuck in a not much hard situation, so here it goes.
      i am getting data from a serial port char by char(done that part) . i have to show a string of 5 char in row then move to the next row.  e.g
49999
39999
50000
20000

. but how can i code it so the first string stays there and move onto display next row because till now , i cant hold the first string to hold on when i move onto the next row.

thanx
 

Re : displaying text from serial port

$
0
0
I'm not sure if I understand what you want to do,
however, I'm quite sure that if you want to "hold"
a value, you have to store it somewhere, and that
place would be an array or a list.

Can you show us some code?

Best Regards,
Diogo Tudela
////////////////////////////////////
www.diogotudela.com

Re : displaying text from serial port

$
0
0
If you show some code, perhaps we can grasp better your goal.

Audio

$
0
0
I've created a video displayer in processing, and when you press a number on the keyboard it changes the video, so 1 = video1, 2 = video2, 3 = video3 etc.

This switch works fine, however, the problem I'm having is that although a new video displays, the audio carries on playing from the previous video, and I want this to stop at the same time the video changes.

Does anyone have any ideas, or code I could use to prevent this?

Re : displaying text from serial port

$
0
0
e.g this is my code, the problem is that the function writetext in Draw would display text with every new value in new line(which is fine), but i want to keep displaying all the values i get instead of just displaying the latest value recieved.

///////////////////////////////////////
import processing.serial.*;
Serial myPort;
String gps_error = "";
PFont font;
int widthadd = 30 , heightadd = 30 ;


void setup() {
  size(1000,500);
  myPort = new Serial(this, Serial.list()[0], 9600);
  myPort.bufferUntil('\n');
  font = createFont(PFont.list()[2],10);
  textFont(font);
}

void draw() 
{
      writeText("GPS Error reading = " + gps_error ); //want to keep the older one and then display next
}


void serialEvent (Serial myPort){
 
  gps_error = myPort.readStringUntil('\n');
  
 // if(gps_error != null){
   // gps_error=trim(gps_error);
  
// }
heightadd = heightadd + 30 ;
if (heightadd == 450)
{
  heightadd= 30 ;
  widthadd= 200;
}
  
  }
  
void writeText(String textToWrite)
{    
  background(255);
  fill(0);
  text(textToWrite, widthadd, heightadd);   
}

Re : Audio

$
0
0
I suppose you use the core library for video, so I moved the topic here. Showing some code might help in understanding your problem...

Re : displaying text from serial port

$
0
0
You should take a look at ArrayList.
With it, you can cumulate all the successive values you receive, and with a for loop, you can display they all.

Re : Audio

$
0
0
I'm actually using the GSVideo library, but I assumed they functioned the same.

The problem is the audio, not the video. The video changes fine the keyPress but the audio carries on playing.

Here's my code: Any Ideas?

  1. import codeanticode.gsvideo.*;

  2. GSMovie player;

  3. //global variables
  4. int direction;

  5. public void setup() {
  6.   size(640, 480);
  7.   background(0);
  8.   
  9.   // GSvideo setup
  10.   player = new GSMovie(this, "tdogg.mov");
  11.   player.loop();
  12. }

  13. void draw() {
  14.   image(player, 0, 0, width, height);
  15. }
  16.   
  17. void keyPressed() {
  18.   
  19.   if (key == '1') {  player = new GSMovie (this, "tdogg.mov");} 
  20.   if (key == '2') {  player = new GSMovie (this, "transit.mov");}
  21.   if (key == '3') {  player = new GSMovie (this, "bunny.mov");}
  22. }

  23. void movieEvent(GSMovie player) {
  24.   player.read();
  25. }

Need some help with left to right/experiments with slitscan (Beginner's frustration)

$
0
0
Hi

I am very new to this but find processing a fun and experimental experience. I am currently interested in the slit scan processing by Golan Levin.

I have been spending hours trying to figure out how to change the direction of the scan to go from left to right in larger sections rather than little slivers of imagery from the webcam.

I have tried to change this part to capture larger sections from the video camera to be displayed but no luck so far:

videoSliceX = video.width / 2;

  
I think this part may be the start position of the shown images?

drawPositionX = width - 1;


From some trial and error I think have narrowed the area that needs to be changed for the position to be continuously drawn:

  for (int y = 0; y < video.height; y++){
      int setPixelIndex = y*width + drawPositionX;
      int getPixelIndex = y*video.width  + videoSliceX;
      pixels[setPixelIndex] = video.pixels[getPixelIndex];
    }

I have been researching and trying to understand these variables and codes from the processing.org tutorials and example part of the website, but there are still some things I don't understand like the coding "width - 1" or "height - 1"- it seems to indent from the right or top if the numbers are changed, but if it is changed to +, the program won't work.

I am a real beginner and very inexperienced and would greatly appreciate any help/support here as my own attempts with code modification won't work and I really want to start learning about processing in a more accurately informed manner.

Thank you for your time!

Here is the code I have been looking at:

/**
 * Simple Real-Time Slit-Scan Program. 
 * By Golan Levin.
 *
 * This demonstration depends on the canvas height being equal 
 * to the video capture height. If you would prefer otherwise, 
 * consider using the image copy() function rather than the 
 * direct pixel-accessing approach I have used here. 
 */
import processing.video.*;

Capture video;

int videoSliceX;
int drawPositionX;

void setup() {
  size(600, 240, P2D);
  
  // Uses the default video input, see the reference if this causes an error
  video = new Capture(this, 320, 240);
  video.start();
  
  videoSliceX = video.width / 2;
  drawPositionX = width - 1;
  background(0);
}


void draw() {
  if (video.available()) {
    video.read();
    video.loadPixels();
    
    // Copy a column of pixels from the middle of the video 
    // To a location moving slowly across the canvas.
    loadPixels();
    for (int y = 0; y < video.height; y++){
      int setPixelIndex = y*width + drawPositionX;
      int getPixelIndex = y*video.width  + videoSliceX;
      pixels[setPixelIndex] = video.pixels[getPixelIndex];
    }
    updatePixels();
    
    drawPositionX--;
    // Wrap the position back to the beginning if necessary.
    if (drawPositionX < 0) {
      drawPositionX = width - 1;
    }
  }
}

Re : Need some help with left to right/experiments with slitscan (Beginner's frustration)

$
0
0
I'll try to explain the math reason behind those mysterious calcs.

video = new Capture(this, 320, 240); makes your video screen w/ width = 320 & height = 240.

width/2 is the horizontal center of the video screen.

Now the logic behind -> drawPositionX = width - 1; :

Even though the video's width is 320, the 1st x position is not 1!
In most programming languages, the 1st position is 0!!!

So, a video w/ 320 width starts at 0 and ends at 319.

In the case above, drawPositionX = last farthest x location (or pixel) of the video. Its far right.
Also, you can consider the x pixel position as the column, and y as the row.

In short, the whole video screen is a 2D rectangle matrix,
which can be addressed by 2 scalar variables, the coordinate pair (x,y).

However, to represent that 2D matrix as a 1D array, you need the following formula:
index1D = row*width + column;  or  index1D = y*width + x;

Hope it's enough to get you started.
Although I think you should start w/ something easier. 
Viewing all 1768 articles
Browse latest View live