////////////////////////////////////////////////////////////////////////////////// // calculateMaxAOI --------------------------------------------------------------- ////////////////////////////////////////////////////////////////////////////////// void ofxUeye::calculateMaxAOI() { bool wasLive = bLive; if (wasLive) disableLive(); // Maximize AOI int curBinning = _binning; int curSubSampling = _subSampling; double curScaler = _scaler; is_SetBinning (m_hCam, IS_BINNING_DISABLE); is_SetSubSampling (m_hCam, IS_SUBSAMPLING_DISABLE); is_SetSensorScaler (m_hCam, IS_ENABLE_SENSOR_SCALER | IS_ENABLE_ANTI_ALIASING, 1.0); IS_RECT fullAOI; fullAOI.s32X = 0; fullAOI.s32Y = 0; fullAOI.s32Width = _sensorWidth; fullAOI.s32Height = _sensorHeight; is_AOI(m_hCam, IS_AOI_IMAGE_SET_AOI, (void*)&fullAOI, sizeof(fullAOI)); is_SetBinning (m_hCam, curBinning); is_SetSubSampling (m_hCam, curSubSampling); is_SetSensorScaler (m_hCam, IS_ENABLE_SENSOR_SCALER | IS_ENABLE_ANTI_ALIASING, curScaler); // Get the maximum AOI in the current binning, sub sampling and scaler IS_SIZE_2D maxAOI; is_AOI(m_hCam, IS_AOI_IMAGE_GET_SIZE_MAX, (void*)&maxAOI, sizeof(maxAOI)); _AOIMax.x = 0; _AOIMax.y = 0; _AOIMax.width = (float)maxAOI.s32Width; _AOIMax.height = (float)maxAOI.s32Height; if (wasLive) enableLive(); }
////////////////////////////////////////////////////////////////////////////////// // setSubSampling ---------------------------------------------------------------- ////////////////////////////////////////////////////////////////////////////////// int ofxUeye::setSubSampling(INT mode) { bool wasLive = bLive; if (wasLive) disableLive(); // As the subsampling change will make the camera irresponsive for a while, we need to flag as NOT ready for thread safety bReady = false; int result; result = is_SetSubSampling (m_hCam, mode); if(result == IS_SUCCESS){ _subSampling = mode; updateDimensions(); ofLog(OF_LOG_WARNING, "ofxUeye - setSubSampling - (%i) Success.", mode); } else { if(bVerbose) ofLog(OF_LOG_WARNING, "ofxUeye - setSubSampling - Couldn't apply %i value.", mode); } if (wasLive) enableLive(); return result; }
INT UEyeCamDriver::setSubsampling(int& rate, bool reallocate_buffer) { if (!isConnected()) return IS_INVALID_CAMERA_HANDLE; INT is_err = IS_SUCCESS; // Stop capture to prevent access to memory buffer setStandbyMode(); INT rate_flag; INT supportedRates; supportedRates = is_SetSubSampling(cam_handle_, IS_GET_SUPPORTED_SUBSAMPLING); switch (rate) { case 1: rate_flag = IS_SUBSAMPLING_DISABLE; break; case 2: rate_flag = IS_SUBSAMPLING_2X; break; case 4: rate_flag = IS_SUBSAMPLING_4X; break; case 8: rate_flag = IS_SUBSAMPLING_8X; break; case 16: rate_flag = IS_SUBSAMPLING_16X; break; default: std::cerr << "Invalid or unsupported subsampling rate: " << rate << ", resetting to 1X" << std::endl; rate = 1; rate_flag = IS_SUBSAMPLING_DISABLE; break; } if ((supportedRates & rate_flag) == rate_flag) { if ((is_err = is_SetSubSampling(cam_handle_, rate_flag)) != IS_SUCCESS) { std::cerr << "Could not set subsampling rate to " << rate << "X (" << err2str(is_err) << ")" << std::endl; return is_err; } } else { std::cerr << "Camera does not support requested sampling rate of " << rate << std::endl; // Query current rate INT currRate = is_SetSubSampling(cam_handle_, IS_GET_SUBSAMPLING); if (currRate == IS_SUBSAMPLING_DISABLE) { rate = 1; } else if (currRate == IS_SUBSAMPLING_2X) { rate = 2; } else if (currRate == IS_SUBSAMPLING_4X) { rate = 4; } else if (currRate == IS_SUBSAMPLING_8X) { rate = 8; } else if (currRate == IS_SUBSAMPLING_16X) { rate = 16; } else { std::cerr << "ColorCamera.has unsupported sampling rate (" << currRate << "), resetting to 1X" << std::endl; if ((is_err = is_SetSubSampling(cam_handle_, IS_SUBSAMPLING_DISABLE)) != IS_SUCCESS) { std::cerr << "Could not set subsampling rate to 1X (" << err2str(is_err) << ")" << std::endl; return is_err; } } return IS_SUCCESS; } std::cout << "Updated subsampling rate to " << rate << "X" << std::endl; cam_subsampling_rate_ = rate; return (reallocate_buffer ? reallocateCamBuffer() : IS_SUCCESS); }
bool IdsSourceSink::Init() { PUEYE_CAMERA_LIST m_pCamList; UEYE_CAMERA_INFO m_CameraInfo; // init the internal camera info structure ZeroMemory (&m_CameraInfo, sizeof(UEYE_CAMERA_INFO)); // get the cameralist from SDK m_pCamList = new UEYE_CAMERA_LIST; m_pCamList->dwCount = 0; if (is_GetCameraList (m_pCamList) == IS_SUCCESS) { DWORD dw = m_pCamList->dwCount; delete m_pCamList; // Reallocate the required camera list size m_pCamList = (PUEYE_CAMERA_LIST)new char[sizeof(DWORD) + dw * sizeof(UEYE_CAMERA_INFO)]; m_pCamList->dwCount = dw; // Get CameraList and store it ... if (is_GetCameraList (m_pCamList) != IS_SUCCESS) return false; } else return false; if (m_pCamList->dwCount==0) { qDebug()<<"No camera found"; return false; } else if (m_pCamList->dwCount>1) { qDebug()<<"More than 1 camera: "<<m_pCamList->dwCount; } // will use camera 0 memcpy (&m_CameraInfo, &m_pCamList->uci[0], sizeof(UEYE_CAMERA_INFO)); hCam = (HIDS) (m_CameraInfo.dwDeviceID | IS_USE_DEVICE_ID); if(is_InitCamera (&hCam, NULL)!= IS_SUCCESS){ qDebug()<<"init not successful"; return false; } // double minFPS, maxFPS, FPSinterval; // is_GetFrameTimeRange (hCam, &minFPS, &maxFPS, &FPSinterval); //cout<< fixed << setprecision(4) << minFPS << " MINFPS " << maxFPS << " MAXFPS "<< FPSinterval << " FPSinterval " << endl; //myfile<< fixed << setprecision(4) << minFPS << " MINFPS " << maxFPS << " MAXFPS "<< FPSinterval << " FPSinterval " << endl; is_SetGainBoost (hCam, IS_SET_GAINBOOST_OFF); is_SetWhiteBalance (hCam, IS_SET_WB_DISABLE); // is_SetBrightness (hCam,0); // is_SetContrast (hCam,0); // is_SetGamma (hCam, 100);// Value multiplied by 100 (for the camera it goes from 0.01 to 10 is_SetHWGainFactor (hCam, IS_SET_MASTER_GAIN_FACTOR, 100); uint pixelC=304; is_PixelClock(hCam, IS_PIXELCLOCK_CMD_SET, (void*)&pixelC, sizeof(pixelC)); flagIDS= is_SetSubSampling (hCam, IS_SUBSAMPLING_2X_VERTICAL | IS_SUBSAMPLING_2X_HORIZONTAL); //Both are needed //Configuration section: very important to match the img_bpp=8 with the chacracteristics of the CV::MAT image to use //weird results like cropping or black lines can be obtained if not changed accordingly int img_width=2048, img_height=2048, img_bpp=8, factorSMP=2; //Variable to state the Linehopping // int img_step, img_data_size; imgMem = NULL; is_AllocImageMem(hCam, img_width/factorSMP, img_height/factorSMP, img_bpp, &imgMem, &memId); is_SetImageMem (hCam, imgMem, memId); // is_SetImageSize (hCam, img_width/factorSMP, img_height/factorSMP); is_SetColorMode (hCam, IS_CM_MONO8); is_SetDisplayMode (hCam, IS_SET_DM_DIB); // Direct buffer mode writes to RAM which is the only option on Linux //OpenCV variables: REMEMBER THE SUBSAMPLING buffer=cv::Mat::zeros(img_width/factorSMP,img_height/factorSMP, CV_8UC1); return true; }
void mexFunction(int nlhs,mxArray *plhs[],int nrhs,const mxArray *prhs[]) { // CHECK ARGS if (nrhs != 0) { mexErrMsgIdAndTxt( "Mscope:initialiseCamera:invalidNumInputs", "No Input arguments accepted."); } if (nlhs > 2) { mexErrMsgIdAndTxt( "Mscope:initialiseCamera:maxlhs", "Too many output arguments."); } HCAM hCam = 0; // CONNECT TO CAMERA AND GET THE HANDLE int rv = is_InitCamera(&hCam, NULL); // SET THE PIXEL CLOCK UINT pixelClock = DFT_PX_CLOCK; rv = is_PixelClock(hCam, IS_PIXELCLOCK_CMD_SET, (void*) &pixelClock, sizeof(pixelClock)); // FRAME RATE double frameRate = DFT_FRAME_RATE; double actualFrameRate; rv = is_SetFrameRate(hCam, frameRate, &actualFrameRate); // EXPOSURE TIME double expTime = 10; // exposure time in ms rv = is_Exposure(hCam, IS_EXPOSURE_CMD_SET_EXPOSURE, &expTime, 8); // TRIGGER MODE rv = is_SetExternalTrigger(hCam, IS_SET_TRIGGER_SOFTWARE); // COLOR MODE rv = is_SetColorMode(hCam, IS_CM_MONO8); // 8-bit monochrome // SET THE SUBSAMPLING rv = is_SetSubSampling(hCam, IS_SUBSAMPLING_4X_VERTICAL | IS_SUBSAMPLING_4X_HORIZONTAL); // ALLOCATE MEMORY int bitDepth = 8; char* pcImgMem; int id; rv = is_AllocImageMem(hCam, H_PIX, V_PIX, bitDepth, &pcImgMem, &id); // CALCULATE THE LINE PITCH int linePitch; rv = is_GetImageMemPitch(hCam, &linePitch); std::printf("\nLine Pitch = %i\n",linePitch); // SET MEMORY rv = is_SetImageMem(hCam, pcImgMem, id); // START CAPTURING rv = is_CaptureVideo(hCam, IS_DONT_WAIT); // RETURN CAMERA HANDLE UINT8_T hCam8 = (UINT8_T) hCam; mwSignedIndex scalarDims[2] = {1,1}; // elements in image plhs[0] = mxCreateNumericArray(1, scalarDims, mxUINT8_CLASS, mxREAL); double * hCamPtr = mxGetPr(plhs[0]); memcpy(hCamPtr, &hCam8, sizeof(hCam8)); // RETURN MEMORY ID UINT32_T id32 = (UINT32_T) id; plhs[1] = mxCreateNumericArray(1, scalarDims, mxUINT32_CLASS, mxREAL); double * mIdPtr = mxGetPr(plhs[1]); memcpy(mIdPtr, &id32, sizeof(id32)); return; }