Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Histogram Viewer derived from the "Histogram" built-in example sketch.
- *
- * Calculates the histogram based on the image from the camera feed.
- */
- import gohai.glvideo.*;
- GLCapture video;
- void setup() {
- size(640, 480, P2D);
- String[] devices = GLCapture.list();
- println("Devices:");
- printArray(devices);
- // Use camera resolution of 640x480 pixels at 24 frames per second
- video = new GLCapture(this, devices[0], 640, 480, 24);
- video.start();
- }
- void draw() {
- background(0);
- if (video.available()) {
- video.read();
- }
- image(video, 0, 0);
- int[] hist = new int[256];
- // Calculate the histogram
- for (int i = 0; i < video.width; i++) {
- for (int j = 0; j < video.height; j++) {
- int bright = int(brightness(get(i, j)));
- hist[bright]++;
- }
- }
- // Find the largest value in the histogram
- int histMax = max(hist);
- stroke(255);
- // Draw half of the histogram (skip every second value)
- for (int i = 0; i < video.width; i += 2) {
- // Map i (from 0..img.width) to a location in the histogram (0..255)
- int which = int(map(i, 0, video.width, 0, 255));
- // Convert the histogram value to a location between
- // the bottom and the top of the picture
- int y = int(map(hist[which], 0, histMax, video.height, 0));
- line(i, video.height, i, y);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement