void CaptureDialog::_on_new_camera_image(cv::Mat image) { // only show webcam resolution, not DSLR if ( mCamera == NULL ) { camera_resolution_label->setText(QString("[%1x%2]").arg(image.cols).arg(image.rows)); } if (_capture) { // take picture using DSLR if there is one if (mCamera) { if ( mCamera->isLiveViewing() ) mCamera->endLiveView(); takePicture(); } // take picture using webcam if there is no DSLR else { camera_image->setImage(image); cv::imwrite(QString("%1/cam_%2.png").arg(_session).arg(_projector.get_current_pattern() + 1, 2, 10, QLatin1Char('0')).toStdString(), image); } _capture = false; _projector.clear_updated(); } else { if ( mCamera ) { if( mCamera->isLiveViewing() == false ) mCamera->startLiveView(); QImage img; mCamera->requestDownloadEvfData( img ); cv::Mat mat = cv::Mat(img.height(), img.width(), CV_8UC3, img.bits(), img.bytesPerLine()); camera_image->setImage(mat); } else { camera_image->setImage(image); } } }
void CaptureDialog::browserDidRemoveCamera(CameraRef camera) { // NB - somewhat redundant as the camera will notify handler first std::cout << "removed a camera: " << camera->getName() << std::endl; if (camera != mCamera) { return; } std::cout << "our camera was disconnected" << std::endl; mCamera = NULL; }
void CaptureDialog::browserDidAddCamera(CameraRef camera) { std::cout << "added a camera: " << camera->getName() << std::endl; if (mCamera != NULL) { return; } mCamera = camera; mCamera->connectRemovedHandler(&CaptureDialog::didRemoveCamera, this); mCamera->connectFileAddedHandler(&CaptureDialog::didAddFile, this); std::cout << "grabbing camera: " << camera->getName() << std::endl; EDSDK::Camera::Settings settings = EDSDK::Camera::Settings(); // settings.setPictureSaveLocation(kEdsSaveTo_Both); // settings.setShouldKeepAlive(false); EdsError error = mCamera->requestOpenSession(settings); if (error == EDS_ERR_OK) { std::cout << "session opened" << std::endl; } }
void Scene::raytrace(CameraRef camera, Rect rect, RenderOption option, ImageRef image) { ASSERT(image->width() == rect.size.width && image->height() == rect.size.height); for (unsigned int y = 0; y < rect.size.height; y++) { for (unsigned int x = 0; x < rect.size.width; x++) { float xPos = (float)(x + rect.origin.x) / (float) camera->width() - 0.5f; float yPos = (float)(y + rect.origin.y) / (float) camera->height() - 0.5f; Ray viewRay = camera->viewRay(xPos, yPos); HitInfo hitInfo; Color color; if (traceRay(viewRay, option, 1.0f, 0, &color, &hitInfo)) { image->setPixelColor(x, y, color); } else { // set Background ccolor //image->setPixelColor(x, y, hitInfo.material->color()); } } } }
ImageRef Scene::parallelRaytrace(CameraRef camera, RenderOption option) { Rect leftRect(0.0f, 0.0f, camera->width(), floor(camera->height() / 2.0f)); Rect rightRect(0.0f, leftRect.maxY(), camera->width(), camera->height() - leftRect.size.height); p1.scene = this; p1.camera = camera; p1.rect = leftRect; p1.option = option; p1.image = new Image(leftRect.size.width, leftRect.size.height); p2.scene = this; p2.camera = camera; p2.rect = rightRect; p2.option = option; p2.image = new Image(rightRect.size.width, rightRect.size.height); pthread_t thread1, thread2; int iret1, iret2; std::cout << this; iret1 = pthread_create(&thread1, NULL, raytraceThread, &p1); iret2 = pthread_create(&thread2, NULL, raytraceThread, &p2); pthread_join(thread1, NULL); pthread_join(thread2, NULL); ImageRef image = new Image(camera->width(), camera->height()); image->drawImageAtPoint(p1.image, p1.rect.origin); image->drawImageAtPoint(p2.image, p2.rect.origin); delete p1.image; delete p2.image; return image; }
void CaptureDialog::didAddFile(CameraRef camera, CameraFileRef file) { QDir destinationFolderPath(_session); camera->requestDownloadFile(file, destinationFolderPath, [&](EdsError error, QString outputFilePath) { if (error == EDS_ERR_OK) { std::cout << "image downloaded to '" << outputFilePath.toStdString() << "'" << std::endl; } }); // camera->requestReadFile(file, [&](EdsError error, ci::Surface surface) { // if (error == EDS_ERR_OK) { // mPhotoTexture = gl::Texture(surface); // } // }); }
void CaptureDialog::on_close_cancel_button_clicked(bool checked) { if (close_cancel_button->text()=="Close") { if ( mCamera && mCamera-> isLiveViewing() ) { mCamera->endLiveView(); } accept(); } else if (!_cancel) { _cancel = true; } }
ImageRef Scene::rasterize(CameraRef camera) { ImageRef image = new Image(camera->width(), camera->height()); for (unsigned int y = 0; y < camera->height(); y++) { for (unsigned int x = 0; x < camera->width(); x++) { float xPos = (float)x / (float) camera->width() - 0.5f; float yPos = (float)y / (float) camera->height() - 0.5f; Ray viewRay = camera->viewRay(xPos, yPos); HitInfo hitInfo; if (m_rootGroup->hit(viewRay, &hitInfo)) { image->setPixelColor(x, y, hitInfo.material->color()); } } } return image; }
int CaptureDialog::update_camera_combo(void) { //disable signals camera_combo->blockSignals(true); //save current value QString current = camera_combo->currentText(); std::cout << current.toStdString() << std::endl; //update combo camera_combo->clear(); if (mCamera) { camera_combo->addItem(QString::fromStdString(mCamera->getName())); } camera_combo->addItems(_video_input.list_devices()); camera_combo->setCurrentIndex(0); //enable signals camera_combo->blockSignals(false); return camera_combo->count(); }
void Scene::renderGL(CameraRef camera) { glDrawBuffer(GL_BACK); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // set up the screen with our camera parameters glMatrixMode( GL_PROJECTION ); glLoadIdentity(); gluPerspective(RAD2DEG(camera->FOV()), camera->aspect(), 0.1, 1000.0); glMatrixMode( GL_MODELVIEW ); glLoadIdentity(); gluLookAt(camera->eye().x, camera->eye().y, camera->eye().z, camera->lookat().x, camera->lookat().y, camera->lookat().z, camera->up().x, camera->up().y, camera->up().z); glEnable( GL_DEPTH_TEST ); glCullFace(GL_CULL_FACE); glCullFace(GL_FRONT); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); for (unsigned int i = 0; i < m_lights.size(); i++) { LightRef light = m_lights[i]; light->drawGL(); } m_rootGroup->drawGL(); glDisable(GL_DEPTH_TEST); glutSwapBuffers(); }
void CaptureDialog::takePicture() { if (mCamera != NULL && mCamera->hasOpenSession()) { mCamera->requestTakePicture(); } }
int init() { // --- ezeket kell osszeszedni egy initwindowban const int screenWidth = m_window.getRealWidth(), screenHeight = m_window.getRealHeight(); const int VSYNC_ENABLED = 1, FULL_SCREEN = 0; this->render.Initialize(screenWidth, screenHeight, VSYNC_ENABLED, this->m_window.getHWnd(), FULL_SCREEN); // init file loader this->m_file_loader = new FileAssetFactory("./../../assets/rotating_cube/"); // -------------------------------------------------- // -- camera m_camera = new Camera; m_camera->SetPosition(0.0f, 0.0f, -10.0f); // -- texture TextureFromBitmap *textureLoader = new TextureFromBitmap("normap.jpg"); TextureResRef textureRes = (TextureRes*)textureLoader->NewResource(); textureLoader->Load(this, textureRes); this->m_texture = textureRes->Get(); delete textureLoader; // -- texture sampler m_textureSampler = new TextureSampler(); m_textureSampler->Initialize(render); // -- load shader ShaderLoader *vShaderLoader = new ShaderLoader("vshader", "texture.hlsl", "TextureVertexShader", ST_Vertex); ShaderResRef vShaderRef = (ShaderRes*)(vShaderLoader->NewResource()); vShaderLoader->Load(this, vShaderRef); m_vertexShader = vShaderRef->Get(); delete vShaderLoader; ShaderLoader *pShaderLoader = new ShaderLoader("pshader", "texture.hlsl", "TexturePixelShader", ST_Pixel); ShaderResRef pShaderRef = (ShaderRes*)(pShaderLoader->NewResource()); pShaderLoader->Load(this, pShaderRef); m_fragmentShader = pShaderRef->Get(); delete pShaderLoader; // -- model this->m_model = new Model; // -- generator SimpleMeshGenerator generator(render, m_vertexShader); generator["POSITION"] = (void*)GrafkitData::cubeVertices; generator["TEXCOORD"] = (void*)GrafkitData::cubeTextureUVs; generator(GrafkitData::cubeVertexLength, GrafkitData::cubeIndicesLength, GrafkitData::cubeIndices, this->m_model); // --- this->t = 0; return 0; };
int init() { // --- ezeket kell osszeszedni egy initwindowban const int screenWidth = m_window.getRealWidth(), screenHeight = m_window.getRealHeight(); const int VSYNC_ENABLED = 1, FULL_SCREEN = 0; this->render.Initialize(screenWidth, screenHeight, VSYNC_ENABLED, this->m_window.getHWnd(), FULL_SCREEN); // init file loader this->m_file_loader = new FileAssetFactory("./../../assets/postfx/"); // -------------------------------------------------- // -- camera CameraRef camera = new Camera; camera->SetPosition(0.0f, 0.0f, -10.0f); // -- texture TextureResRef texture = new TextureRes(); texture = this->Load<TextureRes>(new TextureFromBitmap("Normap.jpg")); // -- texture sampler m_textureSampler = new TextureSampler(); m_textureSampler->Initialize(render); // -- load shader m_vertexShader = Load<ShaderRes>(new ShaderLoader("vShader", "texture.hlsl", "TextureVertexShader", ST_Vertex)); m_fragmentShader = Load<ShaderRes>(new ShaderLoader("pShader", "texture.hlsl", "TexturePixelShader", ST_Pixel)); m_fxFXAA = Load<ShaderRes>(new ShaderLoader("xFXAA", "fxaa.hlsl", "FXAA", ST_Pixel)); m_fxFishEye = Load<ShaderRes>(new ShaderLoader("xFishEye", "fisheye.hlsl", "fisheyeProc", ST_Pixel)); // m_fxVhs = Load<ShaderRes>(new ShaderLoader("xVhs", "vhstape.hlsl", "TextureVertexShader", ST_Pixel)); // this->DoPrecalc(); // -- model ModelRef model = new Model; model->SetMaterial(new MaterialBase); model->GetMaterial()->AddTexture(texture, "diffuse"); SimpleMeshGenerator generator(render, m_vertexShader); generator["POSITION"] = (void*)GrafkitData::cubeVertices; generator["TEXCOORD"] = (void*)GrafkitData::cubeTextureUVs; generator(GrafkitData::cubeVertexLength, GrafkitData::cubeIndicesLength, GrafkitData::cubeIndices, model); // -- setup scene scene = new Scene(); ActorRef cameraActor = new Actor(); cameraActor->AddEntity(camera); ActorRef modelActor = new Actor(); modelActor->AddEntity(model); ActorRef modelActorL = new Actor(); modelActorL->AddEntity(model); modelActorL->Matrix().Translate(3, 0, 0); modelActor->AddChild(modelActorL); ActorRef modelActorR = new Actor(); modelActorR->AddEntity(model); modelActorR->Matrix().Translate(-3, 0, 0); modelActor->AddChild(modelActorR); ActorRef modelActorU = new Actor(); modelActorU->AddEntity(model); modelActorU->Matrix().Translate(0, 3, 0); modelActor->AddChild(modelActorU); ActorRef modelActorD = new Actor(); modelActorD->AddEntity(model); modelActorD->Matrix().Translate(0, -3, 0); modelActor->AddChild(modelActorD); ActorRef modelActorF = new Actor(); modelActorF->AddEntity(model); modelActorF->Matrix().Translate(0, 0, 3); modelActor->AddChild(modelActorF); ActorRef modelActorB = new Actor(); modelActorB->AddEntity(model); modelActorB->Matrix().Translate(0, 0, -3); modelActor->AddChild(modelActorB); // ActorRef lightActor = new Actor(); lightActor->AddEntity(light); ActorRef rootActor = new Actor(); rootActor->AddChild(cameraActor); rootActor->AddChild(modelActor); m_rootActor = rootActor; scene->SetRootNode(rootActor); scene->SetCameraNode(cameraActor); // scene->AddLightNode(lightActor); scene->SetVShader(m_vertexShader); scene->SetFShader(m_fragmentShader); // -- setup postfx size_t k = 0; m_postfx = new EffectComposer(); m_postfx->Initialize(render); k = m_postfx->AddPass(new EffectPass()); m_postfx->GetEffect(k)->Initialize(render, m_fxFXAA); k = m_postfx->AddPass(new EffectPass()); m_postfx->GetEffect(k)->Initialize(render, m_fxFishEye); // k = m_postfx->AddPass(new EffectPass()); m_postfx->GetEffect(k)->Initialize(render, m_fxVhs); // k = m_postfx->AddPass(new EffectPass()); m_postfx->GetEffect(k)->Initialize(render, sahder); // k = m_postfx->AddPass(new EffectPass()); m_postfx->GetEffect(k)->Initialize(render, sahder); // k = m_postfx->AddPass(new EffectPass()); m_postfx->GetEffect(k)->Initialize(render, sahder); // --- return 0; };