|
|
|
|
|
|
|
|
#include "ofApp.h" |
|
|
#include "ofApp.h" |
|
|
|
|
|
|
|
|
#define VIDEO_WIDTH 568 |
|
|
|
|
|
#define VIDEO_HEIGHT 320 |
|
|
|
|
|
|
|
|
#define VIDEO_WIDTH 360 |
|
|
|
|
|
#define VIDEO_HEIGHT 640 |
|
|
|
|
|
|
|
|
//-------------------------------------------------------------- |
|
|
//-------------------------------------------------------------- |
|
|
void ofApp::setup(){ |
|
|
void ofApp::setup(){ |
|
|
vidPlayer.load("beer.mkv"); // in /bin/data/ |
|
|
|
|
|
|
|
|
vidPlayer.load("video.mkv"); // in /bin/data/ |
|
|
vidPlayer.play(); |
|
|
vidPlayer.play(); |
|
|
vidPlayer.setLoopState(OF_LOOP_NORMAL); |
|
|
vidPlayer.setLoopState(OF_LOOP_NORMAL); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
vidPlayer.update(); |
|
|
vidPlayer.update(); |
|
|
colorVideo.setFromPixels(vidPlayer.getPixels()); |
|
|
colorVideo.setFromPixels(vidPlayer.getPixels()); |
|
|
|
|
|
|
|
|
grayVideo = colorVideo; // Convert Color to Grayscale |
|
|
grayVideo = colorVideo; // Convert Color to Grayscale |
|
|
|
|
|
|
|
|
|
|
|
//cvInRange(); |
|
|
|
|
|
//colorVideo.convertToGrayscalePlanarImage(red, 0); |
|
|
|
|
|
|
|
|
if (learnBackground){ |
|
|
if (learnBackground){ |
|
|
background = grayVideo; |
|
|
|
|
|
|
|
|
recognizer.setBackground(grayVideo); |
|
|
learnBackground = false; |
|
|
learnBackground = false; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// Background subtraction |
|
|
|
|
|
binarized.absDiff(background, grayVideo); |
|
|
|
|
|
// Binarization |
|
|
|
|
|
binarized.threshold(threshhold); |
|
|
|
|
|
|
|
|
|
|
|
contourFinder.findContours( |
|
|
|
|
|
binarized, |
|
|
|
|
|
10, |
|
|
|
|
|
VIDEO_HEIGHT * VIDEO_WIDTH / 10, |
|
|
|
|
|
10, |
|
|
|
|
|
true); |
|
|
|
|
|
|
|
|
recognizer.setThreshhold(threshhold); |
|
|
|
|
|
recognizer.update(grayVideo, VIDEO_WIDTH, VIDEO_HEIGHT); |
|
|
|
|
|
|
|
|
|
|
|
background = recognizer.background; |
|
|
|
|
|
subtracted = recognizer.subtracted; |
|
|
|
|
|
binarized = recognizer.binarized; |
|
|
|
|
|
contourFinder = recognizer.contourFinder; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//-------------------------------------------------------------- |
|
|
//-------------------------------------------------------------- |
|
|
|
|
|
|
|
|
ofSetHexColor(0xffffff); |
|
|
ofSetHexColor(0xffffff); |
|
|
colorVideo.draw(20, 20); |
|
|
colorVideo.draw(20, 20); |
|
|
grayVideo.draw(40 + VIDEO_WIDTH, 20); |
|
|
grayVideo.draw(40 + VIDEO_WIDTH, 20); |
|
|
background.draw(20, 40 + VIDEO_HEIGHT); |
|
|
|
|
|
binarized.draw(40 + VIDEO_WIDTH, 40 + VIDEO_HEIGHT); |
|
|
|
|
|
|
|
|
subtracted.draw(60 + 2 * VIDEO_WIDTH, 20); |
|
|
|
|
|
//binarized.draw(80 + 3 * VIDEO_WIDTH, 20); |
|
|
|
|
|
//colorVideo.draw(20, 20); |
|
|
|
|
|
//grayVideo.draw(40 + VIDEO_WIDTH, 20); |
|
|
|
|
|
//background.draw(20, 40 + VIDEO_HEIGHT); |
|
|
|
|
|
//binarized.draw(40 + VIDEO_WIDTH, 40 + VIDEO_HEIGHT); |
|
|
|
|
|
|
|
|
|
|
|
//red.draw(40 + VIDEO_WIDTH, 20); |
|
|
|
|
|
//green.draw(20, 40 + VIDEO_HEIGHT); |
|
|
|
|
|
//blue.draw(40 + VIDEO_WIDTH, 40 + VIDEO_HEIGHT); |
|
|
|
|
|
|
|
|
ofFill(); |
|
|
ofFill(); |
|
|
ofSetHexColor(0x333333); |
|
|
ofSetHexColor(0x333333); |
|
|
ofDrawRectangle(40 + VIDEO_WIDTH, 60 + VIDEO_HEIGHT + VIDEO_HEIGHT, VIDEO_WIDTH, VIDEO_HEIGHT); |
|
|
|
|
|
|
|
|
ofDrawRectangle(80 + 3 * VIDEO_WIDTH, 20, VIDEO_WIDTH, VIDEO_HEIGHT); |
|
|
ofSetHexColor(0xffffff); |
|
|
ofSetHexColor(0xffffff); |
|
|
|
|
|
|
|
|
for (int i = 0; i < contourFinder.blobs.size(); i++) { |
|
|
for (int i = 0; i < contourFinder.blobs.size(); i++) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (aspect_ratio > 0.5 && aspect_ratio < 1.5) |
|
|
if (aspect_ratio > 0.5 && aspect_ratio < 1.5) |
|
|
{ |
|
|
{ |
|
|
blob.draw(40 + VIDEO_WIDTH, 60 + VIDEO_HEIGHT + VIDEO_HEIGHT); |
|
|
|
|
|
|
|
|
blob.draw(80 + 3 * VIDEO_WIDTH, 20); |
|
|
ofDrawBitmapString(sizeStr.str(), |
|
|
ofDrawBitmapString(sizeStr.str(), |
|
|
contourFinder.blobs[i].boundingRect.getCenter().x + 40 + VIDEO_WIDTH, |
|
|
|
|
|
contourFinder.blobs[i].boundingRect.getCenter().y + 60 + VIDEO_HEIGHT + VIDEO_HEIGHT); |
|
|
|
|
|
|
|
|
contourFinder.blobs[i].boundingRect.getCenter().x + 80 + 3 * VIDEO_WIDTH, |
|
|
|
|
|
contourFinder.blobs[i].boundingRect.getCenter().y + 20); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|