Created
July 12, 2014 10:05
-
-
Save nylki/a0dc415a074b6e65fb25 to your computer and use it in GitHub Desktop.
vector getting empty in draw method problem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "Artefact.h" | |
Artefact::Artefact(string cascadepath_, string name_, string description_, ofImage mockup_){ | |
cascadepath = cascadepath_; | |
name = name_; | |
description = description_; | |
mockup = mockup_; | |
} | |
Artefact::Artefact(){ | |
} | |
Artefact::Artefact(ofDirectory dir){ | |
// create an artefact object from a directory, including a config file | |
string configjson = ofFilePath::join(dir.path(), "config.json"); | |
ofxJSONElement result = ofxJSONElement(); | |
// Now parse the JSON | |
bool parsingSuccessful = result.open(configjson); | |
if (parsingSuccessful) { | |
cout << "parsing of " << configjson << "succesful" << endl; | |
cascadepath = ofFilePath::join(dir.path(), result["cascade"].asString()); | |
name = result["name"].asString(); | |
description = result["description"].asString(); | |
mockup.loadImage(result["mockup"].asString()); | |
} else { | |
cout << "could not open " << configjson << "\n using empty values. please check your artefacts folder for proper functionality!" << endl; | |
cascadepath = ""; | |
name = "without name"; | |
description = "without description"; | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Artefact.h | |
// PhysicalFinder | |
// | |
// Created by tom on 11.07.14. | |
// | |
// | |
#ifndef __PhysicalFinder__Artefact__ | |
#define __PhysicalFinder__Artefact__ | |
#include "ofMain.h" | |
#include "ofxCv.h" | |
#include "ofxJSONElement.h" | |
class Artefact{ | |
public: | |
Artefact(string cascadepath_, string name_, string description_, ofImage mockup_); | |
Artefact(ofDirectory dir); | |
Artefact(); | |
std::vector<ofRectangle> foundObjects; | |
string cascadepath; | |
string name; | |
string description; | |
ofImage mockup; | |
private: | |
}; | |
#endif /* defined(__PhysicalFinder__Artefact__) */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "ofApp.h" | |
using namespace ofxCv; | |
using namespace cv; | |
void ofApp::setup() { | |
ofSetVerticalSync(true); | |
ofSetFrameRate(120); | |
finder.setPreset(ObjectFinder::Fast); | |
finder.getTracker().setSmoothingRate(.3); | |
cam.initGrabber(1280, 960); | |
ofEnableAlphaBlending(); | |
/* stepping through config/artefact directoy | |
and creating objects for each artefact */ | |
string path = "artefacts/"; | |
ofDirectory dir(path); | |
dir.listDir(); | |
for(int i = 0; i < dir.numFiles(); i++){ | |
ofDirectory curDir(dir.getPath(i)); | |
if(curDir.isDirectory()){ | |
// curDir is a single artefact dir | |
// with the config.json, 3d file, cascade file inside. | |
Artefact curArtefact = Artefact(curDir); | |
artefacts.push_back(curArtefact); | |
} | |
} | |
} | |
void ofApp::update() { | |
cam.update(); | |
if(cam.isFrameNew()) { | |
for(Artefact a : artefacts){ | |
finder.setup(a.cascadepath); | |
finder.update(cam); | |
for(int i = 0; i < finder.size(); i++){ | |
ofRectangle r; | |
cout << "found objects: " << finder.size() << " in " << a.name << endl; | |
r = ofRectangle(finder.getObjectSmoothed(i)); | |
cout << " size of foundobjects before: " << a.foundObjects.size() << endl; | |
a.foundObjects.push_back(r); | |
cout << " size of foundobjects after: " << a.foundObjects.size() << endl; | |
} | |
} | |
} | |
} | |
void ofApp::draw() { | |
ofSetColor(255); | |
cam.draw(0, 0); | |
for(Artefact a : artefacts){ | |
for(int i = 0; i < a.foundObjects.size(); i++) { | |
// wird GARNICHT AUSGEFÜHRT!! | |
cout << "draw2" << endl; | |
cout << a.foundObjects.size() << endl; | |
ofRectangle object = a.foundObjects[i]; | |
ofNoFill(); | |
ofSetColor(0, 30, 200); | |
ofRect(object.getPosition(), object.width, object.height); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment