@nami wrote:
// Sorry.I am Japanese programmer.So, my English is not good enough.
Hello!I'm trying to use XBOX One Kinect with ofxMultiKinectV2.I can get the IR picture sent from Kinect.But I set it to ofxOpenCV Images or ofxCv Images.
There is my code.This one is using ofxOpenCV.
ofApp.h
class ofApp : public ofBaseApp{ public: ・・・ ofxMultiKinectV2 kinect; ofTexture texture1; ofTexture texture2; ofxPanel gui; ofxTurboJpeg turbo; ofShader irShader; ofxCvGrayscaleImage irImage; ofFbo frameBuffer; ofPixels irPixels; int threshold; int width; int height; }; static string irFragmentShader = STRINGIFY( uniform sampler2DRect tex; void main() { vec4 col = texture2DRect(tex, gl_TexCoord[0].xy); float value = col.r / 65535.0; gl_FragColor = vec4(vec3(value), 1.0); } );
ofApp.cpp
void ofApp::setup(){ ofBackground(255, 255, 255); ofSetVerticalSync(true); ofSetFrameRate(60); kinect.open(true, true, 0, 2); kinect.start(); irShader.setupShaderFromSource(GL_FRAGMENT_SHADER, irFragmentShader); irShader.linkProgram(); width = 2585; height = 1081; irImage.allocate(width, height); frameBuffer.allocate(width, height); } //-------------------------------------------------------------- void ofApp::update(){ kinect.update(); if(kinect.isFrameNew()){ texture2.loadData(kinect.getIrPixelsRef()); if (texture2.isAllocated()) { frameBuffer.begin(); irShader.begin(); texture2.draw(0, 0, width, height); irShader.end(); frameBuffer.end(); frameBuffer.readToPixels(irPixels); unsigned char pixs2[width*height*3]; for(int i = 0; i < width*height; i++) { pixs2[i*3] = irPixels[i*4]; pixs2[i*3+1] = irPixels[i*4]; pixs2[i*3+2] = irPixels[i*4]; } ofPixels pixels; pixels.setFromPixels(pixs2, width, height, GL_RGB); irImage.setFromPixels(pixs2, width, height); } } } //-------------------------------------------------------------- void ofApp::draw(){ irImage.draw(0.0, 0.0, 960, 540); ofDrawBitmapStringHighlight(ofToString(ofGetFrameRate()), 10, 20); ofDrawBitmapStringHighlight("Device Count : " + ofToString(ofxMultiKinectV2::getDeviceCount()), 10, 40); }
Can anybody help me?
Posts: 2
Participants: 2