int Ibex::VLCVideoPlayer::openCamera(bool isStereo, int cameraId) { first = true; done = false; if(!openCVInited) { initOpenCV(isStereo, cameraId); } bool first = true; while(captureVideo && cvCapture && !done) { IplImage* cameraCapture = cvQueryFrame(cvCapture); if( cameraCapture && (cameraCapture->width > 0) && (cameraCapture->height > 0)) { //width = cameraCapture->width; //height = cameraCapture->height; const int numBytes = (cameraCapture->widthStep/cameraCapture->width == 4 || cameraCapture->nChannels == 4) ? 4 : 3; const GLenum formatIn = (numBytes == 4) ? GL_BGRA : GL_BGR; if(isStereo) { glBindTexture(GL_TEXTURE_2D, videoTexture[1]); glPixelStorei(GL_UNPACK_ROW_LENGTH,width*2); glPixelStorei(GL_UNPACK_ALIGNMENT,1); if(first) { glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, width, height/2, 0, formatIn, GL_UNSIGNED_BYTE, cameraCapture->imageData); glBindTexture(GL_TEXTURE_2D, videoTexture[0]); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, width, height/2, 0, formatIn, GL_UNSIGNED_BYTE, cameraCapture->imageData+(width*numBytes)); } else { glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height/2, formatIn, GL_UNSIGNED_BYTE, cameraCapture->imageData); glBindTexture(GL_TEXTURE_2D, videoTexture[0]); glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height/2, formatIn, GL_UNSIGNED_BYTE, cameraCapture->imageData+(width*numBytes)); } } else { glBindTexture(GL_TEXTURE_2D, videoTexture[0]); glPixelStorei(GL_UNPACK_ROW_LENGTH,width); glPixelStorei(GL_UNPACK_ALIGNMENT,1); if(first) { glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, width, height, 0, formatIn, GL_UNSIGNED_BYTE, cameraCapture->imageData); } else { glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, formatIn, GL_UNSIGNED_BYTE, cameraCapture->imageData); } } glFlush(); } std::this_thread::sleep_for(std::chrono::milliseconds(30)); } stopCapturing(); return 0; }
int main(int argc, char* argv[]) { if (!init(argc, argv)) return 1; if (!initVuzix()) { cleanup(); return 1; } if (!initGL()) { cleanup(); return 1; } if (!initOpenCV()) { cleanup(); return 1; } glutMainLoop(); return 0; }