Position VisiblePosition::previousVisiblePosition(const Position &pos) { if (pos.isNull() || atStart(pos)) return Position(); Position test = deepEquivalent(pos); Position downstreamTest = test.downstream(StayInBlock); bool acceptAnyVisiblePosition = !isCandidate(test); Position current = test; while (!atStart(current)) { current = previousPosition(current); if (isCandidate(current) && (acceptAnyVisiblePosition || (downstreamTest != current.downstream(StayInBlock)))) { return current; } } return Position(); }
void ofApp::drawContFinder(){ ofSetBackgroundAuto(bShowLabels); ofxCv::RectTracker& tracker = contFinder.getTracker(); if(bShowLabels) { ofSetColor(255); if(bBackgroundLearned){ grayDiffOfImage.draw(0,0); } else { grayImage.draw(0, 0); } contFinder.draw(); for(int i = 0; i < contFinder.size(); i++) { ofPoint center = ofxCv::toOf(contFinder.getCenter(i)); ofPushMatrix(); ofTranslate(center.x, center.y); int label = contFinder.getLabel(i); string msg = ofToString(label) + ":" + ofToString(tracker.getAge(label)); ofDrawBitmapString(msg, 0, 0); ofVec2f velocity = ofxCv::toOf(contFinder.getVelocity(i)); ofScale(5, 5); ofLine(0, 0, velocity.x, velocity.y); ofPopMatrix(); } } else { for(int i = 0; i < contFinder.size(); i++) { unsigned int label = contFinder.getLabel(i); // only draw a line if this is not a new label if(tracker.existsPrevious(label)) { // use the label to pick a random color ofSeedRandom(label << 24); ofSetColor(ofColor::fromHsb(ofRandom(255), 255, 255)); // get the tracked object (cv::Rect) at current and previous position const cv::Rect& previous = tracker.getPrevious(label); const cv::Rect& current = tracker.getCurrent(label); // get the centers of the rectangles ofVec2f previousPosition(previous.x + previous.width / 2, previous.y + previous.height / 2); ofVec2f currentPosition(current.x + current.width / 2, current.y + current.height / 2); ofLine(previousPosition, currentPosition); } } } // this chunk of code visualizes the creation and destruction of labels const vector<unsigned int>& currentLabels = tracker.getCurrentLabels(); const vector<unsigned int>& previousLabels = tracker.getPreviousLabels(); const vector<unsigned int>& newLabels = tracker.getNewLabels(); const vector<unsigned int>& deadLabels = tracker.getDeadLabels(); ofSetColor(ofxCv::cyanPrint); for(int i = 0; i < currentLabels.size(); i++) { int j = currentLabels[i]; ofLine(j, 0, j, 4); } ofSetColor(ofxCv::magentaPrint); for(int i = 0; i < previousLabels.size(); i++) { int j = previousLabels[i]; ofLine(j, 4, j, 8); } ofSetColor(ofxCv::yellowPrint); for(int i = 0; i < newLabels.size(); i++) { int j = newLabels[i]; ofLine(j, 8, j, 12); } ofSetColor(ofColor::white); for(int i = 0; i < deadLabels.size(); i++) { int j = deadLabels[i]; ofLine(j, 12, j, 16); } }
void nebulaContourFinder::draw(int x, int y, int w, int h){ if(!enabled || blurred.size() == cv::Size(0,0)) return; ofxCv::RectTracker& tracker = finder.getTracker(); ofPushMatrix(); ofScale(w/blurred.cols, h/blurred.rows); ofTranslate(x,y); if(showLabels) { finder.draw(); for(int i = 0; i < finder.size(); i++) { ofPoint center = ofxCv::toOf(finder.getCenter(i)); ofPushMatrix(); ofTranslate(center.x, center.y); int label = finder.getLabel(i); string msg = ofToString(label) + ":" + ofToString(tracker.getAge(label)); ofDrawBitmapString(msg, 0, 0); ofDrawCircle(0,0,2); ofVec2f pt = ofxCv::toOf(finder.getCentroid(i)); pt.x /= blurred.cols; pt.y /= blurred.rows; msg = ofToString(pt); ofDrawBitmapString(msg, 0, 12); ofVec2f velocity = ofxCv::toOf(finder.getVelocity(i)); ofScale(5, 5); ofDrawLine(0, 0, velocity.x, velocity.y); ofPopMatrix(); } } else { for(int i = 0; i < finder.size(); i++) { unsigned int label = finder.getLabel(i); // only draw a line if this is not a new label if(tracker.existsPrevious(label)) { // use the label to pick a random color ofSeedRandom(label << 24); ofSetColor(ofColor::fromHsb(ofRandom(255), 255, 255)); // get the tracked object (cv::Rect) at current and previous position const cv::Rect& previous = tracker.getPrevious(label); const cv::Rect& current = tracker.getCurrent(label); // get the centers of the rectangles ofVec2f previousPosition(previous.x + previous.width / 2, previous.y + previous.height / 2); ofVec2f currentPosition(current.x + current.width / 2, current.y + current.height / 2); ofDrawLine(previousPosition, currentPosition); } } } ofTranslate(x,y); // this chunk of code visualizes the creation and destruction of labels const vector<unsigned int>& currentLabels = tracker.getCurrentLabels(); const vector<unsigned int>& previousLabels = tracker.getPreviousLabels(); const vector<unsigned int>& newLabels = tracker.getNewLabels(); const vector<unsigned int>& deadLabels = tracker.getDeadLabels(); ofSetColor(ofxCv::cyanPrint); for(int i = 0; i < currentLabels.size(); i++) { int j = currentLabels[i]; ofDrawLine(j, 0, j, 4); } ofSetColor(ofxCv::magentaPrint); for(int i = 0; i < previousLabels.size(); i++) { int j = previousLabels[i]; ofDrawLine(j, 4, j, 8); } ofSetColor(ofxCv::yellowPrint); for(int i = 0; i < newLabels.size(); i++) { int j = newLabels[i]; ofDrawLine(j, 8, j, 12); } ofSetColor(ofColor::white); for(int i = 0; i < deadLabels.size(); i++) { int j = deadLabels[i]; ofDrawLine(j, 12, j, 16); } ofPopMatrix(); ofPopStyle(); }