簡體   English   中英

將深度圖像轉換為開放的cv Mat格式

[英]Converting Depth Image into open cv Mat format

我正在使用PMD相機以以下格式捕獲深度圖像

struct DepthData
{
    int      version;  
    std::chrono::microseconds timeStamp;       
    uint16_t                  width;           
    uint16_t                  height;          
    Vector of uint_16          exposureTimes;   
    Vector of DepthPoint     points;          //!< array of points
};

深度點結構看起來像這樣

struct DepthPoint
{
    float x;                 //!< X coordinate [meters]
    float y;                 //!< Y coordinate [meters]
    float z;                 //!< Z coordinate [meters]
    float noise;             //!< noise value [meters]
    uint16_t grayValue;      //!< 16-bit gray value
    uint8_t depthConfidence; //!< value 0 = bad, 255 = good
};

而且我正在嘗試將其轉換為opencv mat數據結構。 下面是代碼。 但這引發了異常。 請幫助

const int imageSize = w * h;

Mat out = cv::Mat(h, w, CV_16UC3, Scalar(0, 0, 0));

const Scalar S;


for (int h = 0; h < out.rows; h++)
{
  //printf("%" PRIu64 "\n", point.at(h).grayValue);
  for (int w = 0; w < out.cols; w++)
  {
    //printf("%" PRIu64 "\n", point.at(h).grayValue);
    out.at<cv::Vec3f>(h,w)[0] = point[w].x;
    out.at<cv::Vec3f>(h, w)[1] = point[w].y;
    out.at<cv::Vec3f>(h, w)[2] = point[w].z;

  }
}

imwrite("E:/softwares/1.8.0.71/bin/depthImage1.png", out);

您似乎做錯了幾件事。

您正在創建CV_16UC3類型的圖像,它是一個3通道16位無符號字符圖像。 然后在out.at<cv::Vec3f>(h,w)[0] ,嘗試將其一部分讀取為3個浮點的向量。 您可能應該將圖像創建為浮動圖像。

有關更多詳細信息,請提供例外。 幫助會更容易。

UPD:如果只需要深度圖像,請創建如下圖像:

Mat out = cv::Mat::zeros(h, w, CV_16UC1);

然后在每個像素中:

out.at<uint16_t>(h, w) = depth_point.grayValue;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM