33
32

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

[openFrameworks] ofVideograberをリサイズして高速にピクセルデータを取得する方法

Last updated at Posted at 2014-08-13

久しぶりのoFで、ビデオをリサイズしてピクセルデータを取得するのに、ofImageでリサイズしたらとても遅く、使い物になりませんでした。

Higa(http://qiita.com/satoruhiga) さんから教えてもらった方法を忘れないようにメモします。

ざっくりとコードは以下の様な感じです。

###ダメな例(ぼくがやっていた。)

ofApp.cpp
ofVideoGrabber video;
ofImage img;
    
void setup()
{
    ofSetFrameRate(60);
    ofSetVerticalSync(true);
    ofBackground(0);
        
    video.initGrabber(640, 480);
}
    
void update()
 {
    video.update();
        
    if (video.isFrameNew())
    {
     img.setFromPixels(video.getPixels(), video.getWidth(), video.getHeight(), OF_IMAGE_COLOR);
     img.resize(320, 240);
            
     unsinged char * pix;
     pix = img.getPixels();
            
    // do something
  }
}

###高速な例(Higaさんに教えてもらった。)

ofApp.cpp
ofVideoGrabber video;
ofFbo fbo;
    
void setup()
{
    ofSetFrameRate(60);
    ofSetVerticalSync(true);
    ofBackground(0);
        
    video.initGrabber(640, 480);
    fbo.allocate(320, 240, GL_RGB);
}
    
void update()
 {
    video.update();
        
    if (video.isFrameNew())
    {
     fbo.begin();
     video.draw(0, 0, fbo.getWidth(), fbo.getHeight());
     fbo.end();
            
     ofPixels pix;
     fbo.readToPixels(pix);
            
    // do something
  }
}

おかげでfpsが20から60に変化しましたー
Higaさんにマジ感謝ですー

33
32
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
33
32

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?