Skip to content
Snippets Groups Projects
Commit edbf95c3 authored by simon.fanetti's avatar simon.fanetti
Browse files

fixed loaded config + some cleaning

parent b3c0bdb1
No related branches found
No related tags found
No related merge requests found
...@@ -21,5 +21,7 @@ public: ...@@ -21,5 +21,7 @@ public:
int getWidth(){ return width; }; int getWidth(){ return width; };
int getHeight(){ return height; }; int getHeight(){ return height; };
void findBeamerFrom(Camera camera); void findBeamerFrom(Camera camera);
void printPosition();
}; };
#endif #endif
...@@ -16,7 +16,8 @@ public: ...@@ -16,7 +16,8 @@ public:
cv::Point2i rotatePixel(cv::Point2i pixel); cv::Point2i rotatePixel(cv::Point2i pixel);
void adjustFrame(cv::Mat &src, cv::Mat &dst, Camera camera, cv::Point3f beamer); void adjustFrame(cv::Mat &src, cv::Mat &dst, Camera camera, cv::Point3f beamer);
void adjustFrame(cv::Mat &depth, cv::Mat &src, cv::Mat &dst, Camera camera, cv::Point3f beamer); void adjustFrame(cv::Mat &depth, cv::Mat &src, cv::Mat &dst, Camera camera, cv::Point3f beamer);
void setAdjustingMatrix(cv::Mat matrix){ adjustingMatrix = matrix.clone(); } void setAdjustingMatrix(cv::Mat matrix){ matrix.clone(); }
cv::Mat getAdjustingMatrix(){ return adjustingMatrix.clone(); } cv::Mat getAdjustingMatrix(){ return adjustingMatrix.clone(); }
void printAdjustingMatrix();
}; };
#endif #endif
\ No newline at end of file
...@@ -40,5 +40,7 @@ public: ...@@ -40,5 +40,7 @@ public:
cv::Mat getRGBFrameAlign(){ return matRGB.clone(); }; cv::Mat getRGBFrameAlign(){ return matRGB.clone(); };
void setCroppingMask(cv::Rect mask){ croppingMask = mask; }; void setCroppingMask(cv::Rect mask){ croppingMask = mask; };
cv::Rect getCroppingMask(){ return croppingMask; }; cv::Rect getCroppingMask(){ return croppingMask; };
void printCroppingMask();
}; };
#endif #endif
\ No newline at end of file
...@@ -10,24 +10,26 @@ ...@@ -10,24 +10,26 @@
class Controller class Controller
{ {
public:
Controller();
cv::Mat getRGBFrame();
cv::Mat getDepthFrame();
void showImage(cv::Mat* image);
void loadConfig();
void loadConfigFrom(char *path);
void initWindowsFullScreen();
private: private:
static const int ESCAPE_CHAR = 27; static const int ESCAPE_CHAR = 27;
char *defaultConfigFilePath = (char *)"./sandbox_conf.yaml"; char *defaultConfigFilePath = (char *)"./sandbox_conf.yaml";
char *defaultWindowsName = (char*) "Image"; char *defaultWindowsName = (char*) "ShowApp";
BeamerProjection projection; BeamerProjection projection;
Camera camera; Camera camera;
Beamer beamer; Beamer beamer;
void initWindowsFullScreen(char *windowName); void initWindowsFullScreen(char *windowName);
void showImage(cv::Mat* image, char *windowName); void showImage(cv::Mat* image, char *windowName);
public:
Controller();
cv::Mat getRGBFrame();
cv::Mat getDepthFrame();
cv::Mat* adjustProjection(cv::Mat* frame);
void showImage(cv::Mat* image);
int loadConfig();
int loadConfigFrom(char *path);
void initWindowsFullScreen();
}; };
#endif #endif
...@@ -6,14 +6,17 @@ ...@@ -6,14 +6,17 @@
class Sandbox class Sandbox
{ {
private:
Controller controller;
public: public:
Sandbox(); Sandbox();
cv::Mat getRGBFrame(); cv::Mat getRGBFrame();
cv::Mat getDepthFrame(); cv::Mat getDepthFrame();
cv::Mat* adjustProjection(cv::Mat* frame);
void initWindowsFullScreen();
void showImage(cv::Mat* image); void showImage(cv::Mat* image);
void loadConfig(); int loadConfig();
private:
Controller controller;
}; };
#endif #endif
...@@ -113,6 +113,9 @@ void Beamer::findBeamerFrom(Camera camera) ...@@ -113,6 +113,9 @@ void Beamer::findBeamerFrom(Camera camera)
vector<Point3d> points2; //1 point for each vector (to calculate constante d) vector<Point3d> points2; //1 point for each vector (to calculate constante d)
double fact = -20.0; double fact = -20.0;
camera.startAlign();
for (int i = 0; i < (int)points.size(); i++) for (int i = 0; i < (int)points.size(); i++)
{ {
vector<Point3f> capturedPoints; vector<Point3f> capturedPoints;
...@@ -158,6 +161,8 @@ void Beamer::findBeamerFrom(Camera camera) ...@@ -158,6 +161,8 @@ void Beamer::findBeamerFrom(Camera camera)
} }
} }
camera.stop();
Point3d pa, pb; Point3d pa, pb;
double mua; double mua;
double mub; double mub;
...@@ -186,3 +191,9 @@ void Beamer::findBeamerFrom(Camera camera) ...@@ -186,3 +191,9 @@ void Beamer::findBeamerFrom(Camera camera)
destroyAllWindows(); destroyAllWindows();
} }
void Beamer::printPosition(){
cv::Point3f pos = getPosition();
std::cout << "(" << pos.x << "," << pos.y << "," << pos.z << ")" << std::endl;
}
...@@ -15,8 +15,8 @@ Point2i BeamerProjection::rotatePixel(Point2i pixel) ...@@ -15,8 +15,8 @@ Point2i BeamerProjection::rotatePixel(Point2i pixel)
return Point2i(tmp.at<Vec2f>(0, 0)); return Point2i(tmp.at<Vec2f>(0, 0));
} }
Point2i BeamerProjection::adjustPixel(int i, int j, float z, Camera camera, Point3f beamer) Point2i BeamerProjection::adjustPixel(int i, int j, float z, Camera camera, Point3f beamer){
{
//pixel to point 3d //pixel to point 3d
float coord[2] = {static_cast<float>(j), static_cast<float>(i)}; float coord[2] = {static_cast<float>(j), static_cast<float>(i)};
Point3f p = camera.deprojectPixelToPoint(coord, z / 1000.0); Point3f p = camera.deprojectPixelToPoint(coord, z / 1000.0);
...@@ -50,8 +50,8 @@ void BeamerProjection::adjustFrame(cv::Mat &src, cv::Mat &dst, Camera camera, Po ...@@ -50,8 +50,8 @@ void BeamerProjection::adjustFrame(cv::Mat &src, cv::Mat &dst, Camera camera, Po
// medianBlur(dst, dst, 3); // medianBlur(dst, dst, 3);
} }
void BeamerProjection::adjustFrame(cv::Mat &depth, cv::Mat &src, cv::Mat &dst, Camera camera, Point3f beamer) void BeamerProjection::adjustFrame(cv::Mat &depth, cv::Mat &src, cv::Mat &dst, Camera camera, Point3f beamer){
{
int nbChannel = src.channels(); int nbChannel = src.channels();
//transformation on all pixel //transformation on all pixel
//int64_t t1 = getTickCount(); //int64_t t1 = getTickCount();
...@@ -75,3 +75,14 @@ void BeamerProjection::adjustFrame(cv::Mat &depth, cv::Mat &src, cv::Mat &dst, C ...@@ -75,3 +75,14 @@ void BeamerProjection::adjustFrame(cv::Mat &depth, cv::Mat &src, cv::Mat &dst, C
dilate(dst, dst, Mat(), Point(-1, -1), 2, 1, 1); dilate(dst, dst, Mat(), Point(-1, -1), 2, 1, 1);
erode(dst, dst, Mat(), Point(-1, -1), 2, 1, 1); erode(dst, dst, Mat(), Point(-1, -1), 2, 1, 1);
} }
void BeamerProjection::printAdjustingMatrix(){
cv::Mat matrix = getAdjustingMatrix();
for (int y = 0; y < matrix.rows; y++){
for (int x = 0; x < matrix.cols; x++){
std::cout << (float)matrix.at<double>(y, x) << " ";
}
std::cout << std::endl;
}
}
\ No newline at end of file
#include "../../../includes/camera.h" #include "../../../includes/camera.h"
using namespace cv; using namespace cv;
Camera::Camera() {}
Camera::Camera() {
}
// Capture 30 frames to give autoexposure, etc. a chance to settle // Capture 30 frames to give autoexposure, etc. a chance to settle
void Camera::warmingUp() void Camera::warmingUp()
...@@ -148,3 +151,9 @@ void Camera::stop() ...@@ -148,3 +151,9 @@ void Camera::stop()
{ {
pipe.stop(); pipe.stop();
} }
void Camera::printCroppingMask(){
cv::Rect mask = getCroppingMask();
std::cout << "(" << mask.x << "," << mask.y << ") + " << mask.width << "," << mask.height << std::endl;
}
\ No newline at end of file
...@@ -11,7 +11,7 @@ using namespace std; ...@@ -11,7 +11,7 @@ using namespace std;
*/ */
Controller::Controller(){ Controller::Controller(){
camera.startAlign();
} }
...@@ -29,42 +29,72 @@ cv::Mat Controller::getDepthFrame(){ ...@@ -29,42 +29,72 @@ cv::Mat Controller::getDepthFrame(){
return camera.getDepthFrameAlign()(camera.getCroppingMask()); return camera.getDepthFrameAlign()(camera.getCroppingMask());
} }
cv::Mat* Controller::adjustProjection(cv::Mat* frame){
static cv::Mat frameBeamer(cv::Size(beamer.getWidth(), beamer.getHeight()), CV_8UC3);
cv::Mat depth = getDepthFrame();
cv::Mat imageCalibrate(depth.size(), CV_8UC3, cv::Scalar(0, 0, 0));
cv::resize(*frame, *frame, depth.size());
projection.adjustFrame(depth, *frame, imageCalibrate, camera, beamer.getPosition());
//flip to align frame with beamer
cv::flip(imageCalibrate, imageCalibrate, 1);
cv::flip(imageCalibrate, imageCalibrate, 0);
cv::resize(imageCalibrate, frameBeamer, frameBeamer.size());
frameBeamer.copyTo(*frame);
return frame;
}
void Controller::showImage(cv::Mat* image){ void Controller::showImage(cv::Mat* image){
showImage(image, defaultWindowsName);
initWindowsFullScreen(defaultWindowsName);
adjustProjection(image);
cv::imshow(defaultWindowsName, *image);
} }
void Controller::loadConfigFrom(char *path){ int Controller::loadConfigFrom(char *path){
SandboxConfig::loadAdjustingMatrixInto(path, &projection);
SandboxConfig::loadCroppingMaskInto(path, &camera); int err = SandboxConfig::loadAdjustingMatrixInto(path, &projection);
SandboxConfig::loadBeamerPositionInto(path, &beamer); if(err){ return err; }
err = SandboxConfig::loadCroppingMaskInto(path, &camera);
if(err){ return err; }
err = SandboxConfig::loadBeamerPositionInto(path, &beamer);
if(err){ return err; }
return 0;
}
int Controller::loadConfig(){
std::cout << "Config loading..." << std::endl;
int err = loadConfigFrom(defaultConfigFilePath);
if(err){
std::cout << "error config" << std::endl;
return err;
} }
void Controller::loadConfig(){ std::cout << "Adjusting Matrix :" << std::endl;
loadConfigFrom(defaultConfigFilePath); projection.printAdjustingMatrix();
std::cout << "Cropping mask (base+size) :" << std::endl;
camera.printCroppingMask();
std::cout << "Beamer position :" << std::endl;
beamer.printPosition();
return 0;
} }
void Controller::initWindowsFullScreen(){ void Controller::initWindowsFullScreen(){
initWindowsFullScreen(defaultWindowsName); initWindowsFullScreen(defaultWindowsName);
} }
/* /*
* PRIVATE * PRIVATE
*/ */
void Controller::showImage(cv::Mat* image, char *windowName){
static cv::Mat frameBeamer(cv::Size(beamer.getWidth(), beamer.getHeight()), CV_8UC3);
camera.captureFramesAlign();
cv::Mat depth = camera.getDepthFrameAlign()(camera.getCroppingMask());
resize(*image, *image, depth.size());
cv::Mat imageCalibrate(depth.size(), CV_8UC3, cv::Scalar(0, 0, 0));
projection.adjustFrame(depth, *image, imageCalibrate, camera, beamer.getPosition());
//flip to align frame with beamer
cv::flip(imageCalibrate, imageCalibrate, 1);
cv::flip(imageCalibrate, imageCalibrate, 0);
cv::resize(imageCalibrate, frameBeamer, frameBeamer.size());
cv::imshow(windowName, frameBeamer);
}
void Controller::initWindowsFullScreen(char *windowName){ void Controller::initWindowsFullScreen(char *windowName){
cv::namedWindow(windowName, CV_WINDOW_NORMAL); cv::namedWindow(windowName, CV_WINDOW_NORMAL);
cv::setWindowProperty(windowName, CV_WND_PROP_FULLSCREEN, CV_WINDOW_FULLSCREEN); cv::setWindowProperty(windowName, CV_WND_PROP_FULLSCREEN, CV_WINDOW_FULLSCREEN);
......
...@@ -9,11 +9,10 @@ int SandboxConfig::saveAdjustingMatrixInto(char *path, cv::Mat matrix){ ...@@ -9,11 +9,10 @@ int SandboxConfig::saveAdjustingMatrixInto(char *path, cv::Mat matrix){
YAML::Node vec = YAML::Load("[]"); YAML::Node vec = YAML::Load("[]");
for (int y = 0; y < matrix.rows; y++){ for (int y = 0; y < matrix.rows; y++){
for (int x = 0; x < matrix.cols; x++){ for (int x = 0; x < matrix.cols; x++){
vec.push_back(matrix.at<float>(y, x)); vec.push_back((float)matrix.at<double>(y, x));
} }
} }
YAML::Node val; YAML::Node val;
val["width"] = matrix.cols; val["width"] = matrix.cols;
...@@ -29,14 +28,6 @@ int SandboxConfig::saveAdjustingMatrixInto(char *path, cv::Mat matrix){ ...@@ -29,14 +28,6 @@ int SandboxConfig::saveAdjustingMatrixInto(char *path, cv::Mat matrix){
config[MATRIX] = val; config[MATRIX] = val;
std::cout << "Adjusting Matrix" << std::endl;
for (int y = 0; y < matrix.rows; y++){
for (int x = 0; x < matrix.cols; x++){
std::cout << matrix.at<float>(y, x) << " ";
}
std::cout << std::endl;
}
return saveConfigIn(path, config); return saveConfigIn(path, config);
} }
...@@ -59,10 +50,6 @@ int SandboxConfig::saveCroppingMaskInto(char *path, cv::Rect mask){ ...@@ -59,10 +50,6 @@ int SandboxConfig::saveCroppingMaskInto(char *path, cv::Rect mask){
config[MASK] = val; config[MASK] = val;
std::cout << "Cropping Mask (base + size)" << std::endl;
std::cout << "(" << mask.x << "," << mask.y << ") + ";
std::cout << "(" << mask.width << "," << mask.height << ")" << std::endl;
return saveConfigIn(path, config); return saveConfigIn(path, config);
} }
...@@ -84,8 +71,6 @@ int SandboxConfig::saveBeamerPositionInto(char *path, cv::Point3f pos){ ...@@ -84,8 +71,6 @@ int SandboxConfig::saveBeamerPositionInto(char *path, cv::Point3f pos){
config[POSITION] = val; config[POSITION] = val;
std::cout << "Beamer position: " << pos.x << " " << pos.y << " " << pos.z << std::endl;
return saveConfigIn(path, config); return saveConfigIn(path, config);
} }
...@@ -131,16 +116,6 @@ int SandboxConfig::loadAdjustingMatrixInto(char *path, BeamerProjection *project ...@@ -131,16 +116,6 @@ int SandboxConfig::loadAdjustingMatrixInto(char *path, BeamerProjection *project
projection->setAdjustingMatrix(matrix); projection->setAdjustingMatrix(matrix);
// Debug
matrix = projection->getAdjustingMatrix();
std::cout << "Adjusting Matrix" << std::endl;
for (int y = 0; y < matrix.rows; y++){
for (int x = 0; x < matrix.cols; x++){
std::cout << matrix.at<float>(y, x) << " ";
}
std::cout << std::endl;
}
return 0; return 0;
} }
...@@ -173,10 +148,6 @@ int SandboxConfig::loadCroppingMaskInto(char *path, Camera *camera){ ...@@ -173,10 +148,6 @@ int SandboxConfig::loadCroppingMaskInto(char *path, Camera *camera){
camera->setCroppingMask(mask); camera->setCroppingMask(mask);
// Debug
mask = camera->getCroppingMask();
std::cout << "Cropping mask (base+size): (" << mask.x << "," << mask.y << ") + " << mask.width << "," << mask.height << std::endl;
return 0; return 0;
} }
...@@ -208,10 +179,6 @@ int SandboxConfig::loadBeamerPositionInto(char *path, Beamer *beamer){ ...@@ -208,10 +179,6 @@ int SandboxConfig::loadBeamerPositionInto(char *path, Beamer *beamer){
beamer->setPosition(pos); beamer->setPosition(pos);
// Debug
pos = beamer->getPosition();
std::cout << "Beamer position :" << std::endl << "(" << pos.x << "," << pos.y << "," << pos.z << ")" << std::endl;
return 0; return 0;
} }
......
#include "../includes/sandbox.h" #include "../includes/sandbox.h"
Sandbox::Sandbox(){ Sandbox::Sandbox(){
controller.initWindowsFullScreen();
} }
cv::Mat Sandbox::getRGBFrame(){ cv::Mat Sandbox::getRGBFrame(){
...@@ -12,10 +12,18 @@ cv::Mat Sandbox::getDepthFrame(){ ...@@ -12,10 +12,18 @@ cv::Mat Sandbox::getDepthFrame(){
return controller.getDepthFrame(); return controller.getDepthFrame();
} }
cv::Mat* Sandbox::adjustProjection(cv::Mat* frame){
return controller.adjustProjection(frame);
}
void Sandbox::initWindowsFullScreen(){
controller.initWindowsFullScreen();
}
void Sandbox::showImage(cv::Mat* image){ void Sandbox::showImage(cv::Mat* image){
controller.showImage(image); controller.showImage(image);
} }
void Sandbox::loadConfig(){ int Sandbox::loadConfig(){
controller.loadConfig(); return controller.loadConfig();
} }
\ No newline at end of file
...@@ -37,6 +37,7 @@ void SandboxSetup::setupProjection(){ ...@@ -37,6 +37,7 @@ void SandboxSetup::setupProjection(){
cv::Mat coloredFrame = camera.getRGBFrameAlign(); cv::Mat coloredFrame = camera.getRGBFrameAlign();
cv::Size s = frameData.size(); cv::Size s = frameData.size();
cv::Point center(s.width / 2, s.height / 2); cv::Point center(s.width / 2, s.height / 2);
camera.stop();
cv::destroyAllWindows(); cv::destroyAllWindows();
// Edit projection // Edit projection
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment