Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SP-11788 - fix detection model through extra types #76

Merged
merged 1 commit into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 85 additions & 0 deletions src/ext/extra-types/match-detection-types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import { DetectionQuality, FaceQualityScenarios, FaceSDKResult, ImageData } from "../../models";

type TDetection = {
/**
*
* @type {ImageData}
* @memberof Detection
*/
'crop'?: ImageData;
/**
*
* @memberof Detection
*/
'attributes'?: {
/**
*
* @type {Array<{ name?: string; confidence?: number; value?: any; }>}
*/
'details'?: { name?: string; confidence?: number; value?: any; }[];
/**
* The elapsed time for attribute detection.
* @type {number}
*/
'elapsedTime'?: number;
};
/**
* Absolute coordinates (x,y) of five points of each detected face: left eye, right eye, nose, left point of lips, right point of lips.
* @type {Array<Array<number>>}
* @memberof Detection
*/
'landmarks': Array<Array<number>>;
/**
*
* @type {DetectionQuality}
* @memberof Detection
*/
'quality'?: DetectionQuality;
/**
* The rectangular area of a detected face that is represented by a set of four elements: the X and Y coordinates of the top-left point, and the width and height dimensions of the rectangle.
* @type {Array<number>}
* @memberof Detection
*/
'roi': Array<number>;
/**
* Base64 of the cropped portrait.
* @type {string}
* @memberof Detection
*/
'thumbnail'?: string;
}

export type TDetectResponse = {
results?: {
/**
*
* @type {Array<Detection>}
* @memberof DetectResult
*/
'detections': Array<TDetection>;
/**
* Internal.
* @type {number}
* @memberof DetectResult
*/
'detectorType'?: number;
/**
* Internal.
* @type {number}
* @memberof DetectResult
*/
'landmarksType'?: number;
/**
*
* @type {FaceQualityScenarios}
* @memberof DetectResult
*/
'scenario'?: FaceQualityScenarios;
/**
* The total time taken for the detection.
* @type {number}
* @memberof DetectResult
*/
'timer'?: number;
}
} & FaceSDKResult;
7 changes: 4 additions & 3 deletions src/ext/matching-api.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { MatchingApi as GenMatchingApi } from '../api/matching-api';
import { MatchRequest, DetectRequest, ImageSource, MatchResponse, DetectResponse } from '../models';
import { MatchRequest, DetectRequest, ImageSource, MatchResponse } from '../models';
import { AxiosRequestConfig, AxiosInstance } from 'axios';
import { Configuration } from '../configuration';
import * as converter from 'base64-arraybuffer';
import { TDetectResponse } from './extra-types/match-detection-types';

export class MatchingApi {
private superClass: GenMatchingApi;
Expand Down Expand Up @@ -30,12 +31,12 @@ export class MatchingApi {
detectRequest: DetectRequest,
xRequestID?: string,
options?: AxiosRequestConfig,
): Promise<DetectResponse> {
): Promise<TDetectResponse> {
if (detectRequest.image && typeof detectRequest.image !== 'string') {
detectRequest.image = converter.encode(detectRequest.image);
}

const response = await this.superClass.detect(detectRequest, xRequestID, options);
return response.data;
return response.data as TDetectResponse;
}
}
1 change: 1 addition & 0 deletions src/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export * from './group-page';
export * from './group-page-all-of';
export * from './group-to-create';
export * from './image';
export * from './image-data';
export * from './image-fields';
export * from './image-fields-image';
export * from './image-page';
Expand Down