105 lines
2.4 KiB
C++
105 lines
2.4 KiB
C++
#include "aigoqt.h"
|
|
#include <QtDebug>
|
|
#include <state.h>
|
|
#include "image.h"
|
|
|
|
AigoQt::AigoQt(QWidget *parent)
|
|
: QMainWindow(parent)
|
|
{
|
|
setupUi(this);
|
|
cam = new Quickcam("/dev/video0");
|
|
|
|
timer = new QTimer(this);
|
|
connect(timer, SIGNAL(timeout()), this, SLOT(updateImage()));
|
|
timer->start(10);
|
|
|
|
}
|
|
|
|
AigoQt::~AigoQt( void )
|
|
{
|
|
delete cam;
|
|
}
|
|
|
|
void AigoQt::updateImage( void )
|
|
{
|
|
cam->update();
|
|
SDL_Surface *s = cam->getSurface();
|
|
Image::threshold(s, sliderBlack->value(), sliderWhite->value());
|
|
image->setPixmap(QPixmap::fromImage(QImage((uchar*)s->pixels, s->w, s->h, QImage::Format_RGB32)));
|
|
on_buttonGenerateState_clicked();
|
|
}
|
|
|
|
void AigoQt::on_buttonSetCorners_clicked( void )
|
|
{
|
|
disconnect(image, 0, 0, 0);
|
|
connect(image, SIGNAL(clicked(int, int)), this, SLOT(handleCornerClicked(int, int)));
|
|
statusBar()->showMessage("Please click the upper left corner of the board.");
|
|
}
|
|
|
|
void AigoQt::on_buttonGenerateState_clicked( void )
|
|
{
|
|
State state = State::generateState(cam->getSurface(), settings);
|
|
state.printState();
|
|
}
|
|
|
|
void AigoQt::on_sliderBlack_valueChanged( int value)
|
|
{
|
|
settings.setBlackThreshold(value);
|
|
on_buttonGenerateState_clicked();
|
|
}
|
|
|
|
void AigoQt::on_sliderWhite_valueChanged( int value)
|
|
{
|
|
settings.setWhiteThreshold(value);
|
|
on_buttonGenerateState_clicked();
|
|
}
|
|
|
|
void AigoQt::on_buttonDrawPoints_clicked( void )
|
|
{
|
|
updateImage();
|
|
for (int i = 0; i < 19; i++)
|
|
{
|
|
for (int j = 0; j < 19; j++)
|
|
{
|
|
point p = State::positionPoint(i, j, settings);
|
|
((uint32_t*)cam->getSurface()->pixels)[p.y*640 + p.x] = 0xffff0000;
|
|
}
|
|
}
|
|
SDL_Surface *s = cam->getSurface();
|
|
image->setPixmap(QPixmap::fromImage(QImage((uchar*)s->pixels, s->w, s->h, QImage::Format_RGB32)));
|
|
}
|
|
|
|
void AigoQt::handleCornerClicked( int x, int y)
|
|
{
|
|
point p;
|
|
p.x = x;
|
|
p.y = y;
|
|
|
|
QString pointString = QString::fromLatin1("(%1, %2)").arg(x).arg(y);
|
|
|
|
static int corner = -1;
|
|
++corner %= 4;
|
|
switch (corner)
|
|
{
|
|
case 0:
|
|
settings.setUL(p);
|
|
statusBar()->showMessage("Upper left set to " + pointString + ". Click upper right.");
|
|
break;
|
|
case 1:
|
|
settings.setUR(p);
|
|
statusBar()->showMessage("Upper right set to " + pointString + ". Click bottom left.");
|
|
break;
|
|
case 2:
|
|
settings.setBL(p);
|
|
statusBar()->showMessage("Bottom left set to " + pointString + ". Click bottom right.");
|
|
break;
|
|
case 3:
|
|
settings.setBR(p);
|
|
statusBar()->showMessage("Bottom right set to " + pointString + ". All done.");
|
|
disconnect(image, NULL, this, NULL);
|
|
break;
|
|
}
|
|
}
|
|
|
|
#include "aigoqt.moc"
|