ScanNet / ScanNet

http://www.scan-net.org/
Other
1.77k stars 346 forks source link

How to read depth.pgm file correctly? #15

Open hychiang-git opened 6 years ago

hychiang-git commented 6 years ago

Hi, I am trying to interpret depth value in depth.pgm file after I unpack the .sens file by SensReader. I read depth.pgm file by an online searched python script:

`def read_pgm(filename, byteorder='>'):

#Return image data from a raw PGM file as numpy array.
#Format specification: http://netpbm.sourceforge.net/doc/pgm.html
with open(filename, 'rb') as f:
    buffer = f.read()
try:
    header, width, height, maxval = re.search(
        b"(^P5\s(?:\s*#.*[\r\n])*"
        b"(\d+)\s(?:\s*#.*[\r\n])*"
        b"(\d+)\s(?:\s*#.*[\r\n])*"
        b"(\d+)\s(?:\s*#.*[\r\n]\s)*)", buffer).groups()
except AttributeError:
    raise ValueError("Not a raw PGM file: '%s'" % filename)
return np.frombuffer(buffer,
                     dtype='u1' if int(maxval) < 256 else byteorder+'u2',
                     count=int(width)*int(height),
                     offset=len(header)
                     ).reshape((int(height), int(width)))`

As I reading the depth.pgm by the script, I found the value almost bigger than 1000. What is the measuring unit of the number? Is it millimeter?

Thanks

hychiang-git commented 6 years ago

I also read the code ScanNet/SensReader/c++/src/main.cpp. ` //THIS IS A DEMO FUNCTION: HOW TO DECODE .SENS FILES: CHECK IT OUT! (doesn't do anything real though) void processFrame(const ml::SensorData& sd, size_t frameIdx) {

//de-compress color and depth values
ml::vec3uc* colorData = sd.decompressColorAlloc(frameIdx);
unsigned short* depthData = sd.decompressDepthAlloc(frameIdx);

//dimensions of a color/depth frame
sd.m_colorWidth;
sd.m_colorHeight;
sd.m_depthWidth;
sd.m_depthHeight;

for (unsigned int i = 0; i < sd.m_depthWidth * sd.m_depthHeight; i++) {
    //convert depth values to m:
    float depth_in_meters = sd.m_depthShift * depthData[i];
}

std::free(colorData);
std::free(depthData);

}

` Does the code means the depth value I read from already in meters? However, the values I read almost bigger than 1000. The measuring unit in meters makes no sense to me.

jmfacil commented 4 years ago

If I understood it correctly a depth shift must be applied. Thus, you must divide the value by the shift and I think that for ScanNet the shift is always 1000.0.

Pattern6 commented 1 year ago

Hi, I am trying to interpret depth value in depth.pgm file after I unpack the .sens file by SensReader. I read depth.pgm file by an online searched python script:

`def read_pgm(filename, byteorder='>'):

#Return image data from a raw PGM file as numpy array.
#Format specification: http://netpbm.sourceforge.net/doc/pgm.html
with open(filename, 'rb') as f:
    buffer = f.read()
try:
    header, width, height, maxval = re.search(
        b"(^P5\s(?:\s*#.*[\r\n])*"
        b"(\d+)\s(?:\s*#.*[\r\n])*"
        b"(\d+)\s(?:\s*#.*[\r\n])*"
        b"(\d+)\s(?:\s*#.*[\r\n]\s)*)", buffer).groups()
except AttributeError:
    raise ValueError("Not a raw PGM file: '%s'" % filename)
return np.frombuffer(buffer,
                     dtype='u1' if int(maxval) < 256 else byteorder+'u2',
                     count=int(width)*int(height),
                     offset=len(header)
                     ).reshape((int(height), int(width)))`

As I reading the depth.pgm by the script, I found the value almost bigger than 1000. What is the measuring unit of the number? Is it millimeter?

Thanks

Hello! I want to ask why I was killed in a few minutes when parsing the. sene file, and the CPU memory burst. Have you ever encountered this problem?