Separate web and java api landmark and world landmark to two classes. This makes the platforms interface consistent.
PiperOrigin-RevId: 492332990
This commit is contained in:
committed by
Copybara-Service
parent
ead41132a8
commit
768d2dc548
+21
-7
@@ -15,10 +15,27 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* Landmark represents a point in 3D space with x, y, z coordinates. If
|
||||
* normalized is true, the landmark coordinates is normalized respect to the
|
||||
* dimension of image, and the coordinates values are in the range of [0,1].
|
||||
* Otherwise, it represenet a point in world coordinates.
|
||||
* Normalized Landmark represents a point in 3D space with x, y, z coordinates.
|
||||
* x and y are normalized to [0.0, 1.0] by the image width and height
|
||||
* respectively. z represents the landmark depth, and the smaller the value the
|
||||
* closer the landmark is to the camera. The magnitude of z uses roughly the
|
||||
* same scale as x.
|
||||
*/
|
||||
export declare interface NormalizedLandmark {
|
||||
/** The x coordinates of the normalized landmark. */
|
||||
x: number;
|
||||
|
||||
/** The y coordinates of the normalized landmark. */
|
||||
y: number;
|
||||
|
||||
/** The z coordinates of the normalized landmark. */
|
||||
z: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Landmark represents a point in 3D space with x, y, z coordinates. The
|
||||
* landmark coordinates are in meters. z represents the landmark depth,
|
||||
* and the smaller the value the closer the world landmark is to the camera.
|
||||
*/
|
||||
export declare interface Landmark {
|
||||
/** The x coordinates of the landmark. */
|
||||
@@ -29,7 +46,4 @@ export declare interface Landmark {
|
||||
|
||||
/** The z coordinates of the landmark. */
|
||||
z: number;
|
||||
|
||||
/** Whether this landmark is normalized with respect to the image size. */
|
||||
normalized: boolean;
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ import {HandDetectorGraphOptions} from '../../../../tasks/cc/vision/hand_detecto
|
||||
import {HandLandmarkerGraphOptions} from '../../../../tasks/cc/vision/hand_landmarker/proto/hand_landmarker_graph_options_pb';
|
||||
import {HandLandmarksDetectorGraphOptions} from '../../../../tasks/cc/vision/hand_landmarker/proto/hand_landmarks_detector_graph_options_pb';
|
||||
import {Category} from '../../../../tasks/web/components/containers/category';
|
||||
import {Landmark} from '../../../../tasks/web/components/containers/landmark';
|
||||
import {Landmark, NormalizedLandmark} from '../../../../tasks/web/components/containers/landmark';
|
||||
import {convertClassifierOptionsToProto} from '../../../../tasks/web/components/processors/classifier_options';
|
||||
import {WasmFileset} from '../../../../tasks/web/core/wasm_fileset';
|
||||
import {VisionTaskRunner} from '../../../../tasks/web/vision/core/vision_task_runner';
|
||||
@@ -67,7 +67,7 @@ FULL_IMAGE_RECT.setHeight(1);
|
||||
export class GestureRecognizer extends
|
||||
VisionTaskRunner<GestureRecognizerResult> {
|
||||
private gestures: Category[][] = [];
|
||||
private landmarks: Landmark[][] = [];
|
||||
private landmarks: NormalizedLandmark[][] = [];
|
||||
private worldLandmarks: Landmark[][] = [];
|
||||
private handednesses: Category[][] = [];
|
||||
|
||||
@@ -306,13 +306,12 @@ export class GestureRecognizer extends
|
||||
for (const binaryProto of data) {
|
||||
const handLandmarksProto =
|
||||
NormalizedLandmarkList.deserializeBinary(binaryProto);
|
||||
const landmarks: Landmark[] = [];
|
||||
const landmarks: NormalizedLandmark[] = [];
|
||||
for (const handLandmarkProto of handLandmarksProto.getLandmarkList()) {
|
||||
landmarks.push({
|
||||
x: handLandmarkProto.getX() ?? 0,
|
||||
y: handLandmarkProto.getY() ?? 0,
|
||||
z: handLandmarkProto.getZ() ?? 0,
|
||||
normalized: true
|
||||
z: handLandmarkProto.getZ() ?? 0
|
||||
});
|
||||
}
|
||||
this.landmarks.push(landmarks);
|
||||
@@ -333,8 +332,7 @@ export class GestureRecognizer extends
|
||||
worldLandmarks.push({
|
||||
x: handWorldLandmarkProto.getX() ?? 0,
|
||||
y: handWorldLandmarkProto.getY() ?? 0,
|
||||
z: handWorldLandmarkProto.getZ() ?? 0,
|
||||
normalized: false
|
||||
z: handWorldLandmarkProto.getZ() ?? 0
|
||||
});
|
||||
}
|
||||
this.worldLandmarks.push(worldLandmarks);
|
||||
|
||||
+2
-2
@@ -15,14 +15,14 @@
|
||||
*/
|
||||
|
||||
import {Category} from '../../../../tasks/web/components/containers/category';
|
||||
import {Landmark} from '../../../../tasks/web/components/containers/landmark';
|
||||
import {Landmark, NormalizedLandmark} from '../../../../tasks/web/components/containers/landmark';
|
||||
|
||||
/**
|
||||
* Represents the gesture recognition results generated by `GestureRecognizer`.
|
||||
*/
|
||||
export declare interface GestureRecognizerResult {
|
||||
/** Hand landmarks of detected hands. */
|
||||
landmarks: Landmark[][];
|
||||
landmarks: NormalizedLandmark[][];
|
||||
|
||||
/** Hand landmarks in world coordniates of detected hands. */
|
||||
worldLandmarks: Landmark[][];
|
||||
|
||||
@@ -24,7 +24,7 @@ import {HandDetectorGraphOptions} from '../../../../tasks/cc/vision/hand_detecto
|
||||
import {HandLandmarkerGraphOptions} from '../../../../tasks/cc/vision/hand_landmarker/proto/hand_landmarker_graph_options_pb';
|
||||
import {HandLandmarksDetectorGraphOptions} from '../../../../tasks/cc/vision/hand_landmarker/proto/hand_landmarks_detector_graph_options_pb';
|
||||
import {Category} from '../../../../tasks/web/components/containers/category';
|
||||
import {Landmark} from '../../../../tasks/web/components/containers/landmark';
|
||||
import {Landmark, NormalizedLandmark} from '../../../../tasks/web/components/containers/landmark';
|
||||
import {WasmFileset} from '../../../../tasks/web/core/wasm_fileset';
|
||||
import {VisionTaskRunner} from '../../../../tasks/web/vision/core/vision_task_runner';
|
||||
import {ImageSource, WasmModule} from '../../../../web/graph_runner/graph_runner';
|
||||
@@ -59,7 +59,7 @@ FULL_IMAGE_RECT.setHeight(1);
|
||||
|
||||
/** Performs hand landmarks detection on images. */
|
||||
export class HandLandmarker extends VisionTaskRunner<HandLandmarkerResult> {
|
||||
private landmarks: Landmark[][] = [];
|
||||
private landmarks: NormalizedLandmark[][] = [];
|
||||
private worldLandmarks: Landmark[][] = [];
|
||||
private handednesses: Category[][] = [];
|
||||
|
||||
@@ -255,13 +255,12 @@ export class HandLandmarker extends VisionTaskRunner<HandLandmarkerResult> {
|
||||
for (const binaryProto of data) {
|
||||
const handLandmarksProto =
|
||||
NormalizedLandmarkList.deserializeBinary(binaryProto);
|
||||
const landmarks: Landmark[] = [];
|
||||
const landmarks: NormalizedLandmark[] = [];
|
||||
for (const handLandmarkProto of handLandmarksProto.getLandmarkList()) {
|
||||
landmarks.push({
|
||||
x: handLandmarkProto.getX() ?? 0,
|
||||
y: handLandmarkProto.getY() ?? 0,
|
||||
z: handLandmarkProto.getZ() ?? 0,
|
||||
normalized: true
|
||||
});
|
||||
}
|
||||
this.landmarks.push(landmarks);
|
||||
@@ -269,7 +268,7 @@ export class HandLandmarker extends VisionTaskRunner<HandLandmarkerResult> {
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts raw data into a landmark, and adds it to our worldLandmarks
|
||||
* Converts raw data into a world landmark, and adds it to our worldLandmarks
|
||||
* list.
|
||||
*/
|
||||
private adddJsWorldLandmarks(data: Uint8Array[]): void {
|
||||
@@ -283,7 +282,6 @@ export class HandLandmarker extends VisionTaskRunner<HandLandmarkerResult> {
|
||||
x: handWorldLandmarkProto.getX() ?? 0,
|
||||
y: handWorldLandmarkProto.getY() ?? 0,
|
||||
z: handWorldLandmarkProto.getZ() ?? 0,
|
||||
normalized: false
|
||||
});
|
||||
}
|
||||
this.worldLandmarks.push(worldLandmarks);
|
||||
|
||||
@@ -15,14 +15,14 @@
|
||||
*/
|
||||
|
||||
import {Category} from '../../../../tasks/web/components/containers/category';
|
||||
import {Landmark} from '../../../../tasks/web/components/containers/landmark';
|
||||
import {Landmark, NormalizedLandmark} from '../../../../tasks/web/components/containers/landmark';
|
||||
|
||||
/**
|
||||
* Represents the hand landmarks deection results generated by `HandLandmarker`.
|
||||
*/
|
||||
export declare interface HandLandmarkerResult {
|
||||
/** Hand landmarks of detected hands. */
|
||||
landmarks: Landmark[][];
|
||||
landmarks: NormalizedLandmark[][];
|
||||
|
||||
/** Hand landmarks in world coordniates of detected hands. */
|
||||
worldLandmarks: Landmark[][];
|
||||
|
||||
Reference in New Issue
Block a user