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.
IndexProgramming Questions & HelpPrograms › Scrolling through images
Pages: 1 2 
Scrolling through images (Read 5267 times)
Scrolling through images
Jan 20th, 2010, 7:20am
 
Hi, I'm wanting to scroll through webcam feeds using a potentiometer. I have previously used an array to view all of the feeds at once & I have the serial working between the arduino & processing, but I don't know how to view each feed individually with the turning of a pot.

Any help would be great!
Re: Scrolling through images
Reply #1 - Jan 20th, 2010, 8:07am
 
Shoudlnt be to hard. What kind of data do you get when using your pot? -255 to 255 ?
we just need to map that to the length of your array and show the image.
Re: Scrolling through images
Reply #2 - Jan 20th, 2010, 8:52am
 
I get a reading between 0 & 1023, but I can alter it so I could get 0 to 29 in Arduino. How do you map the array?
Re: Scrolling through images
Reply #3 - Jan 20th, 2010, 8:58am
 
You don't map the array, but the read value to an array index, using map() function.
Re: Scrolling through images
Reply #4 - Jan 20th, 2010, 9:09am
 
okay, so for example i could:

float scroll = map(potInput, 0, 1023, 1, 30);

& then use whatever number scroll turns out to be to determine what picture?
Re: Scrolling through images
Reply #5 - Jan 20th, 2010, 1:11pm
 
So how do I actually apply the potentiometer number to the array? I can't seem to crack it...
Re: Scrolling through images
Reply #6 - Jan 20th, 2010, 1:17pm
 
looks good so far. you should convert it to an int though

int scroll = (int)map(potInput, 0, 1023, 1, 30);
image(imageArray[scroll],0,0);

Re: Scrolling through images
Reply #7 - Jan 20th, 2010, 3:00pm
 
If your array has size 30, you should use:
int scroll = (int)map(potInput, 0, 1023, 0, 29);
Re: Scrolling through images
Reply #8 - Jan 22nd, 2010, 5:16am
 
I'm having a bit of a problem getting all of the types of data correct, I keep getting the error:
"The method image(PImage, float, float, float, float) in the type PApplet is not applicable for the arguments (String, int, int, int, int)"

I don't know how to change the strings in the array into images.

Here's the code:

Code:
int picture;

String[] feed = new String[5];{
feed[0] = "http://www.adelaidecitycouncil.com/netcatapps/webcam/images/centralMkt.jpg"; //Adelaide Market
feed[1] = "http://www.cbc.ca/bc/webcam/images/webcam.jpg"; // Vancouver Building Site
feed[2] = "http://www.adelaidecitycouncil.com/netcatapps/webcam/images/rundleEast.jpg"; //Rundle Mall East & Lantern
feed[3] = "http://www.draperbee.com/webcam/pic/image.jpg?1262444320177"; //beehive
feed[4] = "http://www.adelaidecitycouncil.com//NetcatApps/webcam/images/bellsth.jpg"; //Adelaide Bell Street South
};
PImage[] images;

void setup() {
size (650, 500);

// need as many images as we have feeds
images = new PImage[feed.length];
// initial load of images (slow)
for (int i = 0 ; i < feed.length ; i++){
images[i] = loadImage(feed[i]);
}
}

void draw() {
loadImage(feed[picture]);
image(feed[picture], 0, 0, width/2, height/2);
}

void serialEvent(Serial Arduino) {
// read the serial buffer:
String myString = Arduino.readStringUntil('\n');
// if you got any bytes other than the linefeed:
if (myString != null) {

myString = trim(myString);

// split the string at the commas
// and convert the sections into integers:
int sensor[] = int(split(myString, ','));

// print out the values you got:
for (int sensorNum = 0; sensorNum < sensor.length; sensorNum++) {
print("sensor " + sensorNum + ": " + sensor[sensorNum] + "\t");
}
// add a linefeed after all the sensor values are printed:
println();
if (sensor.length > 1) {
picture = (int)map(sensor[0], 0, 1023, 0, 4);
}
}
}
Re: Scrolling through images
Reply #9 - Jan 22nd, 2010, 8:02am
 
Quote:
Code:
void draw() {
  loadImage(feed[picture]);
  image(feed[picture], 0, 0, width/2, height/2);
}

The loadImage in draw() is to avoid, because it is a slow operation (even more when you get it from the Net!) which you try to use 60 times per second! And the line is useless as you just drop the result of the operation...

Beside, you already loaded all the images in setup().
Which solves your problem: Code:
void draw() {
  image(images[picture], 0, 0, width/2, height/2);
}

