» codelab : http://codelab.fr/accueil » Forum : openFrameworks : http://codelab.fr/openframeworks » ofTexture to ofImage : http://codelab.fr/5197 Ceci est la version imprimable d'un sujet du forum, pour retourner à la version complète : ofTexture to ofImage |
caracteriel — 2014-07-25 14:50:29 |
Salut, |
Mushussu — 2014-07-25 17:51:28 |
Bonjour, //-------------------------------------------------------------- void testApp::setup(){ camWidth = 320; camHeight = 240; vidGrabber.setVerbose(true); vidGrabber.setDeviceID(0); 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]; verticalFlip = new unsigned char[camWidth*camHeight*3]; horizontalFlip = new unsigned char[camWidth*camHeight*3]; videoTexture90.allocate(camHeight, camWidth, GL_RGB); videoTexture180.allocate(camWidth, camHeight, GL_RGB); videoTexture270.allocate(camHeight, camWidth, GL_RGB); verticalFlipTexture.allocate(camWidth, camHeight, GL_RGB); horizontalFlipTexture.allocate(camWidth, camHeight, 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 - 1) * 3 * camWidth + 3 * (camWidth - 1) - i] = pixels[j * 3 * camWidth + i]; videoRot180[(camHeight - j - 1) * 3 * camWidth + 3 * (camWidth - 1) - i + 1] = pixels[j * 3 * camWidth + i + 1]; videoRot180[(camHeight - j - 1) * 3 * camWidth + 3 * (camWidth - 1) - i + 2] = pixels[j * 3 * camWidth + i + 2]; // Rotation 270 videoRot270[((i / 3)) * 3 * camHeight + 3 * (camHeight - j - 1)] = pixels[j * 3 * camWidth + i]; videoRot270[((i / 3)) * 3 * camHeight + 3 * (camHeight - j - 1) + 1] = pixels[j * 3 * camWidth + i + 1]; videoRot270[((i / 3)) * 3 * camHeight + 3 * (camHeight - j - 1) + 2] = pixels[j * 3 * camWidth + i + 2]; // Vertical Flip verticalFlip[(camHeight - j - 1) * 3 * camWidth + i] = pixels[j * 3 * camWidth + i]; verticalFlip[(camHeight - j - 1) * 3 * camWidth + i + 1] = pixels[j * 3 * camWidth + i + 1]; verticalFlip[(camHeight - j - 1) * 3 * camWidth + i + 2] = pixels[j * 3 * camWidth + i + 2]; // HorizontalFlip horizontalFlip[j * 3 * camWidth + 3 * (camWidth - 1) - i] = pixels[j * 3 * camWidth + i]; horizontalFlip[j * 3 * camWidth + 3 * (camWidth - 1) - i + 1] = pixels[j * 3 * camWidth + i + 1]; horizontalFlip[j * 3 * camWidth + 3 * (camWidth - 1) - i + 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); verticalFlipTexture.loadData(verticalFlip, camWidth, camHeight, GL_RGB); horizontalFlipTexture.loadData(horizontalFlip, camWidth, camHeight, 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); verticalFlipTexture.draw(60 + camWidth + camHeight, 20, camWidth, camHeight); horizontalFlipTexture.draw(60+ camWidth + camHeight, 40 + camWidth, camWidth, camHeight); } Avec dans le .h ofVideoGrabber vidGrabber; unsigned char * videoRot90; unsigned char * videoRot180; unsigned char * videoRot270; unsigned char * verticalFlip; unsigned char * horizontalFlip; ofTexture videoTexture90; ofTexture videoTexture180; ofTexture videoTexture270; ofTexture verticalFlipTexture; ofTexture horizontalFlipTexture; int camWidth; int camHeight; En espérant qu'il te soit utile. |
nononononono — 2014-07-25 22:06:02 |
yop, |