MCPcopy Create free account
hub / github.com/andybarry/makerscanner / PixelToDistance2

Method PixelToDistance2

ScanThread.cpp:433–463  ·  view source on GitHub ↗

compute distance to a point given the x pixel location and the width reference x pixel location

Source from the content-addressed store, hash-verified

431
432// compute distance to a point given the x pixel location and the width reference x pixel location
433double ScanThread::PixelToDistance2(float laserCenter, float widthReference)
434{
435 // TODO: make generic for other sized cameras
436
437 if (laserCenter > widthReference + 20)
438 {
439 // the detected laser appears to be to the right of the width reference.
440 // this is almost certainly noise and will result in crazy distance calculations
441 return -1;
442 } else if (laserCenter > widthReference)
443 {
444 // might just be a slightly tilted laser
445 laserCenter = widthReference;
446 }
447
448 double l = (widthReference) / pixelsPerCmOnFlatReference;
449 double lPlusM = (laserCenter) / pixelsPerCmOnFlatReference;
450 double m = l - lPlusM; // m is the object position projected on the flat reference background
451
452 //double distFromRef = m * m_DistanceFromFlatReference / (DISPARITY_DISTANCE + m);
453
454 double ret = distanceFromFlatReference - m * distanceFromFlatReference / (DISPARITY_DISTANCE + m);
455
456 if (ret > 100)
457 {
458 DisplayText(wxT("\nWarning: large distance detected."));
459 }
460
461 return ret;
462
463}
464
465// Write a string to disk via an event to the frame
466void ScanThread::WriteToFile(wxString str)

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected