Exemple #1
0
bool VGAWorker::takePicture() {
    // Reset connection with VGA2USB. Needed to handle VGA disconnections and grab
    // complete VGA images
    if(camera.isOpened())
        camera.release();
    camera.open(deviceNum);
    // Get the next screen if the image feed is available
    if(camera.isOpened() && camera.get(CV_CAP_PROP_FRAME_WIDTH) != 0) {
        // Update old screen
        if(oldScreen.data)
            oldScreen.release();
        oldScreen = currentScreen.clone();
        // Save current screen
        camera >> currentScreen;
        // Flip the image horizontally and vertically if the camera is upside-down
        if(flipCam) {
            flip(currentScreen, currentScreen, -1);
        }
        // Let listeners know that an image was captured
        if(runningGUI)
            emit capturedImage(currentScreen);
        // Capture was successful, so return true
        return true;
    }
    // We could not pull a frame from the VGA2USB, so return false
    return false;
}
Exemple #2
0
void DC1394Camera::update(double timestep)
{
    dc1394video_frame_t* frame = 0;
    dc1394error_t err = DC1394_FAILURE;
    
    // Grab a frame
    LOGGER.debugStream() << m_guid << ": Grabbing frame " << ++m_frameNum;
    err = dc1394_capture_dequeue(m_camera, DC1394_CAPTURE_POLICY_WAIT, &frame);
    assert(DC1394_SUCCESS == err && "Could not capture a frame\n");

    // See if we have dropped any frames
    if(frame->frames_behind == DMA_BUFFER_SIZE - 1)
    {
        LOGGER.warn("PROBABLE FRAME DROP");
    }
    // Let us know if we are not getting the most recent frame
    LOGGER.debugStream() << m_guid << ": Frame Position: " << frame->id 
                         << " Frames Behind: " << frame->frames_behind
                         << " DMA Buffers: " << DMA_BUFFER_SIZE
                         << " DMA Timestamp: " << frame->timestamp;

    // Put the DC1394 buffer into a temporary Image so we can copy it
    // to the public side.
    OpenCVImage newImage(frame->image, m_width, m_height,
                         false, Image::PF_RGB_8);

    // Copy image to public side of the interface
    capturedImage(&newImage);

    // Free the space back up on the queue
    LOGGER.debugStream() << m_guid << ": Releasing frame " << m_frameNum;
    err = dc1394_capture_enqueue(m_camera, frame);
    assert(DC1394_SUCCESS == err && "Could not enqueue used frame\n");
}
Exemple #3
0
int main()
{
    // Objects
    CameraInput *camera = new CameraInput();
    Control *controller = new Control();
    Process *processer = new Process();
    Tracking *tracker = new Tracking();
    Serial_Communication *serial = new Serial_Communication("/dev/ttyUSB0", "/dev/ttyUSB1");
//    Serial_Communication *serial = new Serial_Communication("/dev/ttyUSB0");// #### For testing with only one arduino
    File_Handler *file_Handler = new File_Handler();
    Window_Handler *window_Handler = new Window_Handler();
    Menu *menu = new Menu();


    // Threads
    QThread *t1 = new QThread;
    QThread *t2 = new QThread;
    QThread *t3 = new QThread;
    QThread *t4 = new QThread;
    QThread *t5 = new QThread;

    camera->moveToThread(t1);
    processer->moveToThread(t2);
    tracker->moveToThread(t3);
    serial->moveToThread(t3);
    controller->moveToThread(t4);
    file_Handler->moveToThread(t5);

    // Connect signals to slots. Whenever a signal is emitted in a function, its corresponding (connected) function will run.
    qRegisterMetaType<cv::Mat>("cv::Mat");

    //Signals calling from:
    //Main thread
    QObject::connect(menu, SIGNAL(startRecording(bool)), controller, SLOT(startRecording(bool)));
    QObject::connect(menu, SIGNAL(stopRecording()), controller, SLOT(stopRecording()));
    QObject::connect(menu, SIGNAL(displayMenu(cv::Mat)), window_Handler, SLOT(drawImage(cv::Mat)));
    QObject::connect(menu, SIGNAL(requestDataFromFootController()), serial, SLOT(receiveDataFromFootControllerLoop()));
    QObject::connect(menu, SIGNAL(startHighRep()), controller, SLOT(startDelayMode()));
    QObject::connect(menu, SIGNAL(decreaseDelay()), controller, SLOT(decreaseDelay()));
    QObject::connect(menu, SIGNAL(increaseDelay()), controller, SLOT(increaseDelay()));
    QObject::connect(menu, SIGNAL(modeSwitch()), controller, SLOT(endMode()));
    QObject::connect(menu, SIGNAL(startPlayback()), file_Handler, SLOT(readFromFile()));
    QObject::connect(menu, SIGNAL(stopPlayback()), file_Handler, SLOT(stopVideo()));
    QObject::connect(menu, SIGNAL(toggleSlowMotion()), file_Handler, SLOT(toggleSlowMotion()));
    QObject::connect(menu, SIGNAL(toggleTracking()), controller, SLOT(toggleTracking()));

    //Thread 1
    QObject::connect(t1, SIGNAL(started()), camera, SLOT(captureImage()));
    QObject::connect(camera, SIGNAL(capturedImage(cv::Mat)), controller, SLOT(inputImage(cv::Mat)));

    //Thread 2
    QObject::connect(t2, SIGNAL(started()), controller, SLOT(processerReady()));
    QObject::connect(processer, SIGNAL(posXposY(int,int)), tracker, SLOT(position(int,int)));
    QObject::connect(processer, SIGNAL(readyForWork()), controller, SLOT(processerReady()));

    //Thread 3
    QObject::connect(tracker, SIGNAL(directionAndSpeed(int,int)), serial, SLOT(sendDataToControlUnit(int,int)));
    QObject::connect(serial, SIGNAL(fromFootController(char)), menu, SLOT(giveInput(char)));

    //Thread 4
    QObject::connect(t4, SIGNAL(started()), controller, SLOT(fileHandlerReadyToWrite()));
    QObject::connect(controller, SIGNAL(imageToProcess(cv::Mat)), processer, SLOT(processImage(cv::Mat)));
    QObject::connect(controller, SIGNAL(requestImage()), camera, SLOT(captureImage()));
    QObject::connect(controller, SIGNAL(imageToRecord(cv::Mat)), file_Handler, SLOT(writeImage(cv::Mat)));
//    QObject::connect(controller, SIGNAL(imageToShow(cv::Mat)), window_Handler, SLOT(drawImage(cv::Mat)));
    QObject::connect(processer, SIGNAL(processedImage(cv::Mat)), window_Handler, SLOT(drawImage(cv::Mat)));
    QObject::connect(controller, SIGNAL(stopMotor()), serial, SLOT(stopMotor()));

    //Thread 5
    QObject::connect(file_Handler, SIGNAL(showFrame(cv::Mat)), window_Handler, SLOT(drawImage(cv::Mat)));
    QObject::connect(file_Handler, SIGNAL(readyToWrite()), controller, SLOT(fileHandlerReadyToWrite()));
    QObject::connect(file_Handler, SIGNAL(timeout()), file_Handler, SLOT(playVideo()));
    QObject::connect(file_Handler, SIGNAL(playbackEnded()), menu, SLOT(returnToLowRep()));

    // Starting Threads
    t1->start();
    t2->start();
    t3->start();
    t4->start();
    t5->start();

//    menu->menu();
    menu->inputHandler();
    return 0;
}