Exemplo n.º 1
0
void CamLabel::mouseMoveEvent(QMouseEvent *ev)
{
    if(ev->buttons() & Qt::LeftButton)
        emit mousePressed(ev->x(), ev->y());
    else if(ev->buttons() & Qt::RightButton)
    {
        emit mouseRightPressed(ev->x()-prevx, ev->y()-prevy);
        prevx = ev->x();
        prevy = ev->y();
    }
    emit mouseOnlyMove(ev->x(), ev->y());
}
Exemplo n.º 2
0
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    calib_vs_vision = false;

    sql = new SQLite("../data/main.db", "passwd");

    for(int i = 0 ; i < 8 ; i++){
        colors.push_back(0);
    }

    image = new QCustomLabel();
    image->setMouseTracking(true);
    QObject::connect(image, SIGNAL(Mouse_Pos()), this, SLOT(mouseCurrentPos()));
    QObject::connect(image, SIGNAL(Mouse_Left_Pressed()), this, SLOT(mouseLeftPressed()));
    QObject::connect(image, SIGNAL(Mouse_Right_Pressed()), this, SLOT(mouseRightPressed()));

    ui->layoutH2->addWidget(image);

    QObject::connect(&calib, SIGNAL(finished()), this, SLOT(quit()));
    calib.alloc_label_input(image);
    calib.alloc_calibration(&_calib);

    QObject::connect(&vi, SIGNAL(finished()), this, SLOT(quit()));
    vi.alloc_label_input(image);
    vi.alloc_calibration(&_calib);
    vi.alloc_state(&state);
    vi.alloc_colors(&colors);
    vi.alloc_execution_config(&execConfig);

    calib.start();
    vi.start();

    image->show();


    coordinate_mouse = new QLabel("M(0, 0)");

    mainItem = new QTreeWidgetItem;

    cmbCameraIds = new QComboBox();
    cmbSavedImages = new QComboBox();
    cmbSavedVideos = new QComboBox();

    checkUseCamera = new QCheckBox();
    checkUseImage = new QCheckBox();
    checkUseVideo = new QCheckBox();

    cmbColors = new QComboBox();
    cmbBallColors = new QComboBox();
    cmbMainColors_1 = new QComboBox();
    cmbMainColors_2 = new QComboBox();
    cmbSecColors_1 = new QComboBox();
    cmbSecColors_2 = new QComboBox();
    cmbSecColors_3 = new QComboBox();
    cmbSecColors_4 = new QComboBox();
    cmbSecColors_5 = new QComboBox();
    cmbSecColors_6 = new QComboBox();

    btnDoColorCalib = new QPushButton("Do", this);
    btnRunVision = new QPushButton("Run", this);

    blockdevice = QIcon(":icons/blockdevice.png");
    ksame = QIcon(":icons/ksame.png");
    kdf = QIcon(":icons/kdf.png");
    package = QIcon(":icons/package.png");

    getAllDevices();
    buildTrees();

    if(devices.size() < 1){
        checkUseCamera->setChecked(false);
        checkUseImage->setChecked(true);
        checkUseVideo->setChecked(false);
        cmbCameraIds->setDisabled(true);

    }else{
        checkUseCamera->setChecked(true);
        checkUseImage->setChecked(false);
        checkUseVideo->setChecked(false);
    }

    lblH = new QLabel("H (0 - 180)");
    lblS = new QLabel("S (0 - 255)");
    lblV = new QLabel("V (0 - 255)");

    lbl_val = new QLabel("Pos\nVel\nKPos\nKVel");

    val_ball = new QLabel("Ball");
    val_robot1 = new QLabel("Robot 1");
    val_robot2 = new QLabel("Robot 2");
    val_robot3 = new QLabel("Robot 3");
    val_robot4 = new QLabel("Robot 4");
    val_robot5 = new QLabel("Robot 5");
    val_robot6 = new QLabel("Robot 6");

    h_val_ball = new QLabel("000, 000, 0.00\n000, 000, 0.00\n000, 000, 0.00\n000, 000, 0.00\n");
    h_val_robot1 = new QLabel("000, 000, 0.00\n000, 000, 0.00\n000, 000, 0.00\n000, 000, 0.00\n");
    h_val_robot2 = new QLabel("000, 000, 0.00\n000, 000, 0.00\n000, 000, 0.00\n000, 000, 0.00\n");
    h_val_robot3 = new QLabel("000, 000, 0.00\n000, 000, 0.00\n000, 000, 0.00\n000, 000, 0.00\n");
    h_val_robot4 = new QLabel("000, 000, 0.00\n000, 000, 0.00\n000, 000, 0.00\n000, 000, 0.00\n");
    h_val_robot5 = new QLabel("000, 000, 0.00\n000, 000, 0.00\n000, 000, 0.00\n000, 000, 0.00\n");
    h_val_robot6 = new QLabel("000, 000, 0.00\n000, 000, 0.00\n000, 000, 0.00\n000, 000, 0.00\n");

    lbl_val->setStyleSheet("QLabel {qproperty-alignment: AlignCenter; font-size: 14px; background: white; border: 1px solid #bbb;");

    h_val_ball->setStyleSheet("QLabel {qproperty-alignment: AlignCenter; font-size: 14px; background: white; border: 1px solid #bbb;}");
    h_val_robot1->setStyleSheet("QLabel {qproperty-alignment: AlignCenter; font-size: 14px; background: white; border: 1px solid #bbb;}");
    h_val_robot2->setStyleSheet("QLabel {qproperty-alignment: AlignCenter; font-size: 14px; background: white; border: 1px solid #bbb;}");
    h_val_robot3->setStyleSheet("QLabel {qproperty-alignment: AlignCenter; font-size: 14px; background: white; border: 1px solid #bbb;}");
    h_val_robot4->setStyleSheet("QLabel {qproperty-alignment: AlignCenter; font-size: 14px; background: white; border: 1px solid #bbb;}");
    h_val_robot5->setStyleSheet("QLabel {qproperty-alignment: AlignCenter; font-size: 14px; background: white; border: 1px solid #bbb;}");
    h_val_robot6->setStyleSheet("QLabel {qproperty-alignment: AlignCenter; font-size: 14px; background: white; border: 1px solid #bbb;}");

    sliderHmin = new QSlider(Qt::Orientation(VerticalTabs));
    sliderHmax = new QSlider(Qt::Orientation(VerticalTabs));
    sliderSmin = new QSlider(Qt::Orientation(VerticalTabs));
    sliderSmax = new QSlider(Qt::Orientation(VerticalTabs));
    sliderVmin = new QSlider(Qt::Orientation(VerticalTabs));
    sliderVmax = new QSlider(Qt::Orientation(VerticalTabs));

    sliderHmin->setMaximum(179);
    sliderSmin->setMaximum(254);
    sliderVmin->setMaximum(254);
    sliderHmax->setMaximum(180);
    sliderSmax->setMaximum(255);
    sliderVmax->setMaximum(255);

    sliderHmin->setMinimum(0);
    sliderSmin->setMinimum(0);
    sliderVmin->setMinimum(0);
    sliderHmax->setMinimum(1);
    sliderSmax->setMinimum(1);
    sliderVmax->setMinimum(1);

    sliderHmin->setMinimumHeight(140);
    sliderSmin->setMinimumHeight(140);
    sliderVmin->setMinimumHeight(140);
    sliderHmax->setMinimumHeight(140);
    sliderSmax->setMinimumHeight(140);
    sliderVmax->setMinimumHeight(140);

    sliderHmin->setValue(_calib.colors.at(0).min.rgb[h]);
    sliderSmin->setValue(_calib.colors.at(0).min.rgb[s]);
    sliderVmin->setValue(_calib.colors.at(0).min.rgb[v]);
    sliderHmax->setValue(_calib.colors.at(0).max.rgb[h]);
    sliderSmax->setValue(_calib.colors.at(0).max.rgb[s]);
    sliderVmax->setValue(_calib.colors.at(0).max.rgb[v]);

    connect(sliderHmin, SIGNAL(valueChanged(int)), this, SLOT(updateHmin(int)));
    connect(sliderSmin, SIGNAL(valueChanged(int)), this, SLOT(updateSmin(int)));
    connect(sliderVmin, SIGNAL(valueChanged(int)), this, SLOT(updateVmin(int)));
    connect(sliderHmax, SIGNAL(valueChanged(int)), this, SLOT(updateHmax(int)));
    connect(sliderSmax, SIGNAL(valueChanged(int)), this, SLOT(updateSmax(int)));
    connect(sliderVmax, SIGNAL(valueChanged(int)), this, SLOT(updateVmax(int)));

    updateValuesHSV();
    update_hsv_s();

    lblH->setStyleSheet("QLabel {qproperty-alignment: AlignCenter; font-weight: bold;}");
    lblS->setStyleSheet("QLabel {qproperty-alignment: AlignCenter; font-weight: bold;}");
    lblV->setStyleSheet("QLabel {qproperty-alignment: AlignCenter; font-weight: bold;}");

    sliderHmax->setStyleSheet("QSlider{ background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0.0 #00f, stop: 0.167 #f0f, stop: 0.334 #f00, stop: 0.501 #ff0, stop: 0.668 #0f0, stop: 0.835 #0ff, stop: 1.0 #00f)}");
    sliderHmin->setStyleSheet("QSlider{ background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0.0 #00f, stop: 0.167 #f0f, stop: 0.334 #f00, stop: 0.501 #ff0, stop: 0.668 #0f0, stop: 0.835 #0ff, stop: 1.0 #00f)}");

    sliderSmin->setStyleSheet(hsv_s.c_str());
    sliderSmax->setStyleSheet(hsv_s.c_str());

    sliderVmin->setStyleSheet("QSlider{ background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #fff, stop: 1 #000)}");
    sliderVmax->setStyleSheet("QSlider{ background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #fff, stop: 1 #000)}");

    ui->layoutH3->setContentsMargins(2, 0, 2, 0);
    ui->layoutH4->setContentsMargins(2, 0, 2, 0);
    ui->layoutH5->setContentsMargins(2, 0, 2, 0);
    ui->layoutH6->setContentsMargins(2, 0, 2, 0);
    ui->layoutH7->setContentsMargins(2, 0, 2, 0);
    ui->layoutH8->setContentsMargins(2, 0, 2, 0);
    ui->layoutH9->setContentsMargins(2, 0, 2, 0);
    ui->layoutH10->setContentsMargins(2, 0, 2, 0);
}