bool IdsSourceSink::GrabFrame(ImagePacket &target, int indexIncrement)
{
    if (indexIncrement<0) qDebug()<<"Cannot stream backwards";

#ifdef Q_OS_WIN32
    if (WaitForSingleObject(hEvent, EVENTTHREAD_WAIT_TIMEOUT) == WAIT_OBJECT_0) {
#else
    if (is_WaitEvent (hCam, IS_SET_EVENT_FRAME, camTimeStep*5) == IS_SUCCESS) {
#endif
        void *pMemVoid; //pointer to where the image is stored  **********************
        is_GetImageMem (hCam, &pMemVoid);
        buffer.data =  (unsigned char*)pMemVoid;
        is_GetImageInfo( hCam, memId, &ImageInfo, sizeof(ImageInfo)); //Get info ASAP in case of an interruption due to a click
        target.image=buffer.clone();

        if (camTimeOffset==0) {
            camTimeOffset=3600000*ImageInfo.TimestampSystem.wHour+60000*ImageInfo.TimestampSystem.wMinute+1000.0*ImageInfo.TimestampSystem.wSecond+ImageInfo.TimestampSystem.wMilliseconds;
            target.timeStamp=0;
        } else {
            double tis;
            tis=3600000*ImageInfo.TimestampSystem.wHour+60000*ImageInfo.TimestampSystem.wMinute+1000.0*ImageInfo.TimestampSystem.wSecond+ImageInfo.TimestampSystem.wMilliseconds-camTimeOffset;
            target.timeStamp=tis;
        }
        target.seqNumber=ImageInfo.u64FrameNumber;

        target.pixFormat="MONO8";

    }

    return true;

}


bool IdsSourceSink::StopAcquisition() {
    is_StopLiveVideo(hCam, IS_WAIT);
    is_DisableEvent (hCam, IS_SET_EVENT_FRAME); //added by Sam
#ifdef Q_OS_WIN32
    is_ExitEvent(hCam, hEvent);
#endif
    is_FreeImageMem (hCam, imgMem, memId);
    Sleeper::msleep(10*camTimeStep); // NEEDS some sleep to stop all internal events
    return true;
}
Exemple #2
0
void UEyeCaptureInterface::SpinThread::run()
{
    qDebug("new frame thread running");
    while (capInterface->spinRunning.tryLock()) {

    	//usleep(20000);
        if (capInterface->sync == SOFT_SYNC || capInterface->sync == FRAME_HARD_SYNC) {
    	   // printf("Both cameras fire!!!\n");
            ueyeTrace(is_FreezeVideo (capInterface->rightCamera.mCamera, IS_DONT_WAIT));
            ueyeTrace(is_FreezeVideo (capInterface->leftCamera .mCamera, IS_DONT_WAIT));
        }

        int result = IS_SUCCESS;

        while ((result = capInterface->rightCamera.waitUEyeFrameEvent(INFINITE)) != IS_SUCCESS)
        {
            SYNC_PRINT(("WaitFrameEvent failed for right camera\n"));
            ueyeTrace(result);
        }
        //SYNC_PRINT(("Got right frame\n"));

        while ((result = capInterface->leftCamera .waitUEyeFrameEvent(INFINITE)) != IS_SUCCESS)
        {
            SYNC_PRINT(("WaitFrameEvent failed for left camera\n"));
            ueyeTrace(result);
        }
        //SYNC_PRINT(("Got left frame\n"));


        /* If we are here seems like both new cameras produced frames*/

        int bufIDL, bufIDR;
        char *rawBufferLeft  = NULL;
        char *rawBufferRight = NULL;
        HIDS mCameraLeft;
        HIDS mCameraRight;

        mCameraLeft = capInterface->leftCamera.mCamera;
        is_GetActSeqBuf(mCameraLeft, &bufIDL, NULL, &rawBufferLeft);
        is_LockSeqBuf (mCameraLeft, IS_IGNORE_PARAMETER, rawBufferLeft);
        mCameraRight = capInterface->rightCamera.mCamera;
        is_GetActSeqBuf(mCameraRight, &bufIDR, NULL, &rawBufferRight);
        is_LockSeqBuf (mCameraRight, IS_IGNORE_PARAMETER, rawBufferRight);

       // SYNC_PRINT(("We have locked buffers [%d and %d]\n", bufIDL, bufIDR));

        /* Now exchange the buffer that is visible from */
        capInterface->protectFrame.lock();
            UEYEIMAGEINFO imageInfo;

            if (capInterface->currentLeft)
                is_UnlockSeqBuf (mCameraLeft, IS_IGNORE_PARAMETER, (char *)capInterface->currentLeft->buffer);
            is_GetImageInfo (mCameraLeft, bufIDL, &imageInfo, sizeof(UEYEIMAGEINFO));
            capInterface->currentLeft = capInterface->leftCamera.getDescriptorByAddress(rawBufferLeft);
            capInterface->currentLeft->internalTimestamp = imageInfo.u64TimestampDevice;
            capInterface->currentLeft->pcTimestamp = imageInfo.TimestampSystem;

            if (capInterface->currentRight)
                is_UnlockSeqBuf (mCameraRight, IS_IGNORE_PARAMETER, (char *)capInterface->currentRight->buffer);
            is_GetImageInfo (mCameraRight, bufIDR, &imageInfo, sizeof(UEYEIMAGEINFO));
            capInterface->currentRight = capInterface->rightCamera.getDescriptorByAddress(rawBufferRight);
            capInterface->currentRight->internalTimestamp = imageInfo.u64TimestampDevice;
            capInterface->currentRight->pcTimestamp = imageInfo.TimestampSystem;

            capInterface->skippedCount++;

            capInterface->triggerSkippedCount = is_CameraStatus (mCameraRight, IS_TRIGGER_MISSED, IS_GET_STATUS);
        capInterface->protectFrame.unlock();
       /* For statistics */
        if (capInterface->lastFrameTime.usecsTo(PreciseTimer()) != 0)
        {
           capInterface->frameDelay = capInterface->lastFrameTime.usecsToNow();
        }
        capInterface->lastFrameTime = PreciseTimer::currentTime();



        frame_data_t frameData;
        frameData.timestamp = (capInterface->currentLeft->usecsTimeStamp() / 2) + (capInterface->currentRight->usecsTimeStamp() / 2);
        capInterface->notifyAboutNewFrame(frameData);

        capInterface->spinRunning.unlock();
        if (capInterface->shouldStopSpinThread)
        {
            qDebug("Break command received");

            break;
        }
    }
    qDebug("new frame thread finished");
}