////////////////////////////////////////////////////////////////////////////////// // OpenCamera -------------------------------------------------------------------- ////////////////////////////////////////////////////////////////////////////////// BOOL ofxUeye::OpenCamera(int id){ int nRet; m_hCam = (HCAM)id; nRet = InitCamera (&m_hCam, m_hwndDisp); // init camera if( nRet == IS_SUCCESS ) { is_GetCameraInfo( m_hCam, &m_ci); // retrieve original image size is_GetSensorInfo( m_hCam, &m_si); GetMaxImageSize(&m_nSizeX, &m_nSizeY); // setup the bitmap or directdraw display mode nRet = InitDisplayMode(); if(nRet == IS_SUCCESS) { // Enable Messages nRet = is_EnableMessage( m_hCam, IS_DEVICE_REMOVED, m_hwndDisp ); nRet = is_EnableMessage( m_hCam, IS_DEVICE_RECONNECTED, m_hwndDisp ); nRet = is_EnableMessage( m_hCam, IS_FRAME, m_hwndDisp ); } // end if( nRet == IS_SUCCESS ) } // end if( nRet == IS_SUCCESS ) return (nRet == IS_SUCCESS); }
INT UEyeCamDriver::connectCam(int new_cam_ID) { INT is_err = IS_SUCCESS; int numCameras; // Terminate any existing opened cameras setStandbyMode(); // Updates camera ID if specified. if (new_cam_ID >= 0) { cam_id_ = new_cam_ID; } // Query for number of connected cameras if ((is_err = is_GetNumberOfCameras(&numCameras)) != IS_SUCCESS) { std::cerr << "Failed query for number of connected UEye cameras (" << err2str(is_err) << ")" << std::endl; return is_err; } else if (numCameras < 1) { std::cerr << "No UEye cameras are connected" << std::endl; return IS_NO_SUCCESS; } // NOTE: previously checked if ID < numCameras, but turns out that ID can be arbitrary // Attempt to open camera handle, and handle case where camera requires a // mandatory firmware upload cam_handle_ = (HIDS) cam_id_; if ((is_err = is_InitCamera(&cam_handle_, NULL)) == IS_STARTER_FW_UPLOAD_NEEDED) { INT uploadTimeMSEC = 25000; is_GetDuration(cam_handle_, IS_STARTER_FW_UPLOAD, &uploadTimeMSEC); std::cout << "Uploading new firmware to UEye camera '" << cam_name_ << "'; please wait for about " << uploadTimeMSEC / 1000.0 << " seconds" << std::endl; // Attempt to re-open camera handle while triggering automatic firmware upload cam_handle_ = (HIDS) (((INT) cam_handle_) | IS_ALLOW_STARTER_FW_UPLOAD); is_err = is_InitCamera(&cam_handle_, NULL); // Will block for N seconds } if (is_err != IS_SUCCESS) { std::cerr << "Could not open UEye camera ID " << cam_id_ << " (" << err2str(is_err) << ")" << std::endl; return is_err; } // Set display mode to Device Independent Bitmap (DIB) is_err = is_SetDisplayMode(cam_handle_, IS_SET_DM_DIB); // Fetch sensor parameters is_err = is_GetSensorInfo(cam_handle_, &cam_sensor_info_); // Initialize local camera frame buffer reallocateCamBuffer(); return is_err; }
/////////////////////////////////////////////////////////////////////////////// // // 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; }
void GetMaxImageSize(HIDS* m_hCam, INT *pnSizeX, INT *pnSizeY) { // Check if the camera supports an arbitrary AOI INT nAOISupported = 0; BOOL bAOISupported = TRUE; if (is_ImageFormat(*m_hCam, IMGFRMT_CMD_GET_ARBITRARY_AOI_SUPPORTED, (void*)&nAOISupported, sizeof(nAOISupported)) == IS_SUCCESS) { bAOISupported = (nAOISupported != 0); } if (bAOISupported) { // Get maximum image size SENSORINFO sInfo; is_GetSensorInfo (*m_hCam, &sInfo); *pnSizeX = sInfo.nMaxWidth; *pnSizeY = sInfo.nMaxHeight; } else { GetImageSize(*m_hCam, *pnSizeX, *pnSizeY); } }
//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; }
PyObject *ids_core_Camera_getinfo(ids_core_Camera *self, void *closure) { CAMINFO cam_info; SENSORINFO sensor_info; int ret = is_GetCameraInfo(self->handle, &cam_info); if (ret != IS_SUCCESS) { raise_general_error(self, ret); return NULL; } ret = is_GetSensorInfo(self->handle, &sensor_info); if (ret != IS_SUCCESS) { raise_general_error(self, ret); return NULL; } PyObject *dict = PyDict_New(); PyObject *serial_num = PyBytes_FromString(cam_info.SerNo); PyObject *manufacturer = PyBytes_FromString(cam_info.ID); PyObject *hw_version = PyBytes_FromString(cam_info.Version); PyObject *manufacture_date = PyBytes_FromString(cam_info.Date); PyObject *id = Py_BuildValue("B", cam_info.Select); PyObject *sensor_id = Py_BuildValue("H", sensor_info.SensorID); PyObject *sensor_name = PyBytes_FromString(sensor_info.strSensorName); PyObject *max_width = Py_BuildValue("I", sensor_info.nMaxWidth); PyObject *max_height = Py_BuildValue("I", sensor_info.nMaxHeight); PyObject *pixel_size = Py_BuildValue("d", sensor_info.wPixelSize/100.0); PyObject *type; switch (cam_info.Type) { case IS_CAMERA_TYPE_UEYE_USB_SE: type = PyBytes_FromString("USB uEye SE or RE"); break; case IS_CAMERA_TYPE_UEYE_USB_ME: type = PyBytes_FromString("USB uEye ME"); break; case IS_CAMERA_TYPE_UEYE_USB_LE: type = PyBytes_FromString("USB uEye LE"); break; case IS_CAMERA_TYPE_UEYE_USB3_CP: type = PyBytes_FromString("USB 3 uEye CP"); break; case IS_CAMERA_TYPE_UEYE_ETH_HE: type = PyBytes_FromString("GigE uEye HE"); break; case IS_CAMERA_TYPE_UEYE_ETH_SE: type = PyBytes_FromString("GigE uEye SE or RE"); break; case IS_CAMERA_TYPE_UEYE_ETH_LE: type = PyBytes_FromString("GigE uEye LE"); break; case IS_CAMERA_TYPE_UEYE_ETH_CP: type = PyBytes_FromString("GigE uEye CP"); break; default: type = PyBytes_FromString("Unknown"); } PyObject *color_mode; switch (sensor_info.nColorMode) { case IS_COLORMODE_BAYER: color_mode = PyBytes_FromString("Bayer"); break; case IS_COLORMODE_MONOCHROME: color_mode = PyBytes_FromString("Monochrome"); break; case IS_COLORMODE_CBYCRY: color_mode = PyBytes_FromString("CBYCRY"); break; default: color_mode = PyBytes_FromString("Unknown"); } PyDict_SetItemString(dict, "serial_num", serial_num); PyDict_SetItemString(dict, "manufacturer", manufacturer); PyDict_SetItemString(dict, "hw_version", hw_version); PyDict_SetItemString(dict, "manufacture_date", manufacture_date); PyDict_SetItemString(dict, "id", id); PyDict_SetItemString(dict, "sensor_id", sensor_id); PyDict_SetItemString(dict, "sensor_name", sensor_name); PyDict_SetItemString(dict, "max_width", max_width); PyDict_SetItemString(dict, "max_height", max_height); PyDict_SetItemString(dict, "type", type); PyDict_SetItemString(dict, "color_mode", color_mode); PyDict_SetItemString(dict, "pixel_size", pixel_size); /* in um */ /* Gains */ if (sensor_info.bMasterGain) { PyDict_SetItemString(dict, "master_gain", Py_True); } else { PyDict_SetItemString(dict, "master_gain", Py_False); } if (sensor_info.bRGain) { PyDict_SetItemString(dict, "red_gain", Py_True); } else { PyDict_SetItemString(dict, "red_gain", Py_False); } if (sensor_info.bGGain) { PyDict_SetItemString(dict, "green_gain", Py_True); } else { PyDict_SetItemString(dict, "green_gain", Py_False); } if (sensor_info.bBGain) { PyDict_SetItemString(dict, "blue_gain", Py_True); } else { PyDict_SetItemString(dict, "blue_gain", Py_False); } /* Global shutter, rolling if false */ if (sensor_info.bGlobShutter) { PyDict_SetItemString(dict, "global_shutter", Py_True); } else { PyDict_SetItemString(dict, "global_shutter", Py_False); } Py_DECREF(serial_num); Py_DECREF(manufacturer); Py_DECREF(hw_version); Py_DECREF(manufacture_date); Py_DECREF(id); Py_DECREF(sensor_id); Py_DECREF(sensor_name); Py_DECREF(max_width); Py_DECREF(max_height); Py_DECREF(type); Py_DECREF(color_mode); Py_DECREF(pixel_size); return dict; }