コード例 #1
0
void Camera::captureFrame() {

    cv::Mat distortedFrame(camFrameHeight, camFrameWidth, CV_8UC1);
    imgIdx = (imgIdx+1) % 8;

    if (testMode) {
        distortedFrame = testImages[imgIdx].clone();
        /* faking camera image acquisition time */
        eventLoopTimer->setInterval(1000/FRAME_RATE);
    } else {
        dc1394video_frame_t *frame = NULL;
        error = dc1394_capture_dequeue(camera, DC1394_CAPTURE_POLICY_WAIT, &frame);
        distortedFrame.data = frame->image;
        dc1394_capture_enqueue(camera, frame);
    }
    
    /* undistort camera image */
    cv::Mat camFrame(camFrameHeight, camFrameWidth, CV_8UC1);
    undistortLUT(distortedFrame, camFrame);
    
    /* display original frame with ambient light in camera widget */
    cv::Rect cropped((camFrame.cols-width)/2, (camFrame.rows-height)/2, width, height);
    emit newCamFrame(camFrame(cropped).clone());
    
    /* remove ambient light */
    camFrame -= ambientImage;
    
    /* cropping image in center to power-of-2 size */
    cv::Mat croppedFrame = camFrame(cropped).clone();

    /* assigning image id (current active LED) to pixel in 0,0 */
    croppedFrame.at<uchar>(0, 0) = imgIdx;
    
    emit newCroppedFrame(croppedFrame);
}
コード例 #2
0
/// \brief A utility routine to obtain a quaternion from a rotation matrix.
vtkQuaternionf vesKiwiCameraTransition::currentOrientation() const
{
  vesMatrix3x3f camFrame =
    makeNormalMatrix3x3f(this->mCamera->computeViewTransform());
  float tmp[3][3];
  for (int i = 0; i < 3; ++i)
    for (int j = 0; j < 3; ++j)
      tmp[i][j] = camFrame(j,i);
  vtkQuaternionf orientation;
  orientation.FromMatrix3x3(tmp);
  return orientation;
}
コード例 #3
0
void FrameRenderSystem::update(ent_ptr<EntityManager> em, ent_ptr<EventManager> events, double dt)
{
	for (auto camEntity : em->entities_with_components<CameraComponent, FrameComponent>()) {
		auto camc = camEntity.component<CameraComponent>();
		auto cfc  = camEntity.component<FrameComponent>();
		auto cpoc = camEntity.component<PosOrientComponent>();
		SDL_assert(cpoc);

		//make a temporary camera frame
		std::unique_ptr<Frame> camFrame(new Frame(cfc->frame, "camera", Frame::FLAG_ROTATING));
		camFrame->SetOrient(cpoc->orient, p3::game->GetSim()->GetGameTime());
		camFrame->SetPosition(cpoc->pos);
		//update root relative pos & interpolate
		camFrame->ClearMovement();
		camFrame->UpdateInterpTransform(1.0);

		//set up star light source(s)
		for (auto lightEntity : em->entities_with_components<LightComponent, FrameComponent>()) {
			auto lc  = lightEntity.component<LightComponent>();
            auto lfc = lightEntity.component<FrameComponent>();
            vector3d lpos = lfc->frame->GetPositionRelTo(camFrame.get());
			const double dist = lpos.Length() / AU;
			lpos *= 1.0/dist; // normalize
            lc->light.SetPosition(vector3f(lpos.x, lpos.y, lpos.z));
            scene->AddLight(&lc->light);
		}

		//copy view transform to each graphic
		//they will be sorted later
		for (auto drawEntity : em->entities_with_components<GraphicComponent, FrameComponent>()) {
			auto efc  = drawEntity.component<FrameComponent>();
			auto egc  = drawEntity.component<GraphicComponent>();
			auto epoc = drawEntity.component<PosOrientComponent>();
			SDL_assert(epoc);
			matrix4x4d viewTransform;
			Frame::GetFrameTransform(efc->frame, camFrame.get(), egc->graphic->viewTransform);

			//vector3d viewCoords = viewTransform * epoc->pos; //should be interp pos
		}

		scene->Render(camc->camera.get());

		cfc->frame->RemoveChild(camFrame.get());
	}
}
コード例 #4
0
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    this->setStyleSheet("background:lightGray;");


    QApplication::setApplicationName("Face Recognizer");
    ui->centralLayout->setContentsMargins(0, 0, 0, 0);
    ui->addPageLayout->setContentsMargins(0, 0, 0, 0);
    ui->searchLayout->setContentsMargins(0, 0, 0, 0);
    ui->mainPageLayout->setContentsMargins(0, 0, 0, 0);
    ui->verticalLayout->setContentsMargins(0, 0, 0, 0);
    ui->imagesLayout->setContentsMargins(0, 0, 0, 0);

    /**
     * Action bar
     */

    ui->actionBarLayout->setMargin(0);
    ui->actionBarLayout->setSizeConstraint(QLayout::SetNoConstraint);

    actionBar = new AndroidActionBar(this);
    ui->actionBarLayout->addWidget(actionBar);

    searchLine = new SearchLineEdit(this);
    QMenu *menu = new QMenu(this);
    QWidgetAction *searchBoxAction = new QWidgetAction(this);
    searchBoxAction->setDefaultWidget(searchLine);
    menu->addAction(searchBoxAction);

    QAction *searchAction = new QAction(QIcon(":icons/search"), "Search", this);
    actionBar->addButton(searchAction, menu);

    QAction *settingsAction = new QAction(QIcon(":icons/settings"), "Settings", this);
    actionBar->addButton(settingsAction);

    QAction *addAction = new QAction(QIcon(":icons/add"), "Add Person", this);
    actionBar->addNavigation(addAction);

    QAction *deleteAction = new QAction(QIcon(":icons/discard"), "Delete Person", this);
    actionBar->addNavigation(deleteAction);

    QAction *menuSearchAction = new QAction(QIcon(":icons/search"), "Find Person", this);
    actionBar->addNavigation(menuSearchAction);

    QAction *helpAction = new QAction(QIcon(":icons/help"), "Help", this);
    actionBar->addNavigation(helpAction);

    actionBar->addSeparator(helpAction);

    actionBar->setTitle("Face Recognizer", false);

    //Connect signals for the navigation bar
    connect(actionBar, &AndroidActionBar::up, this, &MainWindow::actionMain);
    connect(menuSearchAction, &QAction::triggered, this, &MainWindow::actionSearch);
    connect(addAction, &QAction::triggered, this, &MainWindow::actionAddPerson);
    connect(deleteAction, &QAction::triggered, this, &MainWindow::actionDeletePerson);
    connect(helpAction, &QAction::triggered, this, &MainWindow::actionHelp);
    connect(settingsAction, &QAction::triggered, this, &MainWindow::actionSettings);

    // Set page as MainPage
    actionMain();

    // Allow QScreen::orientation to trigger orientation changed signal
    screen = QApplication::primaryScreen();
    screen->setOrientationUpdateMask(Qt::PortraitOrientation | Qt::LandscapeOrientation |
                                     Qt::InvertedPortraitOrientation | Qt::InvertedLandscapeOrientation);

    /**
     * Settings page
     */

    ui->verticalLayout->addStretch();
    ui->cameraLayout->addStretch();
    ui->faceDetectionLayout->addStretch();
    ui->faceRecognitionLayout->addStretch();


    /**
     * Add person page
     */

    addFrameLabel = new SelectionWidget(this);
    addFrameLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
    ui->frameLayout->addWidget(addFrameLabel);


    /**
     * Load data set from Sqlite database
     */


