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

Method GetDistanceToReferenceWall

ScanThread.cpp:526–558  ·  view source on GitHub ↗

NOTE: this function also sets pixelsPerCmOnFlatReference which is required for operation

Source from the content-addressed store, hash-verified

524
525// NOTE: this function also sets pixelsPerCmOnFlatReference which is required for operation
526float ScanThread::GetDistanceToReferenceWall(vector<float> *laserCenterPx)
527{
528 // first, find the laser in the top 25 pixels in the image
529 float refCenter = GetReferenceLaserLocation(laserCenterPx);
530
531 if (refCenter < 0)
532 {
533 // failed to find reference laser.
534 DisplayText(wxT("\nError: failed to compute distance to target. Most likely didn't get a clear enough picture of the laser line. Aborting."));
535 return -1;
536 }
537
538 // compute the distance to the target based on camera parameters and refCenter
539 // refCenter holds the number of pixels the center is from the left of the image.
540 // For this computation, we want to know the number of pixels from the camera's center -- convert
541 float pixelsFromCameraCenter = (laserCentered->width / 2) - refCenter;
542
543 distanceFromFlatReference = 0;
544
545 pixelsPerCmOnFlatReference = pixelsFromCameraCenter / float(DISPARITY_DISTANCE);
546
547 distanceFromFlatReference += float(PIXELS_PER_CM_PER_CM) / pixelsPerCmOnFlatReference;
548
549 wxString strDist = wxT("\nEstimated distance from flat reference = ");
550 wxString numstr;
551 numstr.Printf(wxT("%.0f"), distanceFromFlatReference);
552 strDist += numstr + wxT("cm");
553
554 DisplayText(strDist);
555
556 return distanceFromFlatReference;
557
558}
559
560void ScanThread::DisplayLaserPx(vector<float> *laserPx)
561{

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected