Advertisement
lamiastella

SR300Camera::SR300Camera() constructor

May 24th, 2017
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.29 KB | None | 0 0
  1. SR300Camera::SR300Camera(bool use_live_sensor)
  2. {
  3.  
  4.     if (!use_live_sensor) {
  5.         return;
  6.     }
  7.  
  8.     int res;
  9.     std::cout << "Trying to open SR300 camera\n";
  10.  
  11.  
  12.  
  13.     if (!pp) {
  14.         wprintf_s(L"Unable to create the SenseManager\n");
  15.     }
  16.  
  17.     cm = pp->QueryCaptureManager();
  18.     //Status sts= STATUS_NO_ERROR;
  19.     Status sts = STATUS_DATA_UNAVAILABLE; //mona is this the correct initialization?
  20.  
  21.     //do {
  22.         bool revert = false;
  23.         pp->EnableStream(PXCCapture::StreamType::STREAM_TYPE_DEPTH,
  24.             X_DIMENSION, Y_DIMENSION, depth_fps);
  25.         revert = true;
  26.         sts = pp->Init();
  27.         if (sts < Status::STATUS_NO_ERROR) {
  28.  
  29.             if (revert) {
  30.  
  31.                 pp->Close();
  32.                 pp->EnableStream(PXCCapture::STREAM_TYPE_DEPTH);
  33.                 sts = pp->Init();
  34.                 if (sts < Status::STATUS_NO_ERROR) {
  35.                     pp->Close();
  36.                     //pp->EnableStream(Capture::STREAM_TYPE_COLOR);
  37.                     sts = pp->Init();
  38.                 }
  39.             }
  40.             if (sts < Status::STATUS_NO_ERROR) {
  41.                 wprintf_s(L"Failed to locate any video stream(s)\n");
  42.                 pp->Release();
  43.             }
  44.         }
  45.  
  46.         device = pp->QueryCaptureManager()->QueryDevice();
  47.  
  48.         //device->ResetProperties(PXCCapture::STREAM_TYPE_ANY);
  49.  
  50.         //mona mona for (int nframes = 0; ; nframes++) {
  51.             sts = pp->AcquireFrame(false);
  52.  
  53.             if (sts < Status::STATUS_NO_ERROR) {
  54.                 if (sts == Status::STATUS_STREAM_CONFIG_CHANGED) {
  55.                     wprintf_s(L"Stream configuration was changed, re-initilizing\n");
  56.                     pp->Close();
  57.                 }
  58.                 //mona mona break;
  59.             }
  60.  
  61.             sample = pp->QuerySample();
  62.  
  63.             if (sample) {
  64.                 cv::Mat img;
  65.                 Converter::ConvertPXCImageToOpenCVMat(sample->depth, &img);
  66.                 cv::imshow("Depth Image by OpenARK", Visualizer::visualizeDepthMap(img));
  67.                 //mona mona if (sample->depth && !renderd.RenderFrame(sample->depth)) break;
  68.                 renderd.RenderFrame(sample->depth);
  69.                 PXCImage::ImageData depthImage;
  70.                 PXCImage *depthMap = sample->depth;
  71.                 depthMap->AcquireAccess(PXCImage::ACCESS_READ, &depthImage);
  72.                 //depthMap->AcquireAccess(PXCImage::ACCESS_WRITE, &depthImage); //mona is this the correct flag?
  73.                 PXCImage::ImageInfo imgInfo = depthMap->QueryInfo();
  74.                 int depth_stride = depthImage.pitches[0] / sizeof(pxcU16);
  75.                 PXCProjection * projection = device->CreateProjection();
  76.                 cout << "projection is: " << projection;
  77.                 cout << "device is: " << device;
  78.                 pxcU16 *dpixels = (pxcU16*)depthImage.planes[0];
  79.                 unsigned int dpitch = depthImage.pitches[0] / sizeof(pxcU16);
  80.                 PXCPoint3DF32 *pos3D = new PXCPoint3DF32[num_pixels];
  81.  
  82.                 projection->QueryVertices(depthMap, pos3D);
  83.                
  84.                
  85.                 for (int k = 0; k < num_pixels; k++) {
  86.                    
  87.                     /*if (pos3D[k].x != 0) {
  88.                         cout << " xx is: " << pos3D[k].x << endl;
  89.                     }
  90.                     if (pos3D[k].y != 0) {
  91.                         cout << " yy is: " << pos3D[k].y << endl;
  92.                     }
  93.                     if (pos3D[k].z != 0) {
  94.                         cout << " zz is: " << pos3D[k].z << endl;
  95.                     }*/
  96.                     //xyzBuffer.push_back(cv::Point3f(pos3D[k].x, pos3D[k].y, pos3D[k].z));
  97.                     xyzBuffer.emplace_back(cv::Point3f(pos3D[k].x, pos3D[k].y, pos3D[k].z));
  98.                    
  99.                    
  100.                 }
  101.  
  102.                 //xyzMap = cv::Mat(xyzBuffer);
  103.                 cv::Mat xyzMap{ xyzBuffer };
  104.                
  105.  
  106.             }
  107.             printf("opened sensor\n");
  108.             pp->ReleaseFrame();
  109.             printf("acquired image\n");
  110.             //cout << "xyzMap = " << endl << " " << xyzMap << endl << endl;
  111.  
  112.         //mona mona }
  113.  
  114.     //} while (sts == Status::STATUS_STREAM_CONFIG_CHANGED);
  115.  
  116.     //numRows = width and numCol = height? ?
  117.     //numPixels = dd.img.numRows * dd.img.numColumns; // Number of pixels in camera
  118.     numPixels = depth_width * depth_height;
  119.     dists = new float[3 * numPixels]; // Dists contains XYZ values. needs to be 3x the size of numPixels
  120.     amps = new float[numPixels];
  121.     //frame = cvCreateImage(cvSize(dd.img.numColumns, dd.img.numRows), 8, 3); // Create the frame
  122.     frame = cvCreateImage(cvSize(depth_width, depth_height), 8, 3); // Create the frame
  123.  
  124.     KF.init(6, 3, 0);
  125.     KF.transitionMatrix = (cv::Mat_<float>(6, 6) << 1, 0, 0, 1, 0, 0,
  126.         0, 1, 0, 0, 1, 0,
  127.         0, 0, 1, 0, 0, 1,
  128.         0, 0, 0, 1, 0, 0,
  129.         0, 0, 0, 0, 1, 0,
  130.         0, 0, 0, 0, 0, 1);
  131.     measurement = cv::Mat_<float>::zeros(3, 1);
  132.  
  133.     //Initaite Kalman
  134.     KF.statePre.setTo(0);
  135.     setIdentity(KF.measurementMatrix);
  136.     setIdentity(KF.processNoiseCov, cv::Scalar::all(.001)); // Adjust this for faster convergence - but higher noise
  137.     setIdentity(KF.measurementNoiseCov, cv::Scalar::all(1e-1));
  138.     setIdentity(KF.errorCovPost, cv::Scalar::all(.1));
  139. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement