【发布时间】:2016-05-28 15:31:59
【问题描述】:
为什么当我从设置为OF_PIXELS_RGB 的ofxAndroidVideoGrabber 中绘制ofImage 时,它看起来像这样?
这是我的代码:
void ofApp::setup(){
ofBackground(0,0,0);
grabber.setPixelFormat(OF_PIXELS_RGB);
// Start the grabber
grabber.setup(640,480);
// Get the native android video grabber
ofxAndroidVideoGrabber* androidGrabber = (ofxAndroidVideoGrabber*)grabber.getGrabber().get();
// Ensure facing the correct direction
androidGrabber->setDeviceID(androidGrabber->getBackCamera());
}
void ofApp::update(){
grabber.update();
if(grabber.isFrameNew()){
// Add frame
ofPixels nextFrame = grabber.getPixels();
frameQueue.push(nextFrame);
}
}
void ofApp::draw(){
// Calculate aspect ratio of grabber image
float grabberAspectRatio = grabber.getWidth() / grabber.getHeight();
// Draw camera image centered in the window
ofPushMatrix();
ofSetHexColor(0xFFFFFF);
ofSetRectMode(OF_RECTMODE_CENTER);
ofTranslate(ofGetWidth() / 2, ofGetHeight() / 2);
// Initial check that the next frame should be rendered
if ( ! frameQueue.empty() ) {
ofPixels nextFrame = frameQueue.front();
grabberImage.setFromPixels(nextFrame);
grabberImage.mirror(false, true);
grabberImage.update();
// Advance
frameQueue.pop();
}
if ( grabberImage.isAllocated() ) {
if(ofGetWidth() > ofGetHeight()) {
grabberImage.draw(0, 0, ofGetHeight() * grabberAspectRatio, ofGetHeight());
} else {
grabberImage.draw(0, 0, ofGetWidth(), ofGetWidth() * 1.0/grabberAspectRatio);
}
}
ofPopMatrix();
ofSetRectMode(OF_RECTMODE_CORNER);
}
据我所知,视频以 NV21 形式出现,并由 openframeworks 转换为 RGB。我的最佳猜测是:
- 我做错了什么,跳过了转换
- oF 中存在错误。
我已经尝试了提供的相机示例,我得到了同样的效果。
【问题讨论】:
标签: android image-processing yuv openframeworks