I started developing my project by looking at the existing examples within openFrameworks and coping the project files as a base for my work (which is actually the recommended way of creating a new project... see here). I then added more and more code and addons to my project and ended up with my first prototype. See below.



My first prototype included 6 different video frames within one window to save space and effort. A lot of the code I had written was reused by each of the 6 individual frames and therefore it just made more sense to put them together into one code project. It was mainly a test of several different techniques and basic things like drawing a video on the screen, writing static text or outputting variables that can be adjusted by specific keys. I tested how the physics addon works, how to play with colours and mouse events. I also started to play with the idea of adding a contour to the physics world so they can interact with balls or other contours maybe. The input could be adjusted in the code so either a movie would play in a loop or the live camera feed would be shown.



Below the source files of prototype 01 are shown written in pseudo code for easier understanding.


main.cpp

include stuff

// Main
//--------------------------------------------------------------
open window of size 1050,800
run main c++ file (testApp.cpp)


testApp.h

include addons ofxOpenCv, ofxVectorMath, ofxBox2d and ofxContourAnalysis

// COLLISION
customBall class which sets size and colour of balls

name physics worlds
name the linestrip for the contours
name the contact handler for the physics worlds
name the vector for the customBalls
name the vector for the balls

name variables for simplification, threshold, font, image, mouse location, and various others

name colour images to store the video pixels in
name grayscale images to store the foreground and background pixels in

name contour finders to store the contours in

name video grabber for the webcam or video player for movie

name the vector to store the points of the drawing line in


testApp.cpp

// Setup
//--------------------------------------------------------------
set background colour

initialise video grabber
(or load movie)

allocate memory for the original video, the foreground video and background video

set gauss parameters
create gauss background

load font

// PIXELS
load image
save pixels of image into array

// DRAWING
set number of points of drawing to 0 to begin with

// BALLS
initialise physics world
enable Gravity
enable grabbing of mouse

create customBalls

// COLLISION
allocate memory for original video and contour frame
initialise physics world
enable gravity
set bounds to contour frame only

// Update
//--------------------------------------------------------------
store pixels of input video (camera or movie) into respective frames
update background and foreground models
find contours using the foreground model

// COLLISION
find contours for collision frame

for each blob:
simplify the contour
make each contour to a linestrip which enables them to interact with the physics world

// Draw
//--------------------------------------------------------------
draw original video at 20,40 (top left)
draw foreground at 360,40 (top middle)
draw background at 700,40 (top right)

// CONTOURS
draw background for contours
draw contours at 360,320 (bottom middle)

// TEXT
write strings

// PIXELS
draw image at 700,320 (bottom right)
draw circle in color of current pixel at mouse location

// COLLISION
draw original video for collision at 20,320 (bottom left)
draw contours for collision at 20,320 (bottom left)
draw the linestrips on top of the contour

// BALLS
draw customBalls

// DRAWING
draw line on mouseclick at mouse location

// KeyPressed
//--------------------------------------------------------------
increase or decrease simplification of contour by clicking left or right
draw big balls by clicking space
draw small balls by clicking b

// MouseDragged
//--------------------------------------------------------------
add current point of mouse to drawing array

// MousePressed
//--------------------------------------------------------------
clear drawing array on right click

// MouseReleased
//--------------------------------------------------------------
stop adding points to the drawing array

//--------------------------------------------------------------
add contact handlers for physics world

make balls change color on collision
make customBalls turn pink again after collision