Beispiel #1
0
void mouse_qlabel::mouseMoveEvent(QMouseEvent *ev)
{
    this->x = ev->x();
    this->y = ev->y();
    emit Mouse_Pos();

}
ImageWindows::ImageWindows(QImage image, QString name, QWidget *parent) :
    QWidget(parent),
    ui(new Ui::ImageWindows)
{
    ui->setupUi(this);

    imageLbl=new qlabel_image();

    //Signal émit par la class qlabel_image pour la lecture en dynamique de la position des pixels
    connect(imageLbl, SIGNAL(Mouse_Pos()), this, SLOT(Mouse_current_pos()));
    connect(imageLbl, SIGNAL(Mouse_Pressed()), this, SLOT(Mouse_pressed()));
    connect(imageLbl, SIGNAL(Mouse_ClickLeft()), this, SLOT(MouseClickLeft()));
    connect(imageLbl, SIGNAL(Mouse_ReleasePos()), this, SLOT(Mouse_release_pos()));
    imageLbl->setMouseTracking(true);

   // setFixedHeight(image.height());
   // setFixedWidth(image.width());
    image_ihm = image;
    m_coeffZoom=1;
    affichageImage(image_ihm,m_coeffZoom,ui->scrollArea_Image);
     /*QLabel *imageLabel = new QLabel;
     imageLabel->setBackgroundRole(QPalette::Base);
     imageLabel->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
     imageLabel->setScaledContents(true);
     imageLabel -> setPixmap(QPixmap::fromImage(image));
     ui->scrollArea_Image->setBackgroundRole(QPalette::Dark);
     ui->scrollArea_Image->setWidget(imageLabel);

*/
    //ui ->label_Image -> setPixmap(QPixmap::fromImage(*image));
    QString txt =  QString::number(image.width())  + " x " + QString::number(image.height());
    ui->lbl_imageSize->setText(txt);

    if(image_ihm.isGrayscale())
        ui->lbl_imageDepth->setText("niveau de gris");
    else
        ui->lbl_imageDepth->setText("couleur");




    /*int index = pathImage.lastIndexOf("/");
    std::cout << "index : " << index;
    m_StrImageName = pathImage.left(index);*/
    m_StrImageName = name;
    setWindowTitle(m_StrImageName);


    QPixmap pixmap("actions/document-save-3.ico");
    QIcon ButtonIcon(pixmap);
    ui->pushB_Save->setIcon(ButtonIcon);
    QSize size = pixmap.rect().size();
    size.setHeight(size.height() -10);
    size.setWidth(size.width() -10);
    ui->pushB_Save->setIconSize(size);


    QPixmap pixmap2("actions/zoom-in-3.ico");
    QIcon ButtonIcon2(pixmap2);
    ui->pushB_ZoomIn->setIcon(ButtonIcon2);
    QSize size1 = pixmap2.rect().size();
    size1.setHeight(size1.height() -10);
    size1.setWidth(size1.width() -10);
    ui->pushB_ZoomIn->setIconSize(size1);


    QPixmap pixmap3("actions/zoom-out-3.ico");
    QIcon ButtonIcon3(pixmap3);
    ui->pushB_ZoomOut->setIcon(ButtonIcon3);
    QSize size2 = pixmap3.rect().size();
    size2.setHeight(size2.height() -10);
    size2.setWidth(size2.width() -10);
    ui->pushB_ZoomOut->setIconSize(size2);



}
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);
}