» codelab : http://codelab.fr/accueil » Forum : openFrameworks : http://codelab.fr/openframeworks » Ofcamera / ofEasyCam... ROTATION? : http://codelab.fr/4274 Ceci est la version imprimable d'un sujet du forum, pour retourner à la version complète : Ofcamera / ofEasyCam... ROTATION? |
Malleat — 2013-05-22 14:47:45 |
Bonjour |
Mushussu — 2013-05-22 17:11:31 |
Bonjour, #include "testApp.h" //-------------------------------------------------------------- void testApp::setup(){ camWidth = 320; // try to grab at this size. camHeight = 240; vidGrabber.setVerbose(true); vidGrabber.setDeviceID(1); vidGrabber.setDesiredFrameRate(60); vidGrabber.initGrabber(camWidth,camHeight); video90 = new unsigned char[camWidth*camHeight*3]; videoTexture.allocate(camHeight, camWidth, GL_RGB); ofSetVerticalSync(true); } //-------------------------------------------------------------- void testApp::update(){ ofBackground(100,100,100); vidGrabber.update(); if (vidGrabber.isFrameNew()){ unsigned char * pixels = vidGrabber.getPixels(); for (int i = 0; i < 3 * camWidth; i += 3){ for (int j = 0; j < camHeight; j++) { video90[(camWidth - (i / 3) - 1) * 3 * camHeight + 3 * j] = pixels[j * 3 * camWidth + i]; video90[(camWidth - (i / 3) - 1) * 3 * camHeight + 3 * j + 1] = pixels[j * 3 * camWidth + i + 1]; video90[(camWidth - (i / 3) - 1) * 3 * camHeight + 3 * j + 2] = pixels[j * 3 * camWidth + i + 2]; } } videoTexture.loadData(video90, camHeight, camWidth, GL_RGB); } } //-------------------------------------------------------------- void testApp::draw(){ ofSetHexColor(0xffffff); vidGrabber.draw(20,20); videoTexture.draw(20+camWidth,20, camHeight, camWidth); } et dans testApp.h : unsigned char * video90; Cela devrait fonctionner. |
Mushussu — 2013-05-22 18:18:31 |
Allez ! #include "testApp.h" //-------------------------------------------------------------- void testApp::setup(){ camWidth = 320; // try to grab at this size. camHeight = 240; vidGrabber.setVerbose(true); vidGrabber.setDeviceID(1); vidGrabber.setDesiredFrameRate(60); vidGrabber.initGrabber(camWidth,camHeight); videoRot90 = new unsigned char[camWidth*camHeight*3]; videoRot180 = new unsigned char[camWidth*camHeight*3]; videoRot270 = new unsigned char[camWidth*camHeight*3]; videoTexture90.allocate(camHeight, camWidth, GL_RGB); videoTexture180.allocate(camWidth, camHeight, GL_RGB); videoTexture270.allocate(camHeight, camWidth, GL_RGB); ofSetVerticalSync(true); } //-------------------------------------------------------------- void testApp::update(){ ofBackground(100,100,100); vidGrabber.update(); if (vidGrabber.isFrameNew()){ unsigned char * pixels = vidGrabber.getPixels(); for (int i = 0; i < 3 * camWidth; i += 3){ for (int j = 0; j < camHeight; j++) { // Rotation 90 videoRot90[(camWidth - (i / 3) - 1) * 3 * camHeight + 3 * j] = pixels[j * 3 * camWidth + i]; videoRot90[(camWidth - (i / 3) - 1) * 3 * camHeight + 3 * j + 1] = pixels[j * 3 * camWidth + i + 1]; videoRot90[(camWidth - (i / 3) - 1) * 3 * camHeight + 3 * j + 2] = pixels[j * 3 * camWidth + i + 2]; // Rotation 180 videoRot180[(camHeight - j) * 3 * camWidth + 3 * (camWidth - 1) - i] = pixels[j * 3 * camWidth + i]; videoRot180[(camHeight - j) * 3 * camWidth + 3 * (camWidth - 1) - i + 1] = pixels[j * 3 * camWidth + i + 1]; videoRot180[(camHeight - j) * 3 * camWidth + 3 * (camWidth - 1) - i + 2] = pixels[j * 3 * camWidth + i + 2]; // Rotation 270 videoRot270[((i / 3)) * 3 * camHeight + 3 * (camHeight - j)] = pixels[j * 3 * camWidth + i]; videoRot270[((i / 3)) * 3 * camHeight + 3 * (camHeight - j) + 1] = pixels[j * 3 * camWidth + i + 1]; videoRot270[((i / 3)) * 3 * camHeight + 3 * (camHeight - j) + 2] = pixels[j * 3 * camWidth + i + 2]; } } videoTexture90.loadData(videoRot90, camHeight, camWidth, GL_RGB); videoTexture180.loadData(videoRot180, camWidth, camHeight, GL_RGB); videoTexture270.loadData(videoRot270, camHeight, camWidth, GL_RGB); } } //-------------------------------------------------------------- void testApp::draw(){ ofSetHexColor(0xffffff); vidGrabber.draw(20,20); videoTexture90.draw(40+camWidth,20, camHeight, camWidth); videoTexture180.draw(20,40 + camWidth, camWidth, camHeight); videoTexture270.draw(40+ camWidth,40 + camWidth, camHeight, camWidth); } ofVideoGrabber vidGrabber; unsigned char * videoRot90; unsigned char * videoRot180; unsigned char * videoRot270; ofTexture videoTexture90; ofTexture videoTexture180; ofTexture videoTexture270; int camWidth; int camHeight; |