openFrameworksにて特定フォルダ内の画像全ての、各ピクセルのRGB値を取得し、平均の値を取るようなプログラムを作ろうとしました。
以下のようにofAPP.h
, ofAPP.cpp
, main.cpp
を作成し、実行しようとしたところ、ofAPP.cppの14行目image.load(p.filename());
にて、「外側の関数のローカル変数は、キャプチャ リストに含まれていない限り、lambda 本体で参照できません」とエラーが出てしまいました。
ラムダ式の定義の問題だと思うのですが、C++、openFrameworksどちらにも触れ始めたばかりで上手に理解できませんでした。
こちら、どのように修正すればよいかご教授いただけないでしょうか。
当方の環境、Windows10で、Visual Studio 2015を用いてopenFrameworksを動かしております。
main.cpp
C++
1#include "ofMain.h" 2#include "ofApp.h" 3 4//======================================================================== 5int main( ){ 6 7 ofSetupOpenGL(1024,768, OF_WINDOW); // <-------- setup the GL context 8 9 // this kicks off the running of my app 10 // can be OF_WINDOW or OF_FULLSCREEN 11 // pass in width and height too: 12 ofRunApp( new ofApp()); 13 14} 15
ofAPP.h
C++
1#pragma once 2 3#include "ofMain.h" 4 5class ofApp : public ofBaseApp{ 6 private: 7 ofImage image; 8 public: 9 void setup(); 10 void update(); 11 void draw(); 12 13 void keyPressed(int key); 14 void keyReleased(int key); 15 void mouseMoved(int x, int y); 16 void mouseDragged(int x, int y, int button); 17 void mousePressed(int x, int y, int button); 18 void mouseReleased(int x, int y, int button); 19 void mouseEntered(int x, int y); 20 void mouseExited(int x, int y); 21 void windowResized(int w, int h); 22 void dragEvent(ofDragInfo dragInfo); 23 void gotMessage(ofMessage msg); 24}; 25
ofAPP.cpp
C++
1void ofApp::setup(){ 2 namespace sys = std::tr2::sys; 3 sys::path p("./data"); // 列挙の起点 4 std::for_each(sys::directory_iterator(p), sys::directory_iterator(), 5 [](const sys::path& p) { 6 if (sys::is_regular_file(p)) { // ファイルなら... 7 cout << "file: " << p.filename() << endl; 8 // 640x640, 30 frames/sec 9 ofSetWindowShape(640, 640); 10 ofSetFrameRate(30); 11 // set background 12 ofSetBackgroundColor(0, 80, 0); 13 // load image 14 image.load(p.filename()); 15 ofPixels pixels = image.getPixelsRef(); 16 int w = pixels.getWidth(); 17 int h = pixels.getHeight(); 18 for (int y = 0; y<h; y++) { 19 for (int x = 0; x<w; x++) { 20 ofColor color = pixels.getColor(x, y); 21 totalr = totalr + color.r; 22 totalg = totalg + color.g; 23 totalb = totalb + color.b; 24 } 25 } 26 totalr = totalr / 409600; 27 totalg = totalg / 409600; 28 totalb = totalb / 409600; 29 printf("r: %d \n", totalr); 30 printf("g: %d \n", totalg); 31 printf("b: %d \n", totalb); 32 } 33 else if (sys::is_directory(p)) { // ディレクトリなら... 34 cout << "dir.: " << p.string() << endl; 35 } 36 }); 37}
回答2件
あなたの回答
tips
プレビュー