Compare commits

...

6 Commits

Author SHA1 Message Date
4b0d468c4f Change background subtraction algorithm 2021-05-17 14:10:09 +02:00
cdd4148156 Delete unnecessary files 2021-05-10 14:59:23 +02:00
5fa3b09bd7 Add .gitignore 2021-05-10 14:50:19 +02:00
b10e99aeac Add threshhold ofParameter 2021-05-10 14:26:13 +02:00
e7c68434cf Add ofxGui dependency 2021-05-10 14:25:02 +02:00
3ffa0ac381 Implemented Contour Finding
Before contours can be found, video is converted to grayscale,
background subtraction is performed and results get binarized.

Circles are characterized by the aspect ratio of the individual blob.
2021-05-06 09:48:06 +02:00
45 changed files with 2279 additions and 1624 deletions

436
.gitignore vendored Normal file
View File

@ -0,0 +1,436 @@
# Created by https://www.toptal.com/developers/gitignore/api/openframeworks,visualstudio
# Edit at https://www.toptal.com/developers/gitignore?templates=openframeworks,visualstudio
### OpenFrameworks ###
# ignore generated binaries
# but not the data folder
/bin/*
!/bin/data/
# general
[Bb]uild/
[Oo]bj/
*.o
[Dd]ebug*/
[Rr]elease*/
*.mode*
*.app/
*.pyc
.svn/
*.log
# IDE files which should
# be ignored
# XCode
*.pbxuser
*.perspective
*.perspectivev3
*.mode1v3
*.mode2v3
# XCode 4
xcuserdata
*.xcworkspace
# Code::Blocks
*.depend
*.layout
# Visual Studio
*.sdf
*.opensdf
*.suo
*.pdb
*.ilk
*.aps
ipch/
# Eclipse
.metadata
local.properties
.externalToolBuilders
# operating system
# Linux
*~
# KDE
.directory
.AppleDouble
# OSX
.DS_Store
*.swp
*~.nib
# Thumbnails
._*
# Windows
# Image file caches
Thumbs.db
# Folder config file
Desktop.ini
# Android
.csettings
### VisualStudio ###
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
##
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
# User-specific files
*.rsuser
*.user
*.userosscache
*.sln.docstates
# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs
# Mono auto generated files
mono_crash.*
# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
[Ww][Ii][Nn]32/
[Aa][Rr][Mm]/
[Aa][Rr][Mm]64/
bld/
[Bb]in/
[Ll]og/
[Ll]ogs/
# Visual Studio 2015/2017 cache/options directory
.vs/
# Uncomment if you have tasks that create the project's static files in wwwroot
#wwwroot/
# Visual Studio 2017 auto generated files
Generated\ Files/
# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*
# NUnit
*.VisualState.xml
TestResult.xml
nunit-*.xml
# Build Results of an ATL Project
[Dd]ebugPS/
[Rr]eleasePS/
dlldata.c
# Benchmark Results
BenchmarkDotNet.Artifacts/
# .NET Core
project.lock.json
project.fragment.lock.json
artifacts/
# ASP.NET Scaffolding
ScaffoldingReadMe.txt
# StyleCop
StyleCopReport.xml
# Files built by Visual Studio
*_i.c
*_p.c
*_h.h
*.meta
*.obj
*.iobj
*.pch
*.ipdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*_wpftmp.csproj
*.vspscc
*.vssscc
.builds
*.pidb
*.svclog
*.scc
# Chutzpah Test files
_Chutzpah*
# Visual C++ cache files
*.ncb
*.opendb
*.cachefile
*.VC.db
*.VC.VC.opendb
# Visual Studio profiler
*.psess
*.vsp
*.vspx
*.sap
# Visual Studio Trace Files
*.e2e
# TFS 2012 Local Workspace
$tf/
# Guidance Automation Toolkit
*.gpState
# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
*.DotSettings.user
# TeamCity is a build add-in
_TeamCity*
# DotCover is a Code Coverage Tool
*.dotCover
# AxoCover is a Code Coverage Tool
.axoCover/*
!.axoCover/settings.json
# Coverlet is a free, cross platform Code Coverage Tool
coverage*.[ji][sn][of][no]
coverage*.xml
# Visual Studio code coverage results
*.coverage
*.coveragexml
# NCrunch
_NCrunch_*
.*crunch*.local.xml
nCrunchTemp_*
# MightyMoose
*.mm.*
AutoTest.Net/
# Web workbench (sass)
.sass-cache/
# Installshield output folder
[Ee]xpress/
# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html
# Click-Once directory
publish/
# Publish Web Output
*.[Pp]ublish.xml
*.azurePubxml
# Note: Comment the next line if you want to checkin your web deploy settings,
# but database connection strings (with potential passwords) will be unencrypted
*.pubxml
*.publishproj
# Microsoft Azure Web App publish settings. Comment the next line if you want to
# checkin your Azure Web App publish settings, but sensitive information contained
# in these scripts will be unencrypted
PublishScripts/
# NuGet Packages
*.nupkg
# NuGet Symbol Packages
*.snupkg
# The packages folder can be ignored because of Package Restore
**/[Pp]ackages/*
# except build/, which is used as an MSBuild target.
!**/[Pp]ackages/build/
# Uncomment if necessary however generally it will be regenerated when needed
#!**/[Pp]ackages/repositories.config
# NuGet v3's project.json files produces more ignorable files
*.nuget.props
*.nuget.targets
# Microsoft Azure Build Output
csx/
*.build.csdef
# Microsoft Azure Emulator
ecf/
rcf/
# Windows Store app package directories and files
AppPackages/
BundleArtifacts/
Package.StoreAssociation.xml
_pkginfo.txt
*.appx
*.appxbundle
*.appxupload
# Visual Studio cache files
# files ending in .cache can be ignored
*.[Cc]ache
# but keep track of directories ending in .cache
!?*.[Cc]ache/
# Others
ClientBin/
~$*
*.dbmdl
*.dbproj.schemaview
*.jfm
*.pfx
*.publishsettings
orleans.codegen.cs
# Including strong name files can present a security risk
# (https://github.com/github/gitignore/pull/2483#issue-259490424)
#*.snk
# Since there are multiple workflows, uncomment next line to ignore bower_components
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
#bower_components/
# RIA/Silverlight projects
Generated_Code/
# Backup & report files from converting an old project file
# to a newer Visual Studio version. Backup files are not needed,
# because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm
ServiceFabricBackup/
*.rptproj.bak
# SQL Server files
*.mdf
*.ldf
*.ndf
# Business Intelligence projects
*.rdl.data
*.bim.layout
*.bim_*.settings
*.rptproj.rsuser
*- [Bb]ackup.rdl
*- [Bb]ackup ([0-9]).rdl
*- [Bb]ackup ([0-9][0-9]).rdl
# Microsoft Fakes
FakesAssemblies/
# GhostDoc plugin setting file
*.GhostDoc.xml
# Node.js Tools for Visual Studio
.ntvs_analysis.dat
node_modules/
# Visual Studio 6 build log
*.plg
# Visual Studio 6 workspace options file
*.opt
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
*.vbw
# Visual Studio LightSwitch build output
**/*.HTMLClient/GeneratedArtifacts
**/*.DesktopClient/GeneratedArtifacts
**/*.DesktopClient/ModelManifest.xml
**/*.Server/GeneratedArtifacts
**/*.Server/ModelManifest.xml
_Pvt_Extensions
# Paket dependency manager
.paket/paket.exe
paket-files/
# FAKE - F# Make
.fake/
# CodeRush personal settings
.cr/personal
# Python Tools for Visual Studio (PTVS)
__pycache__/
# Cake - Uncomment if you are using it
# tools/**
# !tools/packages.config
# Tabs Studio
*.tss
# Telerik's JustMock configuration file
*.jmconfig
# BizTalk build output
*.btp.cs
*.btm.cs
*.odx.cs
*.xsd.cs
# OpenCover UI analysis results
OpenCover/
# Azure Stream Analytics local run output
ASALocalRun/
# MSBuild Binary and Structured Log
*.binlog
# NVidia Nsight GPU debugger configuration file
*.nvuser
# MFractors (Xamarin productivity tool) working folder
.mfractor/
# Local History for Visual Studio
.localhistory/
# BeatPulse healthcheck temp database
healthchecksdb
# Backup folder for Package Reference Convert tool in Visual Studio 2017
MigrationBackup/
# Ionide (cross platform F# VS Code tools) working folder
.ionide/
# Fody - auto-generated XML schema
FodyWeavers.xsd
### VisualStudio Patch ###
# Additional files built by Visual Studio
*.tlog
# End of https://www.toptal.com/developers/gitignore/api/openframeworks,visualstudio

Binary file not shown.

View File

@ -1 +1,2 @@
ofxGui
ofxOpenCv

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,19 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LocalDebuggerWorkingDirectory>$(ProjectDir)/bin</LocalDebuggerWorkingDirectory>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LocalDebuggerWorkingDirectory>$(ProjectDir)/bin</LocalDebuggerWorkingDirectory>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LocalDebuggerWorkingDirectory>$(ProjectDir)/bin</LocalDebuggerWorkingDirectory>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LocalDebuggerWorkingDirectory>$(ProjectDir)/bin</LocalDebuggerWorkingDirectory>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup>
</Project>

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1,29 +0,0 @@
 main.cpp
ofApp.cpp
Info: Boost.Config is older than your compiler version - probably nothing bad will happen - but you may wish to look for an update Boost version. Define BOOST_CONFIG_SUPPRESS_OUTDATED_MESSAGE to suppress this message.
Info: Boost.Config is older than your compiler version - probably nothing bad will happen - but you may wish to look for an update Boost version. Define BOOST_CONFIG_SUPPRESS_OUTDATED_MESSAGE to suppress this message.
ofxCvColorImage.cpp
ofxCvContourFinder.cpp
ofxCvFloatImage.cpp
ofxCvGrayscaleImage.cpp
ofxCvHaarFinder.cpp
ofxCvImage.cpp
ofxCvShortImage.cpp
Info: Boost.Config is older than your compiler version - probably nothing bad will happen - but you may wish to look for an update Boost version. Define BOOST_CONFIG_SUPPRESS_OUTDATED_MESSAGE to suppress this message.
Info: Boost.Config is older than your compiler version - probably nothing bad will happen - but you may wish to look for an update Boost version. Define BOOST_CONFIG_SUPPRESS_OUTDATED_MESSAGE to suppress this message.
Info: Boost.Config is older than your compiler version - probably nothing bad will happen - but you may wish to look for an update Boost version. Define BOOST_CONFIG_SUPPRESS_OUTDATED_MESSAGE to suppress this message.
Info: Boost.Config is older than your compiler version - probably nothing bad will happen - but you may wish to look for an update Boost version. Define BOOST_CONFIG_SUPPRESS_OUTDATED_MESSAGE to suppress this message.
Info: Boost.Config is older than your compiler version - probably nothing bad will happen - but you may wish to look for an update Boost version. Define BOOST_CONFIG_SUPPRESS_OUTDATED_MESSAGE to suppress this message.
Info: Boost.Config is older than your compiler version - probably nothing bad will happen - but you may wish to look for an update Boost version. Define BOOST_CONFIG_SUPPRESS_OUTDATED_MESSAGE to suppress this message.
Info: Boost.Config is older than your compiler version - probably nothing bad will happen - but you may wish to look for an update Boost version. Define BOOST_CONFIG_SUPPRESS_OUTDATED_MESSAGE to suppress this message.
Creating library bin\beerpong_debug.lib and object bin\beerpong_debug.exp
beerpong.vcxproj -> C:\Users\mario\Documents\education\Studium\BEI6\interaktion\beerpong\beerpong\bin\beerpong_debug.exe
2 C:\Users\mario\Documents\education\Studium\BEI6\interaktion\of_v0.11.2_vs2017_release\libs\fmod\lib\vs\Win32\
Neue Datei 1544704 C:\Users\mario\Documents\education\Studium\BEI6\interaktion\of_v0.11.2_vs2017_release\libs\fmod\lib\vs\Win32\fmod.dll
Neue Datei 1733120 C:\Users\mario\Documents\education\Studium\BEI6\interaktion\of_v0.11.2_vs2017_release\libs\fmod\lib\vs\Win32\fmodL.dll
1 C:\Users\mario\Documents\education\Studium\BEI6\interaktion\of_v0.11.2_vs2017_release\libs\FreeImage\lib\vs\Win32\
*EXTRA Datei 1544704 C:\Users\mario\Documents\education\Studium\BEI6\interaktion\beerpong\beerpong\bin\fmod.dll
*EXTRA Datei 1733120 C:\Users\mario\Documents\education\Studium\BEI6\interaktion\beerpong\beerpong\bin\fmodL.dll
Neue Datei 6018560 C:\Users\mario\Documents\education\Studium\BEI6\interaktion\of_v0.11.2_vs2017_release\libs\FreeImage\lib\vs\Win32\FreeImage.dll

View File

@ -1,2 +0,0 @@
#TargetFrameworkVersion=v4.0:PlatformToolSet=v141:EnableManagedIncrementalBuild=false:VCToolArchitecture=Native32Bit:WindowsTargetPlatformVersion=10.0.18362.0
Debug|Win32|C:\Users\mario\Documents\education\Studium\BEI6\interaktion\beerpong\beerpong\|

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,30 @@
#include "bpRecognizer.h"
void bpRecognizer::update(ofxCvGrayscaleImage image, int video_width, int video_height) {
//subtracted.absDiff(image, background);
subtracted.allocate(video_width, video_height);
for (int i = 0; i < video_width * video_height; i++)
{
subtracted.getPixels()[i] = image.getPixels()[i] > background.getPixels()[i] + threshhold ? 255 : 0;
}
binarized = subtracted;
//binarized.threshold(threshhold);
contourFinder.findContours(
binarized,
10,
video_height * video_width / 10,
10,
true);
}
void bpRecognizer::setThreshhold(int threshhold) {
this->threshhold = threshhold;
}
void bpRecognizer::setBackground(ofxCvGrayscaleImage image) {
this->background = image;
}

View File

@ -0,0 +1,19 @@
#pragma once
#include "ofxOpenCv.h"
class bpRecognizer
{
public:
void update(ofxCvGrayscaleImage image, int video_width, int video_height);
void setThreshhold(int threshhold);
void setBackground(ofxCvGrayscaleImage image);
ofxCvGrayscaleImage currentImage;
ofxCvGrayscaleImage background;
ofxCvGrayscaleImage subtracted;
ofxCvGrayscaleImage binarized;
ofxCvContourFinder contourFinder;
int threshhold;
};

View File

@ -1,23 +1,106 @@
#include "ofApp.h"
#define VIDEO_WIDTH 360
#define VIDEO_HEIGHT 640
//--------------------------------------------------------------
void ofApp::setup(){
vidPlayer.load("video.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;
gui.setup("Parameter");
gui.add(threshhold.set("Threshhold", 80, 0, 255));
}
//--------------------------------------------------------------
void ofApp::update(){
vidPlayer.update();
colorVideo.setFromPixels(vidPlayer.getPixels());
grayVideo = colorVideo; // Convert Color to Grayscale
//cvInRange();
//colorVideo.convertToGrayscalePlanarImage(red, 0);
if (learnBackground){
recognizer.setBackground(grayVideo);
learnBackground = false;
}
recognizer.setThreshhold(threshhold);
recognizer.update(grayVideo, VIDEO_WIDTH, VIDEO_HEIGHT);
background = recognizer.background;
subtracted = recognizer.subtracted;
binarized = recognizer.binarized;
contourFinder = recognizer.contourFinder;
}
//--------------------------------------------------------------
void ofApp::draw(){
ofSetHexColor(0xffffff);
colorVideo.draw(20, 20);
grayVideo.draw(40 + VIDEO_WIDTH, 20);
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();
ofSetHexColor(0x333333);
ofDrawRectangle(80 + 3 * VIDEO_WIDTH, 20, 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(80 + 3 * VIDEO_WIDTH, 20);
ofDrawBitmapString(sizeStr.str(),
contourFinder.blobs[i].boundingRect.getCenter().x + 80 + 3 * VIDEO_WIDTH,
contourFinder.blobs[i].boundingRect.getCenter().y + 20);
}
}
gui.draw();
}
//--------------------------------------------------------------
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;
}
//--------------------------------------------------------------

View File

@ -1,6 +1,9 @@
#pragma once
#include "ofMain.h"
#include "ofxOpenCv.h"
#include "ofxGui.h"
#include "bpRecognizer.h"
class ofApp : public ofBaseApp{
@ -21,4 +24,26 @@ class ofApp : public ofBaseApp{
void dragEvent(ofDragInfo dragInfo);
void gotMessage(ofMessage msg);
ofVideoPlayer vidPlayer;
// Images displaying original video
ofxCvColorImage colorVideo;
ofxCvGrayscaleImage grayVideo;
bpRecognizer recognizer;
ofxCvGrayscaleImage background;
ofxCvGrayscaleImage subtracted;
ofxCvGrayscaleImage binarized;
ofxCvContourFinder contourFinder;
bool learnBackground;
ofxPanel gui;
ofParameter<int> threshhold;
ofxCvGrayscaleImage red;
ofxCvGrayscaleImage green;
ofxCvGrayscaleImage blue;
};