diff --git a/app/SandboxSetup/camerafocus.cpp b/app/SandboxSetup/camerafocus.cpp index 2c09173dbd277f4918b8c9e048b3dcb73e0ec71e..7b9f6438d130d3913d8447cfbfbb32bac092479f 100644 --- a/app/SandboxSetup/camerafocus.cpp +++ b/app/SandboxSetup/camerafocus.cpp @@ -8,15 +8,12 @@ CameraFocus::CameraFocus(SandboxSetup *sandbox, QWidget *parent) : ui->setupUi(this); setup = sandbox; - if(setup->loadFrameProcessProfil()){ - std::cout << "No process profil found" << std::endl; - } + setup->loadFrameProcessProfil(); initCameraParams(); frameTimer = new QTimer(this); connect(frameTimer, &QTimer::timeout, this, &CameraFocus::refreshFrame); - setup->camera.start(); frameTimer->start(100); } @@ -29,35 +26,36 @@ void CameraFocus::on_btnbxValidate_clicked(QAbstractButton *button) { (void)button; frameTimer->stop(); - setup->camera.stop(); } void CameraFocus::on_btnbxValidate_accepted() { state = true; - if(setup->saveFrameProcessProfil()){ - std::cout << "Error : couldn't save profil" << std::endl; - std::exit(1); - } } void CameraFocus::refreshFrame(){ - setup->camera.captureFrame(); - FrameProcessProfil p = *(setup->beamer.getProfil()); + setup->getCamera()->captureFrame(); + FrameProcessProfil *profil = setup->getBeamer()->getProfil(); cv::Mat gray; cv::Mat rgbFromGray; - cv::Mat rgb = setup->camera.getRGBFrame(); + cv::Mat rgb = setup->getCamera()->getRGBFrame(); std::vector<int> crc; - if(p.getUpperMinThreshold() >= p.getLowerMinThreshold()){ - crc = setup->beamer.findCercleZ(rgb, p.getContrast(), p.getBrightness(), p.getRadiusRatio(), p.getUpperMinThreshold(), p.getLowerMinThreshold()); + if(profil->getUpperMinThreshold() >= profil->getLowerMinThreshold()){ + + crc = setup->getBeamer()->findCercleZ( rgb, + profil->getContrast(), + profil->getBrightness(), + profil->getRadiusRatio(), + profil->getUpperMinThreshold(), + profil->getLowerMinThreshold() ); } // Preview image for the user cv::cvtColor(rgb, gray, CV_BGR2GRAY); - gray = setup->beamer.editContrast(gray, (double)p.getContrast(), (double)p.getBrightness()); + gray = setup->getBeamer()->editContrast(gray, (double)profil->getContrast(), (double)profil->getBrightness()); if(displayConstrasts){ cvSobel(&gray); @@ -78,7 +76,7 @@ void CameraFocus::refreshFrame(){ void CameraFocus::initCameraParams(){ - FrameProcessProfil *profil = setup->beamer.getProfil(); + FrameProcessProfil *profil = setup->getBeamer()->getProfil(); defaultProfil.setContrast(profil->getContrast()); defaultProfil.setBrightness(profil->getBrightness()); @@ -106,33 +104,33 @@ void CameraFocus::loadProfil(FrameProcessProfil *profilLoaded, FrameProcessProfi void CameraFocus::on_dbsbxContrast_valueChanged(double arg1) { - setup->beamer.getProfil()->setContrast(arg1); + setup->getBeamer()->getProfil()->setContrast(arg1); } void CameraFocus::on_sbxBrightness_valueChanged(int arg1) { - setup->beamer.getProfil()->setBrightness(arg1); + setup->getBeamer()->getProfil()->setBrightness(arg1); } void CameraFocus::on_sbxRadiusRatio_valueChanged(int arg1) { - setup->beamer.getProfil()->setRadiusRatio(arg1); + setup->getBeamer()->getProfil()->setRadiusRatio(arg1); } void CameraFocus::on_sbxUpperMin_valueChanged(int arg1) { - setup->beamer.getProfil()->setUpperMinThreshold(arg1); + setup->getBeamer()->getProfil()->setUpperMinThreshold(arg1); } void CameraFocus::on_sbxLowerMin_valueChanged(int arg1) { - setup->beamer.getProfil()->setLowerMinThreshold(arg1); + setup->getBeamer()->getProfil()->setLowerMinThreshold(arg1); } void CameraFocus::on_btnReset_clicked() { - loadProfil(&defaultProfil, setup->beamer.getProfil()); + loadProfil(&defaultProfil, setup->getBeamer()-> getProfil()); } void CameraFocus::on_chbxDisplayContrast_clicked() diff --git a/app/SandboxSetup/camerafocus.ui b/app/SandboxSetup/camerafocus.ui index 4ce81bdceb657ef11d4eb89a1335808051d71860..75a52d0a786b622f10ceb0a1439610d3f3c2ece3 100644 --- a/app/SandboxSetup/camerafocus.ui +++ b/app/SandboxSetup/camerafocus.ui @@ -55,7 +55,7 @@ <double>255.000000000000000</double> </property> <property name="singleStep"> - <double>0.100000000000000</double> + <double>0.010000000000000</double> </property> </widget> </item> @@ -75,7 +75,7 @@ <number>255</number> </property> <property name="singleStep"> - <number>10</number> + <number>1</number> </property> </widget> </item> diff --git a/app/SandboxSetup/croppingmask.cpp b/app/SandboxSetup/croppingmask.cpp index 96dda9eaa8d5776a1aabe9b3907d4efa9fbd8e8b..9a2f70503f8a205a73f04b57f6946310dcd4ac2a 100644 --- a/app/SandboxSetup/croppingmask.cpp +++ b/app/SandboxSetup/croppingmask.cpp @@ -22,8 +22,8 @@ CroppingMask::~CroppingMask() void CroppingMask::on_btnTakePicture_clicked() { - setup->captureBlueScreen(); - cv::Mat rgb = setup->camera.getRGBFrame(); + setup->captureBlueScreen(500); + cv::Mat rgb = setup->getCamera()->getRGBFrame(); cameraRGBFrame = rgb; // no config found diff --git a/app/SandboxSetup/main.cpp b/app/SandboxSetup/main.cpp index 47b0779aa2abf6c9b379ade3a929a4f239079565..1c9720f2675c8da764da9dc11a9261d2f3b97bf8 100644 --- a/app/SandboxSetup/main.cpp +++ b/app/SandboxSetup/main.cpp @@ -13,11 +13,18 @@ void showImage(cv::Mat frame){ cv::imshow(wname, frame); } +void exit_msg(SandboxSetup *setup, std::string msg){ + setup->getCamera()->stop(); + std::cout << msg << std::endl; + exit(1); +} + int main(int argc, char *argv[]) { - SandboxSetup setup; QApplication app(argc, argv); + SandboxSetup setup; + setup.getCamera()->start(); // Select output screen and projection's resolutions @@ -25,10 +32,9 @@ int main(int argc, char *argv[]) mg.show(); app.exec(); if(!mg.isOk()){ - std::cout << "Cancel resolution" << std::endl; - return 1; + exit_msg(&setup, "Cancel resolution"); } - setup.setBeamerResolution(cv::Size(mg.getWidth(), mg.getHeight())); + setup.getBeamer()->setResolution(cv::Size(mg.getWidth(), mg.getHeight())); // Setup camera and beamer physically @@ -42,8 +48,7 @@ int main(int argc, char *argv[]) cf.show(); app.exec(); if(!cf.isOk()){ - std::cout << "Cancel camera parameters" << std::endl; - return 1; + exit_msg(&setup, "Cancel camera parameters"); } @@ -52,11 +57,10 @@ int main(int argc, char *argv[]) cm.show(); app.exec(); if(!cm.isOk()){ - std::cout << "Cancel crop" << std::endl; - return 1; + exit_msg(&setup, "Cancel drop"); } - cv::Size s = setup.camera.getDepthFrame().size(); + cv::Size s = setup.getCamera()->getDepthFrame().size(); cv::Point center(s.width / 2, s.height / 2); std::vector<cv::Point> rectPoints = cm.getRectPoints(); @@ -69,18 +73,16 @@ int main(int argc, char *argv[]) cv::setWindowProperty(wname, CV_WND_PROP_FULLSCREEN, CV_WINDOW_FULLSCREEN); if(setup.setupBeamerLocation(showImage)){ - std::cout << "Cancel beamer position" << std::endl; - return 1; + exit_msg(&setup, "Cancel beamer position"); } cv::destroyAllWindows(); // Save config in file if(setup.saveConfig()){ - std::cout << "Failed to save configuration" << std::endl; - return 1; + exit_msg(&setup, "Failed to save configuration"); } - + setup.getCamera()->stop(); return 0; } diff --git a/app/SandboxSetup/projectiongui.cpp b/app/SandboxSetup/projectiongui.cpp index 5df47d5cc3c70a453e6f62b16ba96720d989ba87..4a0a3538e2d796839afe52f5ec03d8873ccbe412 100644 --- a/app/SandboxSetup/projectiongui.cpp +++ b/app/SandboxSetup/projectiongui.cpp @@ -23,7 +23,6 @@ void ProjectionGui::on_btnSkip_clicked() { if(cameraUsed){ frameTimer->stop(); - setup->camera.stop(); blueScreen->close(); } close(); @@ -48,15 +47,14 @@ void ProjectionGui::on_btnStart_clicked() blueScreen->setStyleSheet("background-color:blue;"); blueScreen->show(); - setup->camera.start(); ui->fContainer->hide(); frameTimer->start(100); cameraUsed = true; } void ProjectionGui::refreshFrame(){ - setup->camera.captureFrame(); - cv::Mat rgb = setup->camera.getRGBFrame(); + setup->getCamera()->captureFrame(); + cv::Mat rgb = setup->getCamera()->getRGBFrame(); QImage img = QImage((uchar *)rgb.data, (int)rgb.cols, (int)rgb.rows, static_cast<int>(rgb.step.buf[0]), QImage::Format_RGB888); QPixmap image = QPixmap::fromImage(img); diff --git a/inc/beamer.h b/inc/beamer.h index bee44c86018cacab58eeef3088da1be27fac0436..fe5dc750e0665ccabc3ce68df96d9d430ea79828 100644 --- a/inc/beamer.h +++ b/inc/beamer.h @@ -52,10 +52,16 @@ class Beamer{ cv::Point3f getPosition(){ return beamerPosition; }; void setPosition(cv::Point3f pos){ beamerPosition = pos; }; + void setWidth(int w){ resolution.width = w; }; int getWidth(){ return resolution.width; }; void setHeight(int h){ resolution.height = h; }; int getHeight(){ return resolution.height; }; + void setResolution(cv::Size res){ + setWidth(res.width); + setHeight(res.height); + } + FrameProcessProfil* getProfil(){ return &profil; }; void setProfil(FrameProcessProfil p){ profil = p; }; diff --git a/inc/sandboxSetup.h b/inc/sandboxSetup.h index 0a3efe1e27e8fd0634ad110b900d886f34813998..cf34f7c99d67f242907435f9672910d3b3b03712 100644 --- a/inc/sandboxSetup.h +++ b/inc/sandboxSetup.h @@ -11,36 +11,34 @@ class SandboxSetup{ private: char *defaultConfigFilePath = (char *)"./sandbox_conf.yaml"; - + BeamerProjection projection; + Camera camera; + Beamer beamer; + double toDegrees(double radians); void initWindowsFullScreen(char *windowName); public: SandboxSetup(); - BeamerProjection projection; - Camera camera; - Beamer beamer; + BeamerProjection* getProjection(){ return &projection; }; + Camera* getCamera(){ return &camera; }; + Beamer* getBeamer(){ return &beamer; }; + // save config in file => persistant int saveConfigFrom(char *path); int saveConfig(); - int saveFrameProcessProfil(); + + int loadFrameProcessProfil(); // edit variables of config => not persistant - void captureBlueScreen(); + void captureBlueScreen(int delay); void setupAdjustMatrix(std::vector<cv::Point> rectPoints, cv::Point center); void setupCroppingMask(std::vector<cv::Point> rectPoints); int setupProjection(); int setupBeamerResolution(); int setupBeamerLocation(void (*showImage)(cv::Mat)); - int loadFrameProcessProfil(); - - void setBeamerResolution(cv::Size resolution); - void setBeamerPosition(cv::Point3f pos); - void setCroppingMask(cv::Rect mask); - void setAdjustingMatrix(cv::Mat matrix); - void setFrameProcessProfil(FrameProcessProfil profil); }; diff --git a/src/components/beamer.cpp b/src/components/beamer.cpp index 218dfc93d0e5106f5842632c44e754994e36f3ae..cf1a1b5996aa0246d4c5963f04f4de1fadfe8ba1 100644 --- a/src/components/beamer.cpp +++ b/src/components/beamer.cpp @@ -30,9 +30,6 @@ int Beamer::findBeamerFrom(Camera camera, void (*showImage)(cv::Mat)) points.push_back( cv::Point( getWidth() * 5/7 , getHeight() * 3/14)); points.push_back( cv::Point( getWidth() * 3/14, getHeight() * 4/7 )); - - camera.start(); - for (int i = 0; i < (int)points.size(); i++) { std::vector<cv::Point3f> capturedPoints; @@ -83,8 +80,6 @@ int Beamer::findBeamerFrom(Camera camera, void (*showImage)(cv::Mat)) bases.push_back(cv::Point3d(line[0], line[1], line[2])); } - camera.stop(); - cv::Point3d beamerPoint = approximatePosition(directions, bases); //set beamer position diff --git a/src/lib/sandboxSetup.cpp b/src/lib/sandboxSetup.cpp index c5ed66d9998cad714dd873d79dcf1e2730d2812d..a43f50389bf583d08a7fc54bbfb8414b9422ecdf 100644 --- a/src/lib/sandboxSetup.cpp +++ b/src/lib/sandboxSetup.cpp @@ -5,27 +5,6 @@ SandboxSetup::SandboxSetup(){ } -void SandboxSetup::setBeamerResolution(cv::Size resolution){ - beamer.setHeight(resolution.height); - beamer.setWidth(resolution.width); -} - -void SandboxSetup::setBeamerPosition(cv::Point3f pos){ - beamer.setPosition(pos); -} - -void SandboxSetup::setCroppingMask(cv::Rect mask){ - camera.setCroppingMask(mask); -} - -void SandboxSetup::setAdjustingMatrix(cv::Mat matrix){ - projection.setAdjustingMatrix(matrix); -} - -void SandboxSetup::setFrameProcessProfil(FrameProcessProfil profil){ - beamer.setProfil(profil); -} - // return 1 when config can't be saved in file int SandboxSetup::saveConfigFrom(char *path){ @@ -56,9 +35,6 @@ int SandboxSetup::loadFrameProcessProfil(){ return SandboxConfig::loadFrameProcessProfil(defaultConfigFilePath, beamer.getProfil()); } -int SandboxSetup::saveFrameProcessProfil(){ - return SandboxConfig::saveFrameProcessProfil(defaultConfigFilePath, *beamer.getProfil()); -} // @@ -97,7 +73,7 @@ int SandboxSetup::setupBeamerLocation(void (*showImage)(cv::Mat)){ // return 1 when user exits process int SandboxSetup::setupProjection(){ - captureBlueScreen(); + captureBlueScreen(300); cv::Mat frameData = camera.getDepthFrame(); cv::Mat coloredFrame = camera.getRGBFrame(); @@ -123,19 +99,18 @@ int SandboxSetup::setupProjection(){ } -void SandboxSetup::captureBlueScreen(){ - +void SandboxSetup::captureBlueScreen(int delay){ + // Blue screen char windowName[] = "border"; initWindowsFullScreen(windowName); cv::Mat frameBeamer(cv::Size(beamer.getWidth(), beamer.getHeight()), CV_8UC3, cv::Scalar(255, 0, 0)); cv::imshow(windowName, frameBeamer); - cv::waitKey(100); + delay = (delay==0)? 1 : delay; + cv::waitKey(delay); // Take picture - camera.start(); // 1 seconde of warming up camera.captureFrame(); - camera.stop(); cv::destroyAllWindows(); }