MCPcopy Create free account
hub / github.com/PointCloudLibrary/pcl / fillDisparityImage

Method fillDisparityImage

io/src/image_depth.cpp:256–298  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

254}
255
256void
257pcl::io::DepthImage::fillDisparityImage (unsigned width, unsigned height, float* disparity_buffer, unsigned line_step) const
258{
259 if (width > wrapper_->getWidth () || height > wrapper_->getHeight ())
260 THROW_IO_EXCEPTION ("upsampling not supported: %d x %d -> %d x %d", wrapper_->getWidth (), wrapper_->getHeight (), width, height);
261
262 if (wrapper_->getWidth () % width != 0 || wrapper_->getHeight () % height != 0)
263 THROW_IO_EXCEPTION ("downsampling only supported for integer scale: %d x %d -> %d x %d", wrapper_->getWidth (), wrapper_->getHeight (), width, height);
264
265 if (line_step == 0)
266 line_step = width * static_cast<unsigned> (sizeof (float));
267
268 unsigned xStep = wrapper_->getWidth () / width;
269 unsigned ySkip = (wrapper_->getHeight () / height - 1) * wrapper_->getWidth ();
270
271 unsigned bufferSkip = line_step - width * static_cast<unsigned> (sizeof (float));
272
273 // Fill in the depth image data
274 // iterate over all elements and fill disparity matrix: disp[x,y] = f * b / z_distance[x,y];
275 // focal length is for the native image resolution -> focal_length = focal_length_ / xStep;
276 float constant = focal_length_ * baseline_ * 1000.0f / static_cast<float> (xStep);
277
278 const auto* inputBuffer = static_cast<const unsigned short*> (wrapper_->getData ());
279
280 for (unsigned yIdx = 0, depthIdx = 0; yIdx < height; ++yIdx, depthIdx += ySkip)
281 {
282 for (unsigned xIdx = 0; xIdx < width; ++xIdx, depthIdx += xStep, ++disparity_buffer)
283 {
284 unsigned short pixel = inputBuffer[depthIdx];
285 if (pixel == 0 || pixel == no_sample_value_ || pixel == shadow_value_)
286 *disparity_buffer = 0.0;
287 else
288 *disparity_buffer = constant / static_cast<float> (pixel);
289 }
290
291 // if we have padding
292 if (bufferSkip > 0)
293 {
294 char* cBuffer = reinterpret_cast<char*> (disparity_buffer);
295 disparity_buffer = reinterpret_cast<float*> (cBuffer + bufferSkip);
296 }
297 }
298}

Callers

nothing calls this directly

Calls 3

getWidthMethod · 0.45
getHeightMethod · 0.45
getDataMethod · 0.45

Tested by

no test coverage detected