INT WINAPI Dispose(HIDS* m_hCam) {
	INT result = IS_SUCCESS;
	AFX_MANAGE_STATE(AfxGetStaticModuleState());
	if( m_bRunning && !m_bRecording) {
		// stop rendering thread
		PostThreadMessage(m_renderThread->m_nThreadID, IS_THREAD_MESSAGE, IS_RUNNING, FALSE);
		// wait for thread to terminate
		WaitForSingleObject(m_renderThread->m_hThread, INFINITE);
		// stop video event notification
		result = is_StopLiveVideo( *m_hCam, IS_WAIT );
		// run rendering thread destructor
		delete m_renderThread;
		m_renderThread = NULL;
		// close AVI handle and reset avi instance ID
		if (m_nAviID) {
			isavi_ExitAVI(m_nAviID);
			m_nAviID = 0;
		}
		// Free the allocated buffer
		if( m_pcImageMemory != NULL ) {
			is_FreeImageMem( *m_hCam, m_pcImageMemory, m_lMemoryId );
		}	
		m_pcImageMemory = NULL;
		// Close camera
		result |= is_ExitCamera(*m_hCam );
		m_hCam = NULL;
		m_bRunning = FALSE;
	} else if (m_hCam) {
		// Close camera
		result = is_ExitCamera(*m_hCam );
		m_hCam = NULL;
	}
	return result;
}
INT LoadSettings(HIDS* m_hCam, const wchar_t* settingsFile) {
	INT result = IS_SUCCESS;
	if (settingsFile != NULL && *settingsFile != '\0') {
		TRACE("Loading settings from %s\n", settingsFile);
		result = is_ParameterSet(*m_hCam, IS_PARAMETERSET_CMD_LOAD_FILE, (void*) settingsFile, NULL);
		if (result == IS_SUCCESS) {
			// realloc image mem with actual sizes and depth.
			is_FreeImageMem( *m_hCam, m_pcImageMemory, m_lMemoryId );
			GetImageSize( *m_hCam, m_nSizeX, m_nSizeY); 
			switch( is_SetColorMode( *m_hCam, IS_GET_COLOR_MODE ) )
            {
                case IS_CM_BGRA8_PACKED:
					m_nBitsPerPixel = 32;
					break;
				case IS_CM_BGR8_PACKED:
					m_nBitsPerPixel = 24;
					break;
				case IS_CM_BGR565_PACKED:
				case IS_CM_UYVY_PACKED:
					m_nBitsPerPixel = 16;
					break;
				case IS_CM_BGR5_PACKED:
					m_nBitsPerPixel = 15;
					break;
				case IS_CM_MONO8:
				case IS_CM_SENSOR_RAW8:
				default:
					m_nBitsPerPixel = 8;
					break;
            }  
		}
	}
	return result;
}
///////////////////////////////////////////////////////////////////////////////
//
// METHOD CIdsSimpleLiveDlg::InitDisplayMode() 
//
// DESCRIPTION: - initializes the display mode
//
///////////////////////////////////////////////////////////////////////////////
int InitDisplayMode(HIDS* m_hCam)
{
    INT result = IS_SUCCESS;
    INT		nColorMode;	// Y8/RGB16/RGB24/REG32
    if (m_hCam == NULL) {
		return IS_NO_SUCCESS;
	}
	
	// Get sensor info
	SENSORINFO m_sInfo;			// sensor information struct
	is_GetSensorInfo(*m_hCam, &m_sInfo);

    if (m_pcImageMemory != NULL) {
        is_FreeImageMem( *m_hCam, m_pcImageMemory, m_lMemoryId );
    }
    m_pcImageMemory = NULL;

	// Set display mode to DIB
    result = is_SetDisplayMode(*m_hCam, IS_SET_DM_DIB);
	if (m_sInfo.nColorMode == IS_COLORMODE_BAYER) {
		// setup the color depth to the current windows setting
        is_GetColorDepth(*m_hCam, &m_nBitsPerPixel, &nColorMode);
    } else if (m_sInfo.nColorMode == IS_COLORMODE_CBYCRY) {
        // for color camera models use RGB32 mode
        nColorMode = IS_CM_RGB8_PACKED;
        m_nBitsPerPixel = 32;
    } else {
        // for monochrome camera models use Y8 mode
        nColorMode = IS_CM_MONO8;
        m_nBitsPerPixel = 8;
    }

    // allocate an image memory.
    if (is_AllocImageMem(*m_hCam, m_nSizeX, m_nSizeY, m_nBitsPerPixel, &m_pcImageMemory, &m_lMemoryId ) != IS_SUCCESS) {
        AfxMessageBox(TEXT("Memory allocation failed!"), MB_ICONWARNING );
    } else {
		is_SetImageMem( *m_hCam, m_pcImageMemory, m_lMemoryId );
	}

    if (result == IS_SUCCESS) {
        // set the desired color mode
        result = is_SetColorMode(*m_hCam, nColorMode);
		// Sets the position and size of the image by using an object of the IS_RECT type.
		IS_RECT rectAOI;
		rectAOI.s32X     = 0;
		rectAOI.s32Y     = 0;
		rectAOI.s32Width = m_nSizeX;
		rectAOI.s32Height = m_nSizeY;
		result |= is_AOI(*m_hCam, IS_AOI_IMAGE_SET_AOI, (void*)&rectAOI, sizeof(rectAOI));
    }   
    return result;
}
Beispiel #4
0
int CameraApi::closeCamera()
{
	for(int i=0; i<ringbufferSize; i++)
	{
		is_FreeImageMem(mhCam, ringbuffer[i], ringbufferId[i]);
	}

	delete ringbuffer;
	delete ringbufferId;

	int isRet = is_ExitCamera(mhCam);

	mhCam = 0;

	return isRet;
}
Beispiel #5
0
//////////////////////////////////////////////////////////////////////////////////
// CloseCamera -------------------------------------------------------------------
//////////////////////////////////////////////////////////////////////////////////
BOOL ofxUeye::CloseCamera(){
	BOOL boRet = FALSE;

    if( m_hCam != 0 )
    {
        is_EnableMessage( m_hCam, IS_FRAME, NULL );
        is_StopLiveVideo( m_hCam, IS_WAIT );
        if( m_pcImageMemory != NULL )
            is_FreeImageMem( m_hCam, m_pcImageMemory, m_nMemoryId );
        m_pcImageMemory = NULL;
        is_ExitCamera( m_hCam );
        m_hCam = NULL;
        boRet = TRUE;
    }

    return boRet;
}
void mexFunction( int nlhs, mxArray *plhs[],int nrhs, const mxArray*prhs[] )
{     
    /* Check for proper number of arguments */
    if (!(nrhs == 2) || !(nlhs==0)) 
    {   
        mexErrMsgTxt("You have to input camera handle"); 
    }  
    
    if (!mxIsStruct(prhs[1]))
    {
        mexErrMsgTxt("That second input has to be an image structure, you know.");
    }
    int error = 0;
    HCAM hCam = *(HCAM *)mxGetPr(prhs[0]);
    
    int pointer_field = mxGetFieldNumber(prhs[1],"pointer");
    int ID_field = mxGetFieldNumber(prhs[1],"id");
       
    mxArray *ppointer_field = mxGetFieldByNumber(prhs[1],0,pointer_field);
    char *ppImgMem = (char *)*(int *)mxGetPr(ppointer_field);
    mxArray *pID_field = mxGetFieldByNumber(prhs[1],0,ID_field);
    int id = *(int *)mxGetPr(pID_field); 

    if (hCam!= NULL)
	{
		error = is_FreeImageMem(hCam, ppImgMem, id);
		if (error != IS_SUCCESS) 
		{
			mexErrMsgTxt("Error freeing image memory"); 
		}

		//Close and exit camera
		error = is_ExitCamera(hCam );
		if (error != IS_SUCCESS) 
		{
		   mexErrMsgTxt("Error exiting camera"); 
		}
		hCam = NULL;
		ppImgMem = NULL;
//         mexPrintf("Memory freed. \n");
	}
    
    return;   
}
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;
}
INT UEyeCamDriver::disconnectCam() {
    INT is_err = IS_SUCCESS;

    if (isConnected()) {
        setStandbyMode();

        // Release existing camera buffers
        if (cam_buffer_ != NULL) {
            is_err = is_FreeImageMem(cam_handle_, cam_buffer_, cam_buffer_id_);
        }
        cam_buffer_ = NULL;

        // Release camera handle
        is_err = is_ExitCamera(cam_handle_);
        cam_handle_ = (HIDS) 0;

        std::cout << "Disconnected UEye camera '" + cam_name_ + "'" << std::endl;
    }

    return is_err;
}
INT UEyeCamDriver::reallocateCamBuffer() {
    INT is_err = IS_SUCCESS;

    // Stop capture to prevent access to memory buffer
    setStandbyMode();

    if (cam_buffer_ != NULL) {
        is_err = is_FreeImageMem(cam_handle_, cam_buffer_, cam_buffer_id_);
        cam_buffer_ = NULL;
    }
    INT width = cam_aoi_.s32Width /
            (cam_sensor_scaling_rate_ * cam_subsampling_rate_ * cam_binning_rate_);
    INT height = cam_aoi_.s32Height /
            (cam_sensor_scaling_rate_ * cam_subsampling_rate_ * cam_binning_rate_);
    if ((is_err = is_AllocImageMem(cam_handle_, width, height, bits_per_pixel_,
                                   &cam_buffer_, &cam_buffer_id_))
        != IS_SUCCESS) {
        std::cerr << "Failed to allocate " << width << " x " << height
                  << " image buffer" << std::endl;
        return is_err;
    }
    if ((is_err = is_SetImageMem(cam_handle_, cam_buffer_, cam_buffer_id_)) != IS_SUCCESS) {
        std::cerr << "Failed to associate an image buffer to the UEye camera driver" << std::endl;
        return is_err;
    }
    if ((is_err = is_GetImageMemPitch(cam_handle_, &cam_buffer_pitch_)) != IS_SUCCESS) {
        std::cerr << "Failed to query UEye camera buffer's pitch (a.k.a. stride)" << std::endl;
        return is_err;
    }
    cam_buffer_size_ = cam_buffer_pitch_ * height;
    std::cout << "Allocate internal memory - width: " << width << "; height: "
              << height << "; fetched pitch: " << cam_buffer_pitch_
              << "; expected bpp: " << bits_per_pixel_ << "; total size: "
              << cam_buffer_size_ << std::endl;

    return is_err;
}
Beispiel #10
0
//Open our camera
bool IDSCamera::OpenCamera()
{
	if (m_hCam!=0)
	{
        //free old image mem.
        is_FreeImageMem(m_hCam,m_pcImageMemory,m_lMemoryId);
        is_ExitCamera(m_hCam);
    }

    // init camera
    m_hCam = (HIDS) 0;    // open next camera
    m_Ret = is_InitCamera(&m_hCam,NULL);    // init camera
    
    if( m_Ret == IS_SUCCESS ){    
        // retrieve original image size
        SENSORINFO sInfo;
        is_GetSensorInfo(m_hCam,&sInfo);
        m_nSizeX = sInfo.nMaxWidth;
        m_nSizeY = sInfo.nMaxHeight;

        // setup the color depth to the current windows setting
        //is_GetColorDepth(m_hCam,&m_nBitsPerPixel,&m_nColorMode);
        is_SetColorMode(m_hCam, IS_SET_CM_Y8);

        //printf("m_nBitsPerPixel=%i  m_nColorMode=%i\n",m_nBitsPerPixel,IS_SET_CM_Y8);

        // memory initialization
        is_AllocImageMem(m_hCam, m_nSizeX, m_nSizeY, m_nBitsPerPixel, &m_pcImageMemory, &m_lMemoryId);
        //set memory active
        is_SetImageMem( m_hCam, m_pcImageMemory,m_lMemoryId ); 
        // display initialization
        is_SetImageSize( m_hCam, m_nSizeX, m_nSizeY );
        is_SetDisplayMode( m_hCam, IS_SET_DM_DIB);
  // Reinit with slower frame rate for testing on vmWare with USB 1.1        
      if( is_LoadParameters( m_hCam, config_file ) == IS_SUCCESS )
		  {
			  // realloc image mem with actual sizes and depth.
			  is_FreeImageMem( m_hCam, m_pcImageMemory, m_lMemoryId );
			  m_nSizeX = is_SetImageSize( m_hCam, IS_GET_IMAGE_SIZE_X, 0 );
			  m_nSizeY = is_SetImageSize( m_hCam, IS_GET_IMAGE_SIZE_Y, 0 );
			  switch( is_SetColorMode( m_hCam, IS_GET_COLOR_MODE ) )
			  {
			  case IS_SET_CM_RGB32:
				  m_nBitsPerPixel = 32;
				  break;
			  case IS_SET_CM_RGB24:
				  m_nBitsPerPixel = 24;
				  break;
			  case IS_SET_CM_RGB16:
			  case IS_SET_CM_UYVY:
				  m_nBitsPerPixel = 16;
				  break;
			  case IS_SET_CM_RGB15:
				  m_nBitsPerPixel = 15;
				  break;
			  case IS_SET_CM_Y8:
			  case IS_SET_CM_RGB8:
			  case IS_SET_CM_BAYER:
			  default:
				  m_nBitsPerPixel = 8;
				  break;
			  }

			  // memory initialization
			  is_AllocImageMem( m_hCam,
							  m_nSizeX,
							  m_nSizeY,
							  m_nBitsPerPixel,
							  &m_pcImageMemory,
							  &m_lMemoryId);
			  is_SetImageMem(m_hCam, m_pcImageMemory, m_lMemoryId );	// set memory active

			  // display initialization
			  is_SetImageSize(m_hCam, m_nSizeX, m_nSizeY );
		  }
    }
  return true;
}
Beispiel #11
0
//////////////////////////////////////////////////////////////////////////////////
// GetMaxImageSize ---------------------------------------------------------------
//////////////////////////////////////////////////////////////////////////////////
int ofxUeye::InitDisplayMode()
{
    int nRet = IS_NO_SUCCESS;

    if (m_hCam == NULL)
        return IS_NO_SUCCESS;

    // if some image memory exist already then free it
    if (m_pcImageMemory != NULL)
        nRet = is_FreeImageMem (m_hCam, m_pcImageMemory, m_nMemoryId);

    m_pcImageMemory = NULL;

	nRet = is_SetDisplayMode( m_hCam, IS_SET_DM_DIB);
    if(nRet == IS_SUCCESS)
    {
        if( m_si.nColorMode == IS_COLORMODE_BAYER )
        {
           // for color camera models use RGB24 mode
            m_nColorMode = IS_SET_CM_RGB24;
            m_nBitsPerPixel = 24;
			_channels = 3;
			_bitsPerPixel = 24;
        }
        else if( m_si.nColorMode == IS_COLORMODE_CBYCRY )
        {
            // for CBYCRY camera models use RGB32 mode
            m_nColorMode = IS_SET_CM_RGB32;
            m_nBitsPerPixel = 32;
			_channels = 4;
			_bitsPerPixel = 32;
        }
        else
        {
            // for monochrome camera models use Y8 mode
            m_nColorMode = IS_SET_CM_Y8;
            m_nBitsPerPixel = 8;
			_channels = 1;
			_bitsPerPixel = 8;
        }

		_bytesPerPixel = _bitsPerPixel / 8;


        // allocate an image memory.
        nRet = is_AllocImageMem(m_hCam,
            m_nSizeX,
            m_nSizeY,
            m_nBitsPerPixel,
            &m_pcImageMemory,
            &m_nMemoryId );

		_fullPixels = (unsigned char*) malloc(sizeof(unsigned char)*m_nSizeX*m_nSizeY*_channels);
    }


    if(nRet == IS_SUCCESS)
    {
        // set the image memory only for the bitmap mode when allocated
        if(m_pcImageMemory != NULL)
            nRet = is_SetImageMem( m_hCam, m_pcImageMemory, m_nMemoryId );

        // set the desired color mode
        nRet = is_SetColorMode( m_hCam, m_nColorMode );
        // set the image size to capture
		// nRet = is_SetImageSize( m_hCam, m_nSizeX, m_nSizeY );
    }   // end if(nRet == IS_SUCCESS)

    return nRet;
}