예제 #1
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);
}
예제 #2
0
PropsDemo::PropsDemo(HINSTANCE hInstance, std::string winCaption, D3DDEVTYPE devType, DWORD requestedVP)
: D3DApp(hInstance, winCaption, devType, requestedVP)
{
	if(!checkDeviceCaps())
	{
		MessageBox(0, "checkDeviceCaps() Failed", 0, 0);
		PostQuitMessage(0);
	}

	InitAllVertexDeclarations();

	mTime = 0.0f;

	mGfxStats = new GfxStats();

	// Set path to art resources.
	SetCurrentDirectory("Art/");

	// World space units are meters.  
	mTerrain = new Terrain(257, 257, 2.0f, 2.0f, 
		"castlehm257.raw", "grass.dds",	"dirt.dds",	
		"rock.dds", "blend_castle.dds", 0.5f, 0.0f);

	D3DXVECTOR3 toSun(-1.0f, 3.0f, 1.0f);
	D3DXVec3Normalize(&toSun, &toSun);
	mTerrain->setDirToSunW(toSun);

	// Setup water.
	D3DXMATRIX waterWorld;
	D3DXMatrixTranslation(&waterWorld, 8.0f, 35.0f, -80.0f);
	mWater = new Water(33, 33, 20, 20, waterWorld);

	// Initialize camera.
	gCamera->pos() = D3DXVECTOR3(8.0f, 35.0f, -100.0f);
	gCamera->setSpeed(20.0f);
	mFreeCamera = false;

	buildCastle();
	buildTrees();
	buildGrass();

	HR(D3DXCreateTextureFromFile(gd3dDevice, "grassfin0.dds", &mGrassTex));
	HR(D3DXCreateTextureFromFile(gd3dDevice, "whitetex.dds", &mWhiteTex));

	buildFX();

	mLight.dirW    = -toSun;
	D3DXVec3Normalize(&mLight.dirW, &mLight.dirW);
	mLight.ambient = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);
	mLight.diffuse = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);
	mLight.spec    = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);
	HR(mFX->SetValue(mhLight, &mLight, sizeof(DirLight)));
	HR(mGrassFX->SetValue(mhGrassDirToSunW, &(-mLight.dirW), sizeof(D3DXVECTOR3)));

	mGfxStats->addVertices(mTerrain->getNumVertices());
	mGfxStats->addTriangles(mTerrain->getNumTriangles());
	mGfxStats->addVertices(mWater->getNumVertices());
	mGfxStats->addTriangles(mWater->getNumTriangles());
	mGfxStats->addVertices(mCastle.mesh->GetNumVertices());
	mGfxStats->addTriangles(mCastle.mesh->GetNumFaces());
	mGfxStats->addVertices(mTrees[0].mesh->GetNumVertices()*NUM_TREES/4);
	mGfxStats->addTriangles(mTrees[0].mesh->GetNumFaces()*NUM_TREES/4);
	mGfxStats->addVertices(mTrees[1].mesh->GetNumVertices()*NUM_TREES/4);
	mGfxStats->addTriangles(mTrees[1].mesh->GetNumFaces()*NUM_TREES/4);
	mGfxStats->addVertices(mTrees[2].mesh->GetNumVertices()*NUM_TREES/4);
	mGfxStats->addTriangles(mTrees[2].mesh->GetNumFaces()*NUM_TREES/4);
	mGfxStats->addVertices(mTrees[3].mesh->GetNumVertices()*NUM_TREES/4);
	mGfxStats->addTriangles(mTrees[3].mesh->GetNumFaces()*NUM_TREES/4);
	mGfxStats->addVertices(mGrassMesh->GetNumVertices());
	mGfxStats->addTriangles(mGrassMesh->GetNumFaces());

	onResetDevice();
}