FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

new gsvideo library · p-render/processing@430bce3 · GitHub

new gsvideo library · p-render/processing@430bce3 · GitHub
Skip to content

Navigation Menu

Repository navigation

Commit 430bce3

Browse files
committed
new gsvideo library
1 parent 82fedb3 commit 430bce3

66 files changed

Lines changed: 6561 additions & 1 deletion

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎core/todo.txt‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@ A (was only happening once b/c was drawing first in perspective)
1111
A seems to be mapping to 0, 0 - width/2, height/2
1212
A fix 3D > OrthoVsPerspective example once ortho works properly
1313
A there's a depth problem in addition to the ortho weirdness
14-
1514
A using createGraphics() image repeatedly runs out of memory with OPENGL
1615
A http://code.google.com/p/processing/issues/detail?id=483
1716
X works with OPENGL2, so no problem
17+
A finish OPENGL2 renderer
18+
A http://code.google.com/p/processing/issues/detail?id=495
1819

1920
_ Potential race condition when resizing sketches
2021
_ http://code.google.com/p/processing/issues/detail?id=697

‎java/libraries/video/.classpath‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="src" path="src"/>
4+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
5+
<classpathentry kind="lib" path="lib/gstreamer-java.jar"/>
6+
<classpathentry kind="lib" path="lib/jna.jar"/>
7+
<classpathentry kind="lib" path="/home/andres/Coding/Processing/libs/1.5/core.jar"/>
8+
<classpathentry kind="output" path="bin"/>
9+
</classpath>

‎java/libraries/video/.project‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>GSVideo</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
</buildSpec>
14+
<natures>
15+
<nature>org.eclipse.jdt.core.javanature</nature>
16+
</natures>
17+
</projectDescription>

