Bonjour
Juste une question simple: comment faire effectuer une rotation de 90° à une caméra, ou easycam?
Merci beaucoup ![]()
Hors ligne
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
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
Pages: 1