Compare commits
1
Commits
ac25d8fdf1
..
output
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
def7b4fdf2 |
No files matched your search
@@ -1,2 +1 @@
|
|||||||
ofxGui
|
|
||||||
ofxOpenCv
|
ofxOpenCv
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
Video mit FFMPEG verkleinern:
|
|
||||||
|
|
||||||
ffmpeg -i beer.mkv -s 568x320 -c:a copy shrink.mkv
|
|
||||||
+1
-72
@@ -1,94 +1,23 @@
|
|||||||
#include "ofApp.h"
|
#include "ofApp.h"
|
||||||
|
|
||||||
#define VIDEO_WIDTH 568
|
|
||||||
#define VIDEO_HEIGHT 320
|
|
||||||
|
|
||||||
//--------------------------------------------------------------
|
//--------------------------------------------------------------
|
||||||
void ofApp::setup(){
|
void ofApp::setup(){
|
||||||
vidPlayer.load("beer.mkv"); // in /bin/data/
|
|
||||||
vidPlayer.play();
|
|
||||||
vidPlayer.setLoopState(OF_LOOP_NORMAL);
|
|
||||||
|
|
||||||
colorVideo.allocate(VIDEO_WIDTH, VIDEO_HEIGHT);
|
|
||||||
grayVideo.allocate(VIDEO_WIDTH, VIDEO_HEIGHT);
|
|
||||||
|
|
||||||
learnBackground = true;
|
|
||||||
threshhold = 80;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------
|
//--------------------------------------------------------------
|
||||||
void ofApp::update(){
|
void ofApp::update(){
|
||||||
|
|
||||||
vidPlayer.update();
|
|
||||||
colorVideo.setFromPixels(vidPlayer.getPixels());
|
|
||||||
|
|
||||||
grayVideo = colorVideo; // Convert Color to Grayscale
|
|
||||||
|
|
||||||
if (learnBackground){
|
|
||||||
background = grayVideo;
|
|
||||||
learnBackground = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Background subtraction
|
|
||||||
binarized.absDiff(background, grayVideo);
|
|
||||||
// Binarization
|
|
||||||
binarized.threshold(threshhold);
|
|
||||||
|
|
||||||
contourFinder.findContours(
|
|
||||||
binarized,
|
|
||||||
10,
|
|
||||||
VIDEO_HEIGHT * VIDEO_WIDTH / 10,
|
|
||||||
10,
|
|
||||||
true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------
|
//--------------------------------------------------------------
|
||||||
void ofApp::draw(){
|
void ofApp::draw(){
|
||||||
ofSetHexColor(0xffffff);
|
|
||||||
colorVideo.draw(20, 20);
|
|
||||||
grayVideo.draw(40 + VIDEO_WIDTH, 20);
|
|
||||||
background.draw(20, 40 + VIDEO_HEIGHT);
|
|
||||||
binarized.draw(40 + VIDEO_WIDTH, 40 + VIDEO_HEIGHT);
|
|
||||||
|
|
||||||
ofFill();
|
|
||||||
ofSetHexColor(0x333333);
|
|
||||||
ofDrawRectangle(40 + VIDEO_WIDTH, 60 + VIDEO_HEIGHT + VIDEO_HEIGHT, VIDEO_WIDTH, VIDEO_HEIGHT);
|
|
||||||
ofSetHexColor(0xffffff);
|
|
||||||
|
|
||||||
for (int i = 0; i < contourFinder.blobs.size(); i++) {
|
|
||||||
ofxCvBlob blob = contourFinder.blobs[i];
|
|
||||||
|
|
||||||
|
|
||||||
// draw over the centroid if the blob is a hole
|
|
||||||
ofSetColor(255);
|
|
||||||
|
|
||||||
// https://docs.opencv.org/master/d1/d32/tutorial_py_contour_properties.html
|
|
||||||
float aspect_ratio = blob.boundingRect.getWidth() / blob.boundingRect.getHeight();
|
|
||||||
|
|
||||||
stringstream sizeStr;
|
|
||||||
sizeStr << std::to_string(i) << ": " << std::to_string(contourFinder.blobs[i].area);
|
|
||||||
sizeStr << " | F=" << aspect_ratio;
|
|
||||||
|
|
||||||
|
|
||||||
if (aspect_ratio > 0.5 && aspect_ratio < 1.5)
|
|
||||||
{
|
|
||||||
blob.draw(40 + VIDEO_WIDTH, 60 + VIDEO_HEIGHT + VIDEO_HEIGHT);
|
|
||||||
ofDrawBitmapString(sizeStr.str(),
|
|
||||||
contourFinder.blobs[i].boundingRect.getCenter().x + 40 + VIDEO_WIDTH,
|
|
||||||
contourFinder.blobs[i].boundingRect.getCenter().y + 60 + VIDEO_HEIGHT + VIDEO_HEIGHT);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------
|
//--------------------------------------------------------------
|
||||||
void ofApp::keyPressed(int key){
|
void ofApp::keyPressed(int key){
|
||||||
if (key == '-') threshhold--;
|
|
||||||
else if (key == '+') threshhold++;
|
|
||||||
else if (key == ' ') learnBackground = true;
|
|
||||||
else if (key == '0') vidPlayer.setPaused(!vidPlayer.isPaused());
|
|
||||||
else if (key == OF_KEY_RIGHT) vidPlayer.nextFrame();
|
|
||||||
else if (key == OF_KEY_LEFT) vidPlayer.previousFrame();
|
|
||||||
else;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------
|
//--------------------------------------------------------------
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "ofMain.h"
|
#include "ofMain.h"
|
||||||
#include "ofxOpenCv.h"
|
|
||||||
|
|
||||||
class ofApp : public ofBaseApp{
|
class ofApp : public ofBaseApp{
|
||||||
|
|
||||||
@@ -22,17 +21,4 @@ class ofApp : public ofBaseApp{
|
|||||||
void dragEvent(ofDragInfo dragInfo);
|
void dragEvent(ofDragInfo dragInfo);
|
||||||
void gotMessage(ofMessage msg);
|
void gotMessage(ofMessage msg);
|
||||||
|
|
||||||
ofVideoPlayer vidPlayer;
|
|
||||||
|
|
||||||
// Images displaying original video
|
|
||||||
ofxCvColorImage colorVideo;
|
|
||||||
ofxCvGrayscaleImage grayVideo;
|
|
||||||
|
|
||||||
ofxCvGrayscaleImage background;
|
|
||||||
ofxCvGrayscaleImage binarized;
|
|
||||||
|
|
||||||
ofxCvContourFinder contourFinder;
|
|
||||||
|
|
||||||
bool learnBackground;
|
|
||||||
int threshhold;
|
|
||||||
};
|
};
|
||||||
Reference in new issue
Block a user