Annonce

>>> Bienvenue sur codelab! >>> Première visite ? >>> quelques mots sur codelab //// une carte des membres//// (apéros) codelab


#1 2013-05-22 14:47:45 Ofcamera / ofEasyCam... ROTATION?

Malleat
membre
Date d'inscription: 2012-04-15
Messages: 148
Site web

Ofcamera / ofEasyCam... ROTATION?



Bonjour


Juste une question simple: comment faire effectuer une rotation de 90° à une caméra, ou easycam?


Merci beaucoup wink


SITE WEB ->REVŒLUTION

Hors ligne

 

#2 2013-05-22 17:11:31 Re : Ofcamera / ofEasyCam... ROTATION?

Mushussu
membre
Lieu: Orléans
Date d'inscription: 2012-05-24
Messages: 802

Re: Ofcamera / ofEasyCam... ROTATION?



Bonjour,

Si tu prends l'exemple du VideoGrabber et que tu remplaces par cela dans testApp.cpp:

#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.

Hors ligne

 

#3 2013-05-22 18:18:31 Re : Ofcamera / ofEasyCam... ROTATION?

Mushussu
membre
Lieu: Orléans
Date d'inscription: 2012-05-24
Messages: 802

Re: Ofcamera / ofEasyCam... ROTATION?



Allez !

En bonus :

#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;

Hors ligne

 

fil rss de cette discussion : rss

Pied de page des forums

Powered by FluxBB

codelab, graphisme & code : emoc / 2008-2024