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

fixe BeamerLocation routine

parent fc7d1bec
Branches
No related tags found
No related merge requests found
...@@ -21,6 +21,7 @@ BeamerLocationGui::BeamerLocationGui(SandboxSetup *_setup, MonitorGui *_mg, QWid ...@@ -21,6 +21,7 @@ BeamerLocationGui::BeamerLocationGui(SandboxSetup *_setup, MonitorGui *_mg, QWid
winFullScreen = new QtFullScreen(mg->getResolution(), true, this); winFullScreen = new QtFullScreen(mg->getResolution(), true, this);
ui->setupUi(this); ui->setupUi(this);
ui->txtInstructions->setAlignment(Qt::AlignJustify); ui->txtInstructions->setAlignment(Qt::AlignJustify);
mut = new QMutex();
myThread = new RefreshFrame(this); myThread = new RefreshFrame(this);
timer = new QTimer(this); timer = new QTimer(this);
connect(timer, &QTimer::timeout, this, &BeamerLocationGui::refreshRoutine); connect(timer, &QTimer::timeout, this, &BeamerLocationGui::refreshRoutine);
...@@ -30,6 +31,7 @@ BeamerLocationGui::~BeamerLocationGui() ...@@ -30,6 +31,7 @@ BeamerLocationGui::~BeamerLocationGui()
{ {
delete timer; delete timer;
delete myThread; delete myThread;
delete mut;
delete winFullScreen; delete winFullScreen;
delete ui; delete ui;
} }
...@@ -71,7 +73,7 @@ void BeamerLocationGui::startRoutine(){ ...@@ -71,7 +73,7 @@ void BeamerLocationGui::startRoutine(){
directions = std::vector<cv::Point3d>(); directions = std::vector<cv::Point3d>();
bases = std::vector<cv::Point3d>(); bases = std::vector<cv::Point3d>();
capturedPoints = std::vector<cv::Point3f>(); capturedPoints = std::vector<cv::Point3f>();
circle = std::vector<cv::Point3i>(); circles = std::vector<cv::Point3i>();
updateLabelSteps(); updateLabelSteps();
if(myThread->isRunning()){ if(myThread->isRunning()){
...@@ -95,32 +97,35 @@ void BeamerLocationGui::routineFrame(){ ...@@ -95,32 +97,35 @@ void BeamerLocationGui::routineFrame(){
depth = camera->getDepthFrame(); depth = camera->getDepthFrame();
rgb = camera->getColorFrame(); rgb = camera->getColorFrame();
// Look for the circle target // Look for the circles target
double minDist = rgb.cols*(double)profil->getMinDistance()/100; double minDist = rgb.cols*(double)profil->getMinDistance()/100;
double minRadius = (profil->getMinRadius()>0) ? rgb.cols*(double)profil->getMinRadius()/100 : 0; double minRadius = (profil->getMinRadius()>0) ? rgb.cols*(double)profil->getMinRadius()/100 : 0;
double maxRadius = (profil->getMaxRadius()>0) ? rgb.cols*(double)profil->getMaxRadius()/100 : 0; double maxRadius = (profil->getMaxRadius()>0) ? rgb.cols*(double)profil->getMaxRadius()/100 : 0;
circle = beamer->findCircles( rgb, std::vector<cv::Point3i> tmp_circles = beamer->findCircles( rgb,
profil->getContrast(), profil->getContrast(),
profil->getBrightness(), profil->getBrightness(),
minDist, minDist,
(int)profil->getCannyEdgeThreshold(), (int)profil->getCannyEdgeThreshold(),
(int)profil->getHoughAccThreshold(), (int)profil->getHoughAccThreshold(),
minRadius, minRadius,
maxRadius ); maxRadius );
mut->lock();
circles = tmp_circles;
mut->unlock();
// preview from the camera's POV // preview from the camera's POV
cv::Mat gray, frameDisplayed; cv::Mat gray, frameDisplayed;
cv::cvtColor(rgb, gray, CV_BGR2GRAY); cv::cvtColor(rgb, gray, CV_BGR2GRAY);
gray = setup->getBeamer()->editContrast(gray, (double)profil->getContrast(), (double)profil->getBrightness()); gray = setup->getBeamer()->editContrast(gray, (double)profil->getContrast(), (double)profil->getBrightness());
cv::cvtColor(gray, frameDisplayed, CV_GRAY2RGB); cv::cvtColor(gray, frameDisplayed, CV_GRAY2RGB);
if(!circle.empty()){ if(!circles.empty()){
cv::circle(frameDisplayed, cv::Point(circle[0].x, circle[0].y), circle[0].z, cv::Scalar(0,255,0), 3); cv::circle(frameDisplayed, cv::Point(circles[0].x, circles[0].y), circles[0].z, cv::Scalar(0,255,0), 3);
} }
QImage img = QImage((uchar *)frameDisplayed.data, (int)frameDisplayed.cols, (int)frameDisplayed.rows, static_cast<int>(frameDisplayed.step.buf[0]), QImage::Format_RGB888); QImage img = QImage((uchar *)frameDisplayed.data, (int)frameDisplayed.cols, (int)frameDisplayed.rows, static_cast<int>(frameDisplayed.step.buf[0]), QImage::Format_RGB888);
QPixmap px = QPixmap::fromImage(img); QPixmap px = QPixmap::fromImage(img);
// Show black screen with cross // Show black screen with cross
cv::Mat frameImage = beamer->getCrossFrame(cross, capturedPoints.size()+1, beamer->MAX_LINEAR_LINE_POINTS, !circle.empty()); cv::Mat frameImage = beamer->getCrossFrame(cross, capturedPoints.size()+1, beamer->MAX_LINEAR_LINE_POINTS, !circles.empty());
cv::cvtColor(frameImage, frameImage, CV_BGR2RGB); cv::cvtColor(frameImage, frameImage, CV_BGR2RGB);
ui->lblFrame->setPixmap(px); ui->lblFrame->setPixmap(px);
...@@ -131,9 +136,17 @@ void BeamerLocationGui::routineFrame(){ ...@@ -131,9 +136,17 @@ void BeamerLocationGui::routineFrame(){
void BeamerLocationGui::userValidePoint(){ void BeamerLocationGui::userValidePoint(){
if(!circle.empty()){ std::vector<cv::Point3i> tmp_circles;
mut->lock();
if(!circles.empty()){
tmp_circles = circles;
circles.clear();
}
mut->unlock();
capturedPoints.push_back( beamer->deprojectPixel(cv::Point2i(circle.at(0).x, circle.at(0).y), &depth, camera) ); if(!tmp_circles.empty()){
cv::Point2i circle_pos = cv::Point2i(tmp_circles.at(0).x, tmp_circles.at(0).y);
capturedPoints.push_back( beamer->deprojectPixel(circle_pos, &depth, camera) );
updateLabelSteps(); updateLabelSteps();
// enough points to perform linear regression and move into next step // enough points to perform linear regression and move into next step
...@@ -141,7 +154,6 @@ void BeamerLocationGui::userValidePoint(){ ...@@ -141,7 +154,6 @@ void BeamerLocationGui::userValidePoint(){
beamer->findLinearLineFrom(&capturedPoints, &bases, &directions); beamer->findLinearLineFrom(&capturedPoints, &bases, &directions);
capturedPoints.clear(); capturedPoints.clear();
circle.clear();
stepCross++; stepCross++;
if((uint)stepCross >= crosses.size()){ if((uint)stepCross >= crosses.size()){
......
...@@ -63,7 +63,8 @@ private: ...@@ -63,7 +63,8 @@ private:
std::vector<cv::Point3f> capturedPoints; std::vector<cv::Point3f> capturedPoints;
cv::Mat depth; cv::Mat depth;
cv::Mat rgb; cv::Mat rgb;
std::vector<cv::Point3i> circle; QMutex *mut;
std::vector<cv::Point3i> circles;
int stepCross = 0; int stepCross = 0;
QTimer *timer; QTimer *timer;
RefreshFrame *myThread; RefreshFrame *myThread;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment