forked from CodingTrain/website-archive
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
690 changed files
with
286 additions
and
1 deletion.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// Daniel Shiffman | ||
// http://codingrainbow.com | ||
// http://patreon.com/codingrainbow | ||
// Code for: https://youtu.be/r0lvsMPGEoY | ||
|
||
class Blob { | ||
float minx; | ||
float miny; | ||
float maxx; | ||
float maxy; | ||
|
||
int id = 0; | ||
|
||
boolean taken = false; | ||
|
||
Blob(float x, float y) { | ||
minx = x; | ||
miny = y; | ||
maxx = x; | ||
maxy = y; | ||
} | ||
|
||
void show() { | ||
stroke(0); | ||
fill(255, 100); | ||
strokeWeight(2); | ||
rectMode(CORNERS); | ||
rect(minx, miny, maxx, maxy); | ||
|
||
textAlign(CENTER); | ||
textSize(64); | ||
fill(0); | ||
text(id, minx + (maxx-minx)*0.5, maxy - 10); | ||
} | ||
|
||
|
||
void add(float x, float y) { | ||
minx = min(minx, x); | ||
miny = min(miny, y); | ||
maxx = max(maxx, x); | ||
maxy = max(maxy, y); | ||
} | ||
|
||
void become(Blob other) { | ||
minx = other.minx; | ||
maxx = other.maxx; | ||
miny = other.miny; | ||
maxy = other.maxy; | ||
} | ||
|
||
float size() { | ||
return (maxx-minx)*(maxy-miny); | ||
} | ||
|
||
PVector getCenter() { | ||
float x = (maxx - minx)* 0.5 + minx; | ||
float y = (maxy - miny)* 0.5 + miny; | ||
return new PVector(x,y); | ||
} | ||
|
||
boolean isNear(float x, float y) { | ||
|
||
float cx = max(min(x, maxx), minx); | ||
float cy = max(min(y, maxy), miny); | ||
float d = distSq(cx, cy, x, y); | ||
|
||
if (d < distThreshold*distThreshold) { | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
} | ||
} |
192 changes: 192 additions & 0 deletions
192
Processing/11_video/sketch_11_9_BlobTrackingIDs/sketch_11_9_BlobTrackingIDs.pde
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,192 @@ | ||
// Daniel Shiffman | ||
// http://codingrainbow.com | ||
// http://patreon.com/codingrainbow | ||
// Code for: https://youtu.be/r0lvsMPGEoY | ||
|
||
import processing.video.*; | ||
|
||
Capture video; | ||
|
||
int blobCounter = 0; | ||
|
||
int maxLife = 200; | ||
|
||
color trackColor; | ||
float threshold = 40; | ||
float distThreshold = 50; | ||
|
||
ArrayList<Blob> blobs = new ArrayList<Blob>(); | ||
|
||
void setup() { | ||
size(640, 360); | ||
String[] cameras = Capture.list(); | ||
printArray(cameras); | ||
video = new Capture(this, cameras[3]); | ||
video.start(); | ||
// 183.0 12.0 83.0 | ||
trackColor = color(183, 12, 83); | ||
} | ||
|
||
void captureEvent(Capture video) { | ||
video.read(); | ||
} | ||
|
||
void keyPressed() { | ||
if (key == 'a') { | ||
distThreshold+=5; | ||
} else if (key == 'z') { | ||
distThreshold-=5; | ||
} | ||
if (key == 's') { | ||
threshold+=5; | ||
} else if (key == 'x') { | ||
threshold-=5; | ||
} | ||
} | ||
|
||
void draw() { | ||
video.loadPixels(); | ||
image(video, 0, 0); | ||
|
||
ArrayList<Blob> currentBlobs = new ArrayList<Blob>(); | ||
|
||
// Begin loop to walk through every pixel | ||
for (int x = 0; x < video.width; x++ ) { | ||
for (int y = 0; y < video.height; y++ ) { | ||
int loc = x + y * video.width; | ||
// What is current color | ||
color currentColor = video.pixels[loc]; | ||
float r1 = red(currentColor); | ||
float g1 = green(currentColor); | ||
float b1 = blue(currentColor); | ||
float r2 = red(trackColor); | ||
float g2 = green(trackColor); | ||
float b2 = blue(trackColor); | ||
|
||
float d = distSq(r1, g1, b1, r2, g2, b2); | ||
|
||
if (d < threshold*threshold) { | ||
|
||
boolean found = false; | ||
for (Blob b : currentBlobs) { | ||
if (b.isNear(x, y)) { | ||
b.add(x, y); | ||
found = true; | ||
break; | ||
} | ||
} | ||
|
||
if (!found) { | ||
Blob b = new Blob(x, y); | ||
currentBlobs.add(b); | ||
} | ||
} | ||
} | ||
} | ||
|
||
for (int i = currentBlobs.size()-1; i >= 0; i--) { | ||
if (currentBlobs.get(i).size() < 500) { | ||
currentBlobs.remove(i); | ||
} | ||
} | ||
|
||
// There are no blobs! | ||
if (blobs.isEmpty() && currentBlobs.size() > 0) { | ||
println("Adding blobs!"); | ||
for (Blob b : currentBlobs) { | ||
b.id = blobCounter; | ||
blobs.add(b); | ||
blobCounter++; | ||
} | ||
} else if (blobs.size() <= currentBlobs.size()) { | ||
// Match whatever blobs you can match | ||
for (Blob b : blobs) { | ||
float recordD = 1000; | ||
Blob matched = null; | ||
for (Blob cb : currentBlobs) { | ||
PVector centerB = b.getCenter(); | ||
PVector centerCB = cb.getCenter(); | ||
float d = PVector.dist(centerB, centerCB); | ||
if (d < recordD && !cb.taken) { | ||
recordD = d; | ||
matched = cb; | ||
} | ||
} | ||
matched.taken = true; | ||
b.become(matched); | ||
} | ||
|
||
// Whatever is leftover make new blobs | ||
for (Blob b : currentBlobs) { | ||
if (!b.taken) { | ||
b.id = blobCounter; | ||
blobs.add(b); | ||
blobCounter++; | ||
} | ||
} | ||
} else if (blobs.size() > currentBlobs.size()) { | ||
for (Blob b : blobs) { | ||
b.taken = false; | ||
} | ||
|
||
|
||
// Match whatever blobs you can match | ||
for (Blob cb : currentBlobs) { | ||
float recordD = 1000; | ||
Blob matched = null; | ||
for (Blob b : blobs) { | ||
PVector centerB = b.getCenter(); | ||
PVector centerCB = cb.getCenter(); | ||
float d = PVector.dist(centerB, centerCB); | ||
if (d < recordD && !b.taken) { | ||
recordD = d; | ||
matched = b; | ||
} | ||
} | ||
if (matched != null) { | ||
matched.taken = true; | ||
matched.become(cb); | ||
} | ||
} | ||
|
||
for (int i = blobs.size() - 1; i >= 0; i--) { | ||
Blob b = blobs.get(i); | ||
if (!b.taken) { | ||
blobs.remove(i); | ||
} | ||
} | ||
} | ||
|
||
for (Blob b : blobs) { | ||
b.show(); | ||
} | ||
|
||
|
||
|
||
textAlign(RIGHT); | ||
fill(0); | ||
//text(currentBlobs.size(), width-10, 40); | ||
//text(blobs.size(), width-10, 80); | ||
textSize(24); | ||
text("color threshold: " + threshold, width-10, 50); | ||
text("distance threshold: " + distThreshold, width-10, 25); | ||
} | ||
|
||
|
||
float distSq(float x1, float y1, float x2, float y2) { | ||
float d = (x2-x1)*(x2-x1) + (y2-y1)*(y2-y1); | ||
return d; | ||
} | ||
|
||
|
||
float distSq(float x1, float y1, float z1, float x2, float y2, float z2) { | ||
float d = (x2-x1)*(x2-x1) + (y2-y1)*(y2-y1) +(z2-z1)*(z2-z1); | ||
return d; | ||
} | ||
|
||
void mousePressed() { | ||
// Save color where the mouse is clicked in trackColor variable | ||
int loc = mouseX + mouseY*video.width; | ||
trackColor = video.pixels[loc]; | ||
println(red(trackColor), green(trackColor), blue(trackColor)); | ||
} |
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Video-Lessons | ||
|
||
I'm using this repo to keep track of supplemental content for my video lessons. This includes: | ||
* captions | ||
* accompanying source code | ||
* notes with links and other materials referenced in the videos | ||
* better video descriptions for vimeo or youtube pages | ||
|
||
# Questions? Need Support? | ||
* Join: http://patreon.com/codingrainbow | ||
|
||
# Learning Processing video site | ||
* http://learningprocessing.com/videos/ | ||
|
||
# Youtube | ||
* https://www.youtube.com/user/shiffman/playlists?view=50&shelf_id=2&sort=dd | ||
* https://www.youtube.com/user/shiffman/playlists?view=50&shelf_id=6&sort=dd | ||
|
||
# Vimeo channels | ||
* https://vimeo.com/channels/introcompmedia | ||
* https://vimeo.com/channels/natureofcode |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.