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 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"); }
void mexFunction( int nlhs, mxArray *plhs[],int nrhs, const mxArray*prhs[] ) { /* Check for proper number of arguments */ if (!(nrhs == 2)) { mexErrMsgTxt("You have to give me two inputs"); } if (!mxIsStruct(prhs[1])) { mexErrMsgTxt("That second input has to be an image structure, you know."); } int error = 0; int BitsPerPixel = 8; HCAM hCam = *(HCAM *)mxGetPr(prhs[0]); //Freeze the video feed for frame grab to prevent split frames error = is_FreezeVideo( hCam, IS_WAIT ); if (error !=IS_SUCCESS) { mexErrMsgTxt("Error freezing video"); } int image_field = mxGetFieldNumber(prhs[1],"image"); int pointer_field = mxGetFieldNumber(prhs[1],"pointer"); int ID_field = mxGetFieldNumber(prhs[1],"id"); mxArray *p_output_image = mxGetFieldByNumber(prhs[1],0,image_field); char *p_output = (char *)mxGetPr(p_output_image); mxArray *ppointer_field = mxGetFieldByNumber(prhs[1],0,pointer_field); char *p_image = (char *)*(int *)mxGetPr(ppointer_field); mxArray *pID_field = mxGetFieldByNumber(prhs[1],0,ID_field); int *ID = (int *)mxGetPr(pID_field); error = is_CopyImageMem (hCam, p_image, *ID, p_output); if (error !=IS_SUCCESS) { mexErrMsgTxt("Error copying image data to output"); } //If a variable is supplied on the LHS, use it to output image frame data if (nlhs == 1) { IS_RECT rectAOI; INT nX, nY; error = is_AOI(hCam, IS_AOI_IMAGE_GET_AOI, (void*)&rectAOI, sizeof(rectAOI)); if (error == IS_SUCCESS) { nX = rectAOI.s32Width; nY = rectAOI.s32Height; } mxArray *p_output_image_new = mxCreateNumericMatrix(nX, nY, mxUINT8_CLASS, mxREAL); p_output = (char *)mxGetPr(p_output_image_new); error = is_CopyImageMem (hCam, p_image, *ID, p_output); if (error !=IS_SUCCESS) { mexErrMsgTxt("Error copying image data to output"); } //Set mex function output plhs[0] = p_output_image_new; } return; }