Use empty keypoint array for Detection if no keypoints are detected

PiperOrigin-RevId: 534572162
This commit is contained in:
Sebastian Schmidt 2023-05-23 15:07:06 -07:00 committed by Copybara-Service
parent 1523cc48a1
commit e8ee934bf9
5 changed files with 14 additions and 11 deletions

View File

@ -27,13 +27,14 @@ export declare interface Detection {
boundingBox?: BoundingBox; boundingBox?: BoundingBox;
/** /**
* Optional list of keypoints associated with the detection. Keypoints * List of keypoints associated with the detection. Keypoints represent
* represent interesting points related to the detection. For example, the * interesting points related to the detection. For example, the keypoints
* keypoints represent the eye, ear and mouth from face detection model. Or * represent the eye, ear and mouth from face detection model. Or in the
* in the template matching detection, e.g. KNIFT, they can represent the * template matching detection, e.g. KNIFT, they can represent the feature
* feature points for template matching. * points for template matching. Contains an empty list if no keypoints are
* detected.
*/ */
keypoints?: NormalizedKeypoint[]; keypoints: NormalizedKeypoint[];
} }
/** Detection results of a model. */ /** Detection results of a model. */

View File

@ -85,7 +85,8 @@ describe('convertFromDetectionProto()', () => {
categoryName: '', categoryName: '',
displayName: '', displayName: '',
}], }],
boundingBox: {originX: 0, originY: 0, width: 0, height: 0} boundingBox: {originX: 0, originY: 0, width: 0, height: 0},
keypoints: []
}); });
}); });
}); });

View File

@ -26,7 +26,7 @@ export function convertFromDetectionProto(source: DetectionProto): Detection {
const labels = source.getLabelList(); const labels = source.getLabelList();
const displayNames = source.getDisplayNameList(); const displayNames = source.getDisplayNameList();
const detection: Detection = {categories: []}; const detection: Detection = {categories: [], keypoints: []};
for (let i = 0; i < scores.length; i++) { for (let i = 0; i < scores.length; i++) {
detection.categories.push({ detection.categories.push({
score: scores[i], score: scores[i],
@ -47,7 +47,6 @@ export function convertFromDetectionProto(source: DetectionProto): Detection {
} }
if (source.getLocationData()?.getRelativeKeypointsList().length) { if (source.getLocationData()?.getRelativeKeypointsList().length) {
detection.keypoints = [];
for (const keypoint of for (const keypoint of
source.getLocationData()!.getRelativeKeypointsList()) { source.getLocationData()!.getRelativeKeypointsList()) {
detection.keypoints.push({ detection.keypoints.push({

View File

@ -191,7 +191,8 @@ describe('FaceDetector', () => {
categoryName: '', categoryName: '',
displayName: '', displayName: '',
}], }],
boundingBox: {originX: 0, originY: 0, width: 0, height: 0} boundingBox: {originX: 0, originY: 0, width: 0, height: 0},
keypoints: []
}); });
}); });
}); });

View File

@ -210,7 +210,8 @@ describe('ObjectDetector', () => {
categoryName: '', categoryName: '',
displayName: '', displayName: '',
}], }],
boundingBox: {originX: 0, originY: 0, width: 0, height: 0} boundingBox: {originX: 0, originY: 0, width: 0, height: 0},
keypoints: []
}); });
}); });
}); });