ofPath::getOutline() and ofPolyline::getBoundingBox() でofRectが返って来ない問題 #openFrameworks

capture

ofPath::getBoundingBox();

ofxSvgの各パスをgetBoundingBox()でゲットしようとしたのが、値が返って来ない問題がありました。この問題の解決策としては、アウトラインを取るのに線の太さが設定し、またofPathのWindingModeも適したものを選択しておく必要があります。

サンプルコード

[cpp]

ofPath path; //パスを追加してください。
path.setStrokeWidth(1.0); //太さがないとアウトラインは取れない
path.setPolyWindingMode(OF_POLY_WINDING_ODD); //適した
auto polyLine = path.getOutline()[0]; //とりあえず0番目のアウトライン
auto rect = polyLine.getBoudingBox();

[/cpp]

参考

Get ofPath bounding box

ofImage画像をofPath描画でマスクする #openFrameworks

ofImageへのマスク処理

alpha

0.9.0~ できるようになったというofImageへのマスク処理 setAlphaMask (参考:画像を形を指定してマスクする)を試してみました。

サンプルコード

[cpp]

ofPath path;
ofImage img;
ofFbo fbo;

void ofApp::setup(){

ofHideCursor();

//set path
for(auto i = 0 ; i < 100 ; i++){
ofSetColor(255);
const auto pos = ofPoint(ofRandom(float(ofGetWidth())),float(ofRandom(ofGetHeight())));
path.lineTo(pos);
}

//set fbo
fbo.allocate(ofGetWidth(),ofGetHeight(),GL_RGBA /*GL_LUMINANCE*/);
fbo.begin();
path.draw();
fbo.end();

//set img
//dataフォルダに好きな画像を入れてください。
if(!img.load("mirrorboy.jpg")){
ofLog() << "image is not loaded." ;
};

img.setAnchorPercent(0.5,0.5);
img.getTexture().setAlphaMask(fbo.getTexture());
}

void ofApp::draw(){

ofBackgroundGradient(ofColor::yellow,ofColor::gray);

ofSetColor(255);
img.draw(ofGetWidth()/2,ofGetHeight()/2);

}
[/cpp]

C++14 ラムダ関数で再帰呼び出しサンプル

引数なし

[cpp]

std::function<void()> func = [&](){

fun();

}

func();

[/cpp]

引数あり

[cpp]

std::function<void(class&)> func = [&func](auto& obj){

func(obj);

}

class obj;

func(obj);

[/cpp]

オブジェクトを参照渡ししつつ、再帰呼び出しするラムダ関数のサンプル。openFrameworks 0.9以上だとC++14対応なので動く。

IntensityShuttleViewer 0.2.2 公開しました #max7

IntensityShuttleViewerとは?

MacでBlackmagic Design社 IntensityShuttle for ThunderboltのPreviewを簡単にできるアプリです。今回、久しぶりにバージョンアップをしました。詳しくは、以前の記事をご覧ください。

変更点

スクリーンショット 2016-03-12 16.13.24

  • 内部処理を見直し軽量化
  • GUIの変更
  • Max6 → Max7で書き換え
  • OS 10.11.3 対応

ダウンロード

こちらからどうぞ

実行環境が無く最新版に対応できないため、非公開とさせていただきました。

ofxCvHaarFinderとofBeginShape()を一緒に使ったら顔認識されなくなった #openFrameworks

cvgraphics

ofxCvHaarFinder × ofBeginShape()

Raspberry PI の openFrameworks で ofxCvHaarFinderのfindHaarObjects()とofBeginShape() / ofEndShape()を使ったコードを書いていたら、何故か顔認識動かない。ofBeginShape() ~ ofEndShape()をコメントアウトすると認識される。

とりあえず解決案 – ofPushStyle() ~ ofPopStyle();

[code]

ofPushStyle(); //追加

ofBeginShape();

ofVertexes(); //描画

ofEndShape();

ofPopStyle(); //追加

[/code]

ofBeginShape() ~ ofEndShape()するときに内部で描画設定を変えられてるからかな〜と推測して、前後にofPopStyle()とofPushStyle()で囲んだら顔認識動いた。