Arduino and Processing Documentations
In this recitation, I tried to make some fun actions with the camera captured image. Inspired by the example codes given, I change the size and positions of each pixel of the camera captured image. These two values are controlled by the potentiometers from Arduino. By rotating the two potentiometers, the face of the user or whatever the camera is capturing would be formed by pixels of different size and position, making an interesting image to interact with.
This work is associated with the computer vision, since the computer camera inputs a image, and it process through different algorithms and output new images.
Codes for Arduino
void setup() { Serial.begin(9600); }w void loop() { int sensor1 = analogRead(A0); int sensor2 = analogRead(A1); Serial.print(sensor1); Serial.print(","); Serial.print(sensor2); Serial.println(); delay(100); }
Codes for Processing
import processing.serial.*; import processing.video.*; String[] cameras = Capture.list(); String myString = null; Serial myPort; int NUM_OF_VALUES = 2; int[] sensorValues; Capture cam; void setup() { size(640, 480); printArray(cam.list()); cam = new Capture(this, cam.list()[0]); cam.start(); setupSerial(); } void draw() { updateSerial(); clear(); printArray(sensorValues); if (cam.available()) { cam.read(); } if (sensorValues[0] < 10){ image(cam, 0, 0); }else{ float dotSpacing = map(sensorValues[0], 0, 1023, 1, 20); float dotSize = map(sensorValues[1], 0, height, 1, dotSpacing * 1.4); for (int x = 0; x < cam.width; x += dotSpacing) { for (int y = 0; y < cam.height; y += dotSpacing) { color c = cam.get(x, y); fill(c); noStroke(); circle(x, y, dotSize); } } } } void setupSerial() { printArray(Serial.list()); myPort = new Serial(this, Serial.list()[1], 9600); myPort.clear(); myString = myPort.readStringUntil( 10 ); myString = null; sensorValues = new int[NUM_OF_VALUES]; } void updateSerial() { while (myPort.available() > 0) { myString = myPort.readStringUntil( 10 ); if (myString != null) { String[] serialInArray = split(trim(myString), ","); if (serialInArray.length == NUM_OF_VALUES) { for (int i=0; i<serialInArray.length; i++) { sensorValues[i] = int(serialInArray[i]); } } } } }