예제 #1
0
int main(){
    unsigned char buffer[BUF_SIZE] = {0};
    unsigned int picSize=0;
    unsigned int packNum=0;
    unsigned int packSize;
    unsigned short int checksum;
    unsigned int width, height;
    unsigned int i,j;
    unsigned char bytes[2];
    unsigned char image[160][120];

    int  fd = serialOpen("/dev/ttyUSB1", 115200);
    FILE* filefd = fopen("./image.ppm", "w");
    unsigned char* bufptr;

    sendShot(fd, RES_160X128);
    readImageDetails(fd, &picSize, &packNum);
    printf("size: %d\npackets count: %d\n", picSize, packNum);
    unsigned char* imgBuffer = (unsigned char*) malloc((picSize+1)*sizeof(unsigned char));
    readImage(fd, imgBuffer, picSize, packNum); 
    serialClose(fd);
    njInit();
    if (njDecode(imgBuffer, picSize)) {
        printf("Error decoding the input file.\n");
        return 1;
    }
    printf("size:\n%d %d\n", njGetWidth(), njGetHeight());
    fprintf(filefd, "P%d\n%d %d\n255\n", njIsColor() ? 6 : 5, njGetWidth(), njGetHeight());
    width = njGetWidth();
    height = njGetHeight();
    fwrite(njGetImage(), 1, njGetImageSize(), filefd);
    bufptr = njGetImage();
    for(i=0;i<width;i++){
        for(j=0;j<height;j++){
            image[i][j] = (char)((0.21 * (double)bufptr[(i+j*width)*3]) + 0.72 * (double)bufptr[(i+j*width)*3 + 1]  + 0.07 * (double)bufptr[(i+j*width)*3 + 2]);
        }
    }
    for(j=0;j<height;j++){
        for(i=0;i<width;i++){
            if(image[i][j]<63)
                printf("@");
            else if(image[i][j]<128)
                printf("*");
            else if(image[i][j]<191)
                printf("+");
            else
                printf("-");
        }
        printf("\n");
    }   
    fclose(filefd);
    njDone();
}
예제 #2
0
파일: mainwindow.cpp 프로젝트: riless/smoky
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent)
{

    setCentralWidget(new QWidget);
    QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
    layout->setContentsMargins(0,0,0,0);
    layout->setSpacing(0);

    layout->addWidget( ui.header = new Header( this ) );
    connect( &Socket::sock(), SIGNAL(userLoggedIn(QString)), ui.header, SLOT(onUserConnected(QString)) );
    connect( &Socket::sock(), SIGNAL(userLoggedOut()), ui.header, SLOT(onUserDisconnected()) );
    connect( ui.header, SIGNAL(disconnectClicked()), &Socket::sock(), SLOT(logout()) );
    // mettre obligatoirement ici pour corriger un petit bug d'affichage

//    /*temp refresh button*/
//    QPushButton *refreshBtn = new QPushButton( "Refresh" );
//    refreshBtn->setObjectName( "refreshBtn" );
//    mainLayout->addWidget( refreshBtn );
//    connect(refreshBtn, SIGNAL(clicked()), ui.header, SLOT( onRefreshClicked() ) );

    QHBoxLayout* centralLayout = new QHBoxLayout( );
    centralLayout->addWidget( ui.sideBar = new SideBar( this ) );
    centralLayout->addWidget( ui.stackedWidget = new StackedWidget( this ) );

    layout->addLayout( centralLayout );

    connect(ui.sideBar, SIGNAL( currentChanged( int ) ), ui.stackedWidget, SLOT( setCurrentIndex( int ) ) );
    connect(ui.sideBar, SIGNAL( currentChanged( int ) ), SLOT( loadViewData( int ) ) );


    // LOG
    connect( &Socket::sock(), SIGNAL(clientEvent(int)), &Socket::sock(), SLOT(log(int)) );


    // LIGHT BOX
    lightBox = new QLightBoxWidget(this);
    QHBoxLayout *mainLayout = new QHBoxLayout( lightBox );

    QWidget *fm = new QWidget();
    fm->setObjectName("connexionFrame");
    mainLayout->addWidget( fm );

    QGridLayout *lightBoxLayout = new QGridLayout( fm );
    lightBoxLayout->setRowStretch(1, 1);

    settings = new QSettings("smoky.ini",QSettings::IniFormat);


    lightBoxLayout->addWidget( new QLabel( "IP du serveur" ), 0, 0);
    lightBoxLayout->addWidget( serverIpEdt = new QLineEdit(), 0, 1 );
    serverIpEdt->setInputMask( "000.000.000.000; " );
    serverIpEdt->setText( settings->value("serverIp").toString() );
    serverIpEdt->setObjectName( "serverIpEdt" );

    lightBoxLayout->addWidget( localhostCbx = new QCheckBox("localhost"), 1,1);
    localhostCbx->setObjectName( "localhostCbx" );
    connect( localhostCbx, SIGNAL( stateChanged(int)), SLOT(onLocalhostCbx(int)) );

    lightBoxLayout->addWidget( loginIndication = new QLabel(), 1, 0);
    loginIndication->setObjectName( "loginIndication" );
    loginIndication->setText("<center><small>Placez votre visage<br>face à la caméra</small></center>");

    lightBoxLayout->addWidget( loginAvatarLbl = new QLabel(""), 2, 0, 2, 1);
    loginAvatarLbl->setObjectName( "loginAvatarLbl" );

    lightBoxLayout->addWidget( loginUserEdt = new QLineEdit(), 2, 1);
    loginUserEdt->setPlaceholderText("Nom d'utilisateur");
    loginUserEdt->setObjectName( "loginUserEdt" );

    lightBoxLayout->addWidget( loginPasswordEdt = new QLineEdit(), 3, 1);
    loginPasswordEdt->setObjectName( "loginPasswordEdt" );
    loginPasswordEdt->setEchoMode( QLineEdit::Password );
    loginPasswordEdt->setPlaceholderText("Mot de passe");


    lightBoxLayout->addWidget( loginSubmitBtn = new QPushButton("Connexion"), 4, 1);
    loginSubmitBtn->setObjectName( "loginSubmitBtn" );

    lightBoxLayout->addWidget( statLbl = new QLabel( "" ), 5,0, 1, 2 );
    statLbl->setObjectName( "statLbl" );

    lightBox->show();



    Camera *cam = new Camera();
    t = new QThread();

    mTimer = new QTimer();
    mTimer->setInterval(1000/24);
    connect(mTimer, SIGNAL(timeout()), cam, SLOT(queryFrame()) );
    connect( this, SIGNAL(startWork()), cam, SLOT(openCamera()) );
    connect( this, SIGNAL(startWork()), mTimer, SLOT(start()) );

    connect( cam, SIGNAL(stopCamera()), mTimer, SLOT(stop()) );
    connect( this, SIGNAL(stopWork()), cam, SLOT(closeCamera()) );

    /*destruction*/
    // connect( qApp, SIGNAL(aboutToQuit()),mTimer, SLOT(stop()) );
    // connect( qApp, SIGNAL(aboutToQuit()),mTimer, SLOT(deleteLater()) );

    // connect( qApp, SIGNAL(aboutToQuit()), cam, SLOT(closeCamera()) );
    // connect( qApp, SIGNAL(aboutToQuit()), cam, SLOT(deleteLater()) );

    connect(t, SIGNAL(finished()), cam, SLOT(deleteLater()));
    // connect(this, &Controller::operate, worker, &Worker::doWork);

    //connect( qApp, SIGNAL(aboutToQuit()), t, SLOT(quit()) );
    // connect( t, SIGNAL(finished()), t, SLOT(deleteLater()) );

    // user logged out
    connect( &Socket::sock(), SIGNAL(userLoggedOut()), SLOT(startCamera()) );

    // user logged in
    connect( &Socket::sock(), SIGNAL(userLoggedIn(QString)), SLOT(stopCamera()) );

    cam->moveToThread( t );
    mTimer->moveToThread( t );
    t->start( QThread::IdlePriority );

    emit startWork();

    connect(cam, SIGNAL(sendShot(QImage, QRect)), SLOT(onShotSent(QImage)) ); // receive shots

    connect( &Socket::sock(), SIGNAL(userLoggedIn(QString)), loginPasswordEdt, SLOT(clear()) );
    connect( &Socket::sock(), SIGNAL(userLoggedIn(QString)), lightBox, SLOT(hide()) );

    // rendre la page d'accueil
    connect( &Socket::sock(), SIGNAL(userLoggedOut()), SLOT(resetThings()) );

    connect( &Socket::sock(), SIGNAL(invalidCred()), SLOT(onInvalidCred()) );

    connect( loginSubmitBtn, SIGNAL(clicked()), SLOT(connectUser()) );


    connect( &Socket::sock(), SIGNAL(connexionError(int)), SLOT(onConnexionError(int)) );

    // move(QApplication::desktop()->screen()->rect().center() - this->rect().center());
    /*
        QDesktopWidget desktop;
        QRect desktop_geometry = desktop.screenGeometry();
    */

    // resize( 780, 650 );

    /*int x = desktop_geometry.width()/2 - width()/2;
    int y = desktop_geometry.height()/2 - height()/2;
    move( x, y );*/

    // showMaximized();
}