‎java/libraries/video/build.xml‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0"?>
2+
<project name="Processing Video Library" default="build">
3+
4+
<target name="clean" description="Clean the build directories">
5+
<delete dir="bin" />
6+
<delete file="library/video.jar" />
7+
</target>
8+
9+
<target name="compile" description="Compile sources">
10+
<condition property="core-built">
11+
<available file="../../../core/core.jar" />
12+
</condition>
13+
<fail unless="core-built" message="Please build the core library first and make sure it sits in ../../../core/core.jar" />
14+
15+
<mkdir dir="bin" />
16+
<javac target="1.5"
17+
srcdir="src" destdir="bin"
18+
encoding="UTF-8"
19+
includeAntRuntime="false"
20+
classpath="../../../core/core.jar; library/gstreamer-java.jar; library/jna.jar" />
21+
</target>
22+
23+
<target name="build" depends="compile" description="Build video library">
24+
<jar basedir="bin" destfile="library/video.jar" />
25+
</target>
26+
</project>
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
/**
2+
* ASCII Video
3+
* by Ben Fry.
4+
*
5+
* GSVideo version by Andres Colubri.
6+
*
7+
* Text characters have been used to represent images since the earliest computers.
8+
* This sketch is a simple homage that re-interprets live video as ASCII text.
9+
* See the keyPressed function for more options, like changing the font size.
10+
*/
11+
12+
import processing.opengl.*;
13+
import codeanticode.gsvideo.*;
14+
15+
GSCapture video;
16+
boolean cheatScreen;
17+
18+
// All ASCII characters, sorted according to their visual density
19+
String letterOrder =
20+
" .`-_':,;^=+/\"|)\\<>)iv%xclrs{*}I?!][1taeo7zjLu" +
21+
"nT#JCwfy325Fp6mqSghVd4EgXPGZbYkOA&8U$@KHDBWNMR0Q";
22+
char[] letters;
23+
24+
float[] bright;
25+
char[] chars;
26+
27+
PFont font;
28+
float fontSize = 1.5;
29+
30+
31+
public void setup() {
32+
size(640, 480, P3D);
33+
// Or run full screen, more fun! Use with Sketch -> Present
34+
//size(screen.width, screen.height, OPENGL);
35+
36+
// Uses the default video input, see the reference if this causes an error
37+
video = new GSCapture(this, 160, 120);
38+
video.play();
39+
int count = video.width * video.height;
40+
println(count);
41+
42+
font = loadFont("UniversLTStd-Light-48.vlw");
43+
44+
// for the 256 levels of brightness, distribute the letters across
45+
// the an array of 256 elements to use for the lookup
46+
letters = new char[256];
47+
for (int i = 0; i < 256; i++) {
48+
int index = int(map(i, 0, 256, 0, letterOrder.length()));
49+
letters[i] = letterOrder.charAt(index);
50+
}
51+
52+
// current characters for each position in the video
53+
chars = new char[count];
54+
55+
// current brightness for each point
56+
bright = new float[count];
57+
for (int i = 0; i < count; i++) {
58+
// set each brightness at the midpoint to start
59+
bright[i] = 128;
60+
}
61+
}
62+
63+
64+
public void captureEvent(GSCapture c) {
65+
c.read();
66+
}
67+
68+
69+
void draw() {
70+
background(0);
71+
72+
pushMatrix();
73+
74+
float hgap = width / float(video.width);
75+
float vgap = height / float(video.height);
76+
77+
scale(max(hgap, vgap) * fontSize);
78+
textFont(font, fontSize);
79+
80+
int index = 0;
81+
for (int y = 1; y < video.height; y++) {
82+
83+
// Move down for next line
84+
translate(0, 1.0 / fontSize);
85+
86+
pushMatrix();
87+
for (int x = 0; x < video.width; x++) {
88+
int pixelColor = video.pixels[index];
89+
// Faster method of calculating r, g, b than red(), green(), blue()
90+
int r = (pixelColor >> 16) & 0xff;
91+
int g = (pixelColor >> 8) & 0xff;
92+
int b = pixelColor & 0xff;
93+
94+
// Another option would be to properly calculate brightness as luminance:
95+
// luminance = 0.3*red + 0.59*green + 0.11*blue
96+
// Or you could instead red + green + blue, and make the the values[] array
97+
// 256*3 elements long instead of just 256.
98+
int pixelBright = max(r, g, b);
99+
100+
// The 0.1 value is used to damp the changes so that letters flicker less
101+
float diff = pixelBright - bright[index];
102+
bright[index] += diff * 0.1;
103+
104+
fill(pixelColor);
105+
int num = int(bright[index]);
106+
text(letters[num], 0, 0);
107+
108+
// Move to the next pixel
109+
index++;
110+
111+
// Move over for next character
112+
translate(1.0 / fontSize, 0);
113+
}
114+
popMatrix();
115+
}
116+
popMatrix();
117+
118+
if (cheatScreen) {
119+
//image(video, 0, height - video.height);
120+
// set() is faster than image() when drawing untransformed images
121+
set(0, height - video.height, video);
122+
}
123+
}
124+
125+
126+
/**
127+
* Handle key presses:
128+
* 'c' toggles the cheat screen that shows the original image in the corner
129+
* 'g' grabs an image and saves the frame to a tiff image
130+
* 'f' and 'F' increase and decrease the font size
131+
*/
132+
public void keyPressed() {
133+
switch (key) {
134+
case 'g': saveFrame(); break;
135+
case 'c': cheatScreen = !cheatScreen; break;
136+
case 'f': fontSize *= 1.1; break;
137+
case 'F': fontSize *= 0.9; break;
138+
}
139+
}
Binary file not shown.
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/**
2+
* Background Subtraction
3+
* by Golan Levin.
4+
*
5+
* GSVideo version by Andres Colubri.
6+
*
7+
* Detect the presence of people and objects in the frame using a simple
8+
* background-subtraction technique. To initialize the background, press a key.
9+
*/
10+
11+
12+
import codeanticode.gsvideo.*;
13+
14+
int numPixels;
15+
int[] backgroundPixels;
16+
GSCapture video;
17+
18+
void setup() {
19+
// Change size to 320 x 240 if too slow at 640 x 480
20+
size(640, 480);
21+
22+
video = new GSCapture(this, width, height);
23+
video.play();
24+
numPixels = video.width * video.height;
25+
// Create array to store the background image
26+
backgroundPixels = new int[numPixels];
27+
// Make the pixels[] array available for direct manipulation
28+
loadPixels();
29+
}
30+
31+
void draw() {
32+
if (video.available()) {
33+
video.read(); // Read a new video frame
34+
video.loadPixels(); // Make the pixels of video available
35+
// Difference between the current frame and the stored background
36+
int presenceSum = 0;
37+
for (int i = 0; i < numPixels; i++) { // For each pixel in the video frame...
38+
// Fetch the current color in that location, and also the color
39+
// of the background in that spot
40+
color currColor = video.pixels[i];
41+
color bkgdColor = backgroundPixels[i];
42+
// Extract the red, green, and blue components of the current pixelÕs color
43+
int currR = (currColor >> 16) & 0xFF;
44+
int currG = (currColor >> 8) & 0xFF;
45+
int currB = currColor & 0xFF;
46+
// Extract the red, green, and blue components of the background pixelÕs color
47+
int bkgdR = (bkgdColor >> 16) & 0xFF;
48+
int bkgdG = (bkgdColor >> 8) & 0xFF;
49+
int bkgdB = bkgdColor & 0xFF;
50+
// Compute the difference of the red, green, and blue values
51+
int diffR = abs(currR - bkgdR);
52+
int diffG = abs(currG - bkgdG);
53+
int diffB = abs(currB - bkgdB);
54+
// Add these differences to the running tally
55+
presenceSum += diffR + diffG + diffB;
56+
// Render the difference image to the screen
57+
pixels[i] = color(diffR, diffG, diffB);
58+
// The following line does the same thing much faster, but is more technical
59+
//pixels[i] = 0xFF000000 | (diffR << 16) | (diffG << 8) | diffB;
60+
}
61+
updatePixels(); // Notify that the pixels[] array has changed
62+
println(presenceSum); // Print out the total amount of movement
63+
}
64+
}
65+
66+
// When a key is pressed, capture the background image into the backgroundPixels
67+
// buffer, by copying each of the current frameÕs pixels into it.
68+
void keyPressed() {
69+
video.loadPixels();
70+
arraycopy(video.pixels, backgroundPixels);
71+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/**
2+
* Brightness Thresholding
3+
* by Golan Levin.
4+
*
5+
* GSVideo version by Andres Colubri.
6+
*
7+
* Determines whether a test location (such as the cursor) is contained within
8+
* the silhouette of a dark object.
9+
*/
10+
11+
12+
import codeanticode.gsvideo.*;
13+
14+
color black = color(0);
15+
color white = color(255);
16+
int numPixels;
17+
GSCapture video;
18+
19+
void setup() {
20+
size(640, 480); // Change size to 320 x 240 if too slow at 640 x 480
21+
strokeWeight(5);
22+
// Uses the default video input, see the reference if this causes an error
23+
video = new GSCapture(this, width, height);
24+
video.play();
25+
numPixels = video.width * video.height;
26+
noCursor();
27+
smooth();
28+
}
29+
30+
void draw() {
31+
if (video.available()) {
32+
video.read();
33+
video.loadPixels();
34+
int threshold = 127; // Set the threshold value
35+
float pixelBrightness; // Declare variable to store a pixel's color
36+
// Turn each pixel in the video frame black or white depending on its brightness
37+
loadPixels();
38+
for (int i = 0; i < numPixels; i++) {
39+
pixelBrightness = brightness(video.pixels[i]);
40+
if (pixelBrightness > threshold) { // If the pixel is brighter than the
41+
pixels[i] = white; // threshold value, make it white
42+
}
43+
else { // Otherwise,
44+
pixels[i] = black; // make it black
45+
}
46+
}
47+
updatePixels();
48+
// Test a location to see where it is contained. Fetch the pixel at the test
49+
// location (the cursor), and compute its brightness
50+
int testValue = get(mouseX, mouseY);
51+
float testBrightness = brightness(testValue);
52+
if (testBrightness > threshold) { // If the test location is brighter than
53+
fill(black); // the threshold set the fill to black
54+
}
55+
else { // Otherwise,
56+
fill(white); // set the fill to white
57+
}
58+
ellipse(mouseX, mouseY, 20, 20);
59+
}
60+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/**
2+
* Brightness Tracking
3+
* by Golan Levin.
4+
*
5+
* GSVideo version by Andres Colubri.
6+
*
7+
* Tracks the brightest pixel in a live video signal.
8+
*/
9+
10+
11+
import codeanticode.gsvideo.*;
12+
13+
GSCapture video;
14+
15+
void setup() {
16+
size(640, 480); // Change size to 320 x 240 if too slow at 640 x 480
17+
// Uses the default video input, see the reference if this causes an error
18+
video = new GSCapture(this, width, height);
19+
video.play();
20+
noStroke();
21+
smooth();
22+
}
23+
24+
void draw() {
25+
if (video.available()) {
26+
video.read();
27+
image(video, 0, 0, width, height); // Draw the webcam video onto the screen
28+
int brightestX = 0; // X-coordinate of the brightest video pixel
29+
int brightestY = 0; // Y-coordinate of the brightest video pixel
30+
float brightestValue = 0; // Brightness of the brightest video pixel
31+
// Search for the brightest pixel: For each row of pixels in the video image and
32+
// for each pixel in the yth row, compute each pixel's index in the video
33+
video.loadPixels();
34+
int index = 0;
35+
for (int y = 0; y < video.height; y++) {
36+
for (int x = 0; x < video.width; x++) {
37+
// Get the color stored in the pixel
38+
int pixelValue = video.pixels[index];
39+
// Determine the brightness of the pixel
40+
float pixelBrightness = brightness(pixelValue);
41+
// If that value is brighter than any previous, then store the
42+
// brightness of that pixel, as well as its (x,y) location
43+
if (pixelBrightness > brightestValue) {
44+
brightestValue = pixelBrightness;
45+
brightestY = y;
46+
brightestX = x;
47+
}
48+
index++;
49+
}
50+
}
51+
// Draw a large, yellow circle at the brightest pixel
52+
fill(255, 204, 0, 128);
53+
ellipse(brightestX, brightestY, 200, 200);
54+
}
55+
}

0 commit comments

Comments
 (0)

Footer

© 2026 GitHub, Inc.

Back | FazBrowse Home | New Git URL