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.
- The first video (top left) was just the original movie or live camera feed as a reference.
- The second video (top middle) was the foreground of that original video.
- The third (top right) was the background, which adjusted over time.
- The fourth video (bottom left) was the original video with a contour on top of it that interacted with balls that could be created by pressing space or the b key on the keyboard.
- The fifth video (bottom middle) showed all of the blobs as a pink rectangle and the contour in light blue.
- The sixth video (bottom right) was just an image. When you moved your mouse over it, it showed the current pixel colour in a big circle.
- At the bottom you could see the current amount of simplification for the contours and there was some space to draw by clicking and dragging the mouse.
- There were also some pink balls floating around that you could grab with your mouse and they changed colour on collision with other balls.
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 ballsname 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 ballsname 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 inname 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 colourinitialise video grabber
(or load movie)allocate memory for the original video, the foreground video and background video
set gauss parameters
create gauss backgroundload 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 mousecreate 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 framefor 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 worldmake balls change color on collision
make customBalls turn pink again after collision