//    QFile dfile("assets:/faces_training_set.sqlite"); - for android
//    if (dfile.exists())
//    {
//        dfile.copy("./faces_training_set.sqlite");
//        QFile::setPermissions("./faces_training_set.sqlite", QFile::WriteOwner | QFile::ReadOwner);
//    }

//    facedb = QSqlDatabase::addDatabase("QSQLITE");
//    facedb.setDatabaseName("./faces_training_set.sqlite");

    facedb = QSqlDatabase::addDatabase("QSQLITE");
    facedb.setDatabaseName("../facerecognition/android/assets/faces_training_set.sqlite");

    future = QtConcurrent::run(this, &MainWindow::loadData);


    /**
     * Camera thread
     */

    cam = new Camera(0, 0, 720, 480);
    cameraThread = new QThread;
    cam->moveToThread(cameraThread);

    //Connect camera with attached thread
    connect(cameraThread, SIGNAL(started()), cam, SLOT(start()));
    connect(cam, SIGNAL(stopped()), cameraThread, SLOT(quit()));
    connect(cam, SIGNAL(stopped()), cam, SLOT(deleteLater()));
    connect(cameraThread, SIGNAL(finished()), cameraThread, SLOT(deleteLater()));

    //Connect camera with main thread
    qRegisterMetaType<cv::Mat>("cv::Mat");
    connect(cam, SIGNAL(camFrame(cv::Mat)), this, SLOT(updateFrame(cv::Mat)));

    cameraThread->start();
    cameraThread->setPriority(QThread::TimeCriticalPriority);


    /**
     * Face recognition thread
     */

    faceRecThread = NULL;

    numberImages = 0;

    // Provide search suggestions
    CustomCompleter *completer = new CustomCompleter(names, this);
    completer->setCaseSensitivity(Qt::CaseInsensitive);
    completer->setMaxVisibleItems(5);
    searchLine->setCompleter(completer);
    connect(searchLine, &QLineEdit::returnPressed, this, &MainWindow::openPage);
}