Also change the map line to: Code:
picture = (int)map(sensor[0], 0, 1023, 0, images.length - 1); 

Re: Scrolling through images
Reply #10 - Jan 22nd, 2010, 8:22am
 
I've changed the code, but now the error is : "cannot convert PImage[] to Pimage" & highlights:
Code:
  
images = new PImage[feed.length];
Re: Scrolling through images
Reply #11 - Jan 22nd, 2010, 9:30am
 
Have you changed the declaration of images? It is correct, above.

Note: you can change the declaration of feed:
Code:
String[] feed = new String[] {
"http://www.adelaidecitycouncil.com/netcatapps/webcam/images/centralMkt.jpg", //Adelaide Market
// and so on, beware of , vs. ;
};
Re: Scrolling through images
Reply #12 - Jan 23rd, 2010, 8:35am
 
I've changed it again, but the same error message appears...
I'll post up the whole code that I'm actually using it for, just in case it's something in that that is causing the problem:

Code:

import processing.video.*; // import theProcessing video library
import processing.serial.*; // import the Processing serial library
Serial Arduino; // The serial port
Capture webCam; // The webcam feed
PFont font;

float xpos, ypos, onoff, scrolltext, x; // Starting position of the webcam feed
int picture;
float size = 700.0;

String[] feed = new String[] {
"http://www.adelaidecitycouncil.com/netcatapps/webcam/images/centralMkt.jpg", //Adelaide Market
"http://www.cbc.ca/bc/webcam/images/webcam.jpg", // Vancouver Building Site
"http://www.adelaidecitycouncil.com/netcatapps/webcam/images/rundleEast.jpg", //Rundle Mall East & Lantern
"http://www.draperbee.com/webcam/pic/image.jpg?1262444320177", //beehive
"http://www.adelaidecitycouncil.com//NetcatApps/webcam/images/bellsth.jpg" //Adelaide Bell Street South
};
PImage images;

void setup() {
size(678,510,P3D);

font = loadFont("01_Digit-23.vlw");
textFont(font, 23);
// List all the available serial ports & cameras
//println(Serial.list());
//println(Capture.list());

webCam = new Capture(this, width/2, height/2, "USB PC Camera-WDM", 30);
Arduino = new Serial(this, Serial.list()[1], 9600);

// read bytes into a buffer until you get a linefeed (ASCII 10):
Arduino.bufferUntil('\n');

// need as many images as we have feeds
images = new PImage[feed.length];
// initial load of images (slow)
for (int i = 0 ; i < feed.length ; i++){
images[i] = loadImage(feed[i]);
}
}

void draw() {
background(0);

if (webCam.available()){
webCam.read();
}
if (onoff == 1){
image(webCam, xpos, ypos);
}
else{
image(images[picture], xpos, ypos, width/2, height/2);
delay(1000);
}

x = x +3;
if (x > width + size){
x = -size;
}

if(scrolltext == 0){
translate(-x, 0, 0);
text("Directive 1: Mid-life transitions", 0, 494);
}
if(scrolltext == 1){
translate(-x, 0, 0);
text("Directive 2: Books & you", 0, 494);
}
}

void serialEvent(Serial Arduino) {
// read the serial buffer:
String myString = Arduino.readStringUntil('\n');
// if you got any bytes other than the linefeed:
if (myString != null) {

myString = trim(myString);

// split the string at the commas
// and convert the sections into integers:
int sensor[] = int(split(myString, ','));

// print out the values you got:
for (int sensorNum = 0; sensorNum < sensor.length; sensorNum++) {
print("sensor " + sensorNum + ": " + sensor[sensorNum] + "\t");
}
// add a linefeed after all the sensor values are printed:
println();
if (sensor.length > 1) {
xpos = map(sensor[0], 0, 1023, 0, (width - width/2));
ypos = map(sensor[1], 0, 1023, 0, (height - height/2));
picture = (int)map(sensor[2], 0, 1023, 0, images.length - 1);
onoff = map(sensor[3], 0, 1, 0, 1);
scrolltext = map(sensor[4], 0, 1023, 0, 2);
}
}
}
Re: Scrolling through images
Reply #13 - Jan 23rd, 2010, 8:46am
 
It was: PImage[] images; which is correct, as I stated.
You have: PImage images; which is wrong, it is no longer an array.
Re: Scrolling through images
Reply #14 - Jan 23rd, 2010, 8:48am
 
ah, got it! sorry for that, didn't notice it first time. Thanks
Pages: 1 2