INT UEyeCamDriver::setPixelClockRate(INT& clock_rate_mhz) { if (!isConnected()) return IS_INVALID_CAMERA_HANDLE; INT is_err = IS_SUCCESS; UINT pixelClockRange[3]; ZeroMemory(pixelClockRange, sizeof(pixelClockRange)); if ((is_err = is_PixelClock(cam_handle_, IS_PIXELCLOCK_CMD_GET_RANGE, (void*) pixelClockRange, sizeof(pixelClockRange))) != IS_SUCCESS) { std::cerr << "Failed to query pixel clock range from UEye camera '" << cam_name_ << "'" << std::endl; return is_err; } CAP(clock_rate_mhz, (int ) pixelClockRange[0], (int ) pixelClockRange[1]); if ((is_err = is_PixelClock(cam_handle_, IS_PIXELCLOCK_CMD_SET, (void*) &(clock_rate_mhz), sizeof(clock_rate_mhz))) != IS_SUCCESS) { std::cerr << "Failed to set pixel clock to " << clock_rate_mhz << "MHz for UEye camera '" << cam_name_ << "'" << std::endl; return is_err; } std::cout << "Updated pixel clock: " << clock_rate_mhz << " MHz" << std::endl; return IS_SUCCESS; }
static int ids_core_Camera_setpixelclock(ids_core_Camera *self, PyObject *value, void *closure) { int ret, clock; PyObject *exception; if (value == NULL) { PyErr_SetString(PyExc_TypeError, "Cannot delete attribute 'pixelclock'"); return -1; } clock = (int) PyLong_AsLong(value); exception = PyErr_Occurred(); if (exception) { PyErr_SetString(exception, "Pixel clock value must be an int or long"); return -1; } if (clock < 0) { PyErr_SetString(PyExc_ValueError, "Pixel clock must be positive."); return -1; } ret = is_PixelClock(self->handle, IS_PIXELCLOCK_CMD_SET, (void*) &clock, sizeof(clock)); switch (ret) { case IS_SUCCESS: return 0; break; case IS_INVALID_PARAMETER: PyErr_SetString(PyExc_ValueError, "Pixel clock value out of range"); break; default: raise_general_error(self, ret); } return -1; }
static PyObject *ids_core_Camera_getpixelclock(ids_core_Camera *self, void *closure) { UINT clock; int ret; ret = is_PixelClock(self->handle, IS_PIXELCLOCK_CMD_GET, &clock, sizeof(clock)); switch (ret) { case IS_SUCCESS: return PyLong_FromLong(clock); break; default: raise_general_error(self, ret); } return NULL; }
static int ids_core_Camera_setaoi(ids_core_Camera *self, PyObject *set_tuple) { int ret; IS_RECT r = { .s32X = PyLong_AsLong(PyTuple_GetItem(set_tuple, 0)), .s32Y = PyLong_AsLong(PyTuple_GetItem(set_tuple, 1)), .s32Width = PyLong_AsLong(PyTuple_GetItem(set_tuple, 2)), .s32Height = PyLong_AsLong(PyTuple_GetItem(set_tuple, 3)) }; ret = is_AOI(self->handle, IS_AOI_IMAGE_SET_AOI, &r, sizeof(r)); switch (ret) { case IS_SUCCESS: return 0; break; default: PyErr_SetString(PyExc_ValueError, "An error occurred when setting AOI status."); return -1; } } static PyObject *ids_core_Camera_getclockrange(ids_core_Camera *self, void *closure) { int ret; UINT r[3]; PyObject *ret_tuple = PyTuple_New(3); ZeroMemory(r, sizeof(r)); ret = is_PixelClock(self->handle, IS_PIXELCLOCK_CMD_GET_RANGE, &r, sizeof(r)); switch (ret) { case IS_SUCCESS: PyTuple_SetItem(ret_tuple, 0, PyLong_FromLong(r[0])); PyTuple_SetItem(ret_tuple, 1, PyLong_FromLong(r[1])); PyTuple_SetItem(ret_tuple, 2, PyLong_FromLong(r[2])); return ret_tuple; default: PyErr_SetString(PyExc_ValueError, "An error occurred when getting clock range."); return PyLong_FromLong(-1); } }
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 get_en_image(pcl::PointCloud<pcl::PointXYZ> &cloud) { char flag = 'g'; int i = 0; while(flag != 'q') { ostringstream conv; conv << i; cout<<"Capturing new calibration image from the ensenso stereo vision camera."<<endl; ///Read the Ensenso stereo cameras: try { // Initialize NxLib and enumerate cameras nxLibInitialize(true); // Reference to the first camera in the node BySerialNo NxLibItem root; NxLibItem camera = root[itmCameras][itmBySerialNo][0]; // Open the Ensenso NxLibCommand open(cmdOpen); open.parameters()[itmCameras] = camera[itmSerialNumber].asString(); open.execute(); // Capture an image NxLibCommand (cmdCapture).execute(); // Stereo matching task NxLibCommand (cmdComputeDisparityMap).execute (); // Convert disparity map into XYZ data for each pixel NxLibCommand (cmdComputePointMap).execute (); // Get info about the computed point map and copy it into a std::vector double timestamp; std::vector<float> pointMap; int width, height; camera[itmImages][itmRaw][itmLeft].getBinaryDataInfo (0, 0, 0, 0, 0, ×tamp); // Get raw image timestamp camera[itmImages][itmPointMap].getBinaryDataInfo (&width, &height, 0, 0, 0, 0); camera[itmImages][itmPointMap].getBinaryData (pointMap, 0); // Copy point cloud and convert in meters //cloud.header.stamp = getPCLStamp (timestamp); cloud.resize (height * width); cloud.width = width; cloud.height = height; cloud.is_dense = false; // Copy data in point cloud (and convert milimeters in meters) for (size_t i = 0; i < pointMap.size (); i += 3) { cloud.points[i / 3].x = pointMap[i] / 1000.0; cloud.points[i / 3].y = pointMap[i + 1] / 1000.0; cloud.points[i / 3].z = pointMap[i + 2] / 1000.0; } NxLibCommand (cmdRectifyImages).execute(); // Save images NxLibCommand saveImage(cmdSaveImage); // raw left saveImage.parameters()[itmNode] = camera[itmImages][itmRaw][itmLeft].path; saveImage.parameters()[itmFilename] = "calib_en/raw_left" + conv.str()+".png"; saveImage.execute(); // raw right /*saveImage.parameters()[itmNode] = camera[itmImages][itmRaw][itmRight].path; saveImage.parameters()[itmFilename] = "calib_en/raw_right.png"; saveImage.execute(); // rectified left saveImage.parameters()[itmNode] = camera[itmImages][itmRectified][itmLeft].path; saveImage.parameters()[itmFilename] = "calib_en/rectified_left.png"; saveImage.execute(); // rectified right saveImage.parameters()[itmNode] = camera[itmImages][itmRectified][itmRight].path; saveImage.parameters()[itmFilename] = "calib_en/rectified_right.png"; saveImage.execute();*/ } catch (NxLibException& e) { // Display NxLib API exceptions, if any printf("An NxLib API error with code %d (%s) occurred while accessing item %s.\n", e.getErrorCode(), e.getErrorText().c_str(), e.getItemPath().c_str()); if (e.getErrorCode() == NxLibExecutionFailed) printf("/Execute:\n%s\n", NxLibItem(itmExecute).asJson(true).c_str()); } /*catch (NxLibException &ex) { ensensoExceptionHandling (ex, "grabSingleCloud"); }*/ catch (...) { // Display other exceptions printf("Something, somewhere went terribly wrong!\n"); } /*cout<<"Plug in the RGB camera and press any key to continue."<<endl; cin.ignore(); cin.get();*/ cout<<"Capturing new calibration image from the ensenso RGB camera."<<endl; ///Read the IDS RGB Camera attached to the Ensenso stereo camera HIDS hCam = 0; printf("Success-Code: %d\n",IS_SUCCESS); //Kamera öffnen INT nRet = is_InitCamera (&hCam, NULL); printf("Status Init %d\n",nRet); //Pixel-Clock setzen UINT nPixelClockDefault = 9; nRet = is_PixelClock(hCam, IS_PIXELCLOCK_CMD_SET, (void*)&nPixelClockDefault, sizeof(nPixelClockDefault)); printf("Status is_PixelClock %d\n",nRet); //Farbmodus der Kamera setzen //INT colorMode = IS_CM_CBYCRY_PACKED; INT colorMode = IS_CM_BGR8_PACKED; nRet = is_SetColorMode(hCam,colorMode); printf("Status SetColorMode %d\n",nRet); UINT formatID = 4; //Bildgröße einstellen -> 2592x1944 nRet = is_ImageFormat(hCam, IMGFRMT_CMD_SET_FORMAT, &formatID, 4); printf("Status ImageFormat %d\n",nRet); //Speicher für Bild alloziieren char* pMem = NULL; int memID = 0; nRet = is_AllocImageMem(hCam, 1280, 1024, 24, &pMem, &memID); printf("Status AllocImage %d\n",nRet); //diesen Speicher aktiv setzen nRet = is_SetImageMem(hCam, pMem, memID); printf("Status SetImageMem %d\n",nRet); //Bilder im Kameraspeicher belassen INT displayMode = IS_SET_DM_DIB; nRet = is_SetDisplayMode (hCam, displayMode); printf("Status displayMode %d\n",nRet); //Bild aufnehmen nRet = is_FreezeVideo(hCam, IS_WAIT); printf("Status is_FreezeVideo %d\n",nRet); //Bild aus dem Speicher auslesen und als Datei speichern String path = "./calib_en/snap_BGR"+conv.str()+".png"; std::wstring widepath; for(int i = 0; i < path.length(); ++i) widepath += wchar_t (path[i] ); IMAGE_FILE_PARAMS ImageFileParams; ImageFileParams.pwchFileName = &widepath[0]; ImageFileParams.pnImageID = NULL; ImageFileParams.ppcImageMem = NULL; ImageFileParams.nQuality = 0; ImageFileParams.nFileType = IS_IMG_PNG; nRet = is_ImageFile(hCam, IS_IMAGE_FILE_CMD_SAVE, (void*) &ImageFileParams, sizeof(ImageFileParams)); printf("Status is_ImageFile %d\n",nRet); //Kamera wieder freigeben is_ExitCamera(hCam); cout<<"To quit capturing calibration images, choose q. Else, choose any other letter."<<endl; cin >> flag; i++; } }
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; }