/*---------------------------------------------------------------------------*/ BOOL8 DummyFastMatch ( FEATURE Feature, PROTO Proto) /* ** Parameters: ** Feature feature to be "fast matched" to proto ** Proto proto being "fast matched" against ** Globals: ** training_tangent_bbox_pad bounding box pad tangent to proto ** training_orthogonal_bbox_pad bounding box pad orthogonal to proto ** Operation: This routine returns TRUE if Feature would be matched ** by a fast match table built from Proto. ** Return: TRUE if feature could match Proto. ** Exceptions: none ** History: Wed Nov 14 17:19:58 1990, DSJ, Created. */ { FRECT BoundingBox; FLOAT32 MaxAngleError; FLOAT32 AngleError; MaxAngleError = training_angle_pad / 360.0; AngleError = fabs (Proto->Angle - Feature->Params[PicoFeatDir]); if (AngleError > 0.5) AngleError = 1.0 - AngleError; if (AngleError > MaxAngleError) return (FALSE); ComputePaddedBoundingBox (Proto, training_tangent_bbox_pad * GetPicoFeatureLength (), training_orthogonal_bbox_pad * GetPicoFeatureLength (), &BoundingBox); return PointInside(&BoundingBox, Feature->Params[PicoFeatX], Feature->Params[PicoFeatY]); } /* DummyFastMatch */
/** * Compare protos p1 and p2 and return an estimate of the * worst evidence rating that will result for any part of p1 * that is compared to p2. In other words, if p1 were broken * into pico-features and each pico-feature was matched to p2, * what is the worst evidence rating that will be achieved for * any pico-feature. * * @param p1, p2 protos to be compared * * Globals: none * * @return Worst possible result when matching p1 to p2. * @note Exceptions: none * @note History: Mon Nov 26 08:27:53 1990, DSJ, Created. */ FLOAT32 CompareProtos(PROTO p1, PROTO p2) { FEATURE Feature; FLOAT32 WorstEvidence = WORST_EVIDENCE; FLOAT32 Evidence; FLOAT32 Angle, Length; /* if p1 and p2 are not close in length, don't let them match */ Length = fabs (p1->Length - p2->Length); if (Length > MAX_LENGTH_MISMATCH) return (0.0); /* create a dummy pico-feature to be used for comparisons */ Feature = NewFeature (&PicoFeatDesc); Feature->Params[PicoFeatDir] = p1->Angle; /* convert angle to radians */ Angle = p1->Angle * 2.0 * PI; /* find distance from center of p1 to 1/2 picofeat from end */ Length = p1->Length / 2.0 - GetPicoFeatureLength () / 2.0; if (Length < 0) Length = 0; /* set the dummy pico-feature at one end of p1 and match it to p2 */ Feature->Params[PicoFeatX] = p1->X + cos (Angle) * Length; Feature->Params[PicoFeatY] = p1->Y + sin (Angle) * Length; if (DummyFastMatch (Feature, p2)) { Evidence = SubfeatureEvidence (Feature, p2); if (Evidence < WorstEvidence) WorstEvidence = Evidence; } else { FreeFeature(Feature); return 0.0; } /* set the dummy pico-feature at the other end of p1 and match it to p2 */ Feature->Params[PicoFeatX] = p1->X - cos (Angle) * Length; Feature->Params[PicoFeatY] = p1->Y - sin (Angle) * Length; if (DummyFastMatch (Feature, p2)) { Evidence = SubfeatureEvidence (Feature, p2); if (Evidence < WorstEvidence) WorstEvidence = Evidence; } else { FreeFeature(Feature); return 0.0; } FreeFeature (Feature); return (WorstEvidence); } /* CompareProtos */
/** * This routine returns TRUE if Feature would be matched * by a fast match table built from Proto. * * @param Feature feature to be "fast matched" to proto * @param Proto proto being "fast matched" against * * Globals: * - training_tangent_bbox_pad bounding box pad tangent to proto * - training_orthogonal_bbox_pad bounding box pad orthogonal to proto * * @return TRUE if feature could match Proto. * @note Exceptions: none * @note History: Wed Nov 14 17:19:58 1990, DSJ, Created. */ BOOL8 DummyFastMatch ( FEATURE Feature, PROTO Proto) { FRECT BoundingBox; FLOAT32 MaxAngleError; FLOAT32 AngleError; MaxAngleError = training_angle_pad / 360.0; AngleError = fabs (Proto->Angle - Feature->Params[PicoFeatDir]); if (AngleError > 0.5) AngleError = 1.0 - AngleError; if (AngleError > MaxAngleError) return (FALSE); ComputePaddedBoundingBox (Proto, training_tangent_bbox_pad * GetPicoFeatureLength (), training_orthogonal_bbox_pad * GetPicoFeatureLength (), &BoundingBox); return PointInside(&BoundingBox, Feature->Params[PicoFeatX], Feature->Params[PicoFeatY]); } /* DummyFastMatch */
/*---------------------------------------------------------------------------*/ FLOAT32 CompareProtos(PROTO p1, PROTO p2) { /* ** Parameters: ** p1, p2 protos to be compared ** Globals: none ** Operation: Compare protos p1 and p2 and return an estimate of the ** worst evidence rating that will result for any part of p1 ** that is compared to p2. In other words, if p1 were broken ** into pico-features and each pico-feature was matched to p2, ** what is the worst evidence rating that will be achieved for ** any pico-feature. ** Return: Worst possible result when matching p1 to p2. ** Exceptions: none ** History: Mon Nov 26 08:27:53 1990, DSJ, Created. */ FEATURE Feature; FLOAT32 WorstEvidence = WORST_EVIDENCE; FLOAT32 Evidence; FLOAT32 Angle, Length; /* if p1 and p2 are not close in length, don't let them match */ Length = fabs (p1->Length - p2->Length); if (Length > MAX_LENGTH_MISMATCH) return (0.0); /* create a dummy pico-feature to be used for comparisons */ Feature = NewFeature (&PicoFeatDesc); Feature->Params[PicoFeatDir] = p1->Angle; /* convert angle to radians */ Angle = p1->Angle * 2.0 * PI; /* find distance from center of p1 to 1/2 picofeat from end */ Length = p1->Length / 2.0 - GetPicoFeatureLength () / 2.0; if (Length < 0) Length = 0; /* set the dummy pico-feature at one end of p1 and match it to p2 */ Feature->Params[PicoFeatX] = p1->X + cos (Angle) * Length; Feature->Params[PicoFeatY] = p1->Y + sin (Angle) * Length; if (DummyFastMatch (Feature, p2)) { Evidence = SubfeatureEvidence (Feature, p2); if (Evidence < WorstEvidence) WorstEvidence = Evidence; } else { FreeFeature(Feature); return 0.0; } /* set the dummy pico-feature at the other end of p1 and match it to p2 */ Feature->Params[PicoFeatX] = p1->X - cos (Angle) * Length; Feature->Params[PicoFeatY] = p1->Y - sin (Angle) * Length; if (DummyFastMatch (Feature, p2)) { Evidence = SubfeatureEvidence (Feature, p2); if (Evidence < WorstEvidence) WorstEvidence = Evidence; } else { FreeFeature(Feature); return 0.0; } FreeFeature (Feature); return (WorstEvidence); } /* CompareProtos */