2022-08-09 12:22:18 +00:00
|
|
|
import ReducerRegistry from '../base/redux/ReducerRegistry';
|
2021-11-17 14:33:03 +00:00
|
|
|
|
|
|
|
import {
|
2022-11-22 13:56:37 +00:00
|
|
|
ADD_FACE_LANDMARKS,
|
|
|
|
CLEAR_FACE_LANDMARKS_BUFFER,
|
2022-04-04 13:09:14 +00:00
|
|
|
UPDATE_FACE_COORDINATES
|
2021-11-17 14:33:03 +00:00
|
|
|
} from './actionTypes';
|
2022-11-22 13:56:37 +00:00
|
|
|
import { FaceBox, FaceLandmarks } from './types';
|
2021-11-17 14:33:03 +00:00
|
|
|
|
|
|
|
const defaultState = {
|
2022-04-04 13:09:14 +00:00
|
|
|
faceBoxes: {},
|
2022-11-22 13:56:37 +00:00
|
|
|
faceLandmarks: [],
|
|
|
|
faceLandmarksBuffer: [],
|
2021-11-17 14:33:03 +00:00
|
|
|
recognitionActive: false
|
|
|
|
};
|
|
|
|
|
2022-08-09 12:22:18 +00:00
|
|
|
export interface IFaceLandmarksState {
|
2022-09-14 12:42:46 +00:00
|
|
|
faceBoxes: { [key: string]: FaceBox; };
|
2022-11-22 13:56:37 +00:00
|
|
|
faceLandmarks: Array<FaceLandmarks>;
|
|
|
|
faceLandmarksBuffer: Array<{
|
2022-08-09 12:22:18 +00:00
|
|
|
emotion: string;
|
2022-11-22 13:56:37 +00:00
|
|
|
timestamp: number;
|
2022-08-09 12:22:18 +00:00
|
|
|
}>;
|
|
|
|
recognitionActive: boolean;
|
|
|
|
}
|
|
|
|
|
2022-09-05 09:05:07 +00:00
|
|
|
ReducerRegistry.register<IFaceLandmarksState>('features/face-landmarks',
|
|
|
|
(state = defaultState, action): IFaceLandmarksState => {
|
2021-11-17 14:33:03 +00:00
|
|
|
switch (action.type) {
|
2022-11-22 13:56:37 +00:00
|
|
|
case ADD_FACE_LANDMARKS: {
|
|
|
|
const { addToBuffer, faceLandmarks }: { addToBuffer: boolean; faceLandmarks: FaceLandmarks; } = action;
|
|
|
|
|
2021-12-21 11:46:54 +00:00
|
|
|
return {
|
|
|
|
...state,
|
2022-11-22 13:56:37 +00:00
|
|
|
faceLandmarks: [ ...state.faceLandmarks, faceLandmarks ],
|
|
|
|
faceLandmarksBuffer: addToBuffer ? [ ...state.faceLandmarksBuffer,
|
|
|
|
{
|
|
|
|
emotion: faceLandmarks.faceExpression,
|
|
|
|
timestamp: faceLandmarks.timestamp
|
|
|
|
} ] : state.faceLandmarksBuffer
|
2021-12-21 11:46:54 +00:00
|
|
|
};
|
|
|
|
}
|
2022-11-22 13:56:37 +00:00
|
|
|
case CLEAR_FACE_LANDMARKS_BUFFER: {
|
2021-12-21 11:46:54 +00:00
|
|
|
return {
|
|
|
|
...state,
|
2022-11-22 13:56:37 +00:00
|
|
|
faceLandmarksBuffer: []
|
2021-12-21 11:46:54 +00:00
|
|
|
};
|
|
|
|
}
|
2022-04-04 13:09:14 +00:00
|
|
|
case UPDATE_FACE_COORDINATES: {
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
faceBoxes: {
|
|
|
|
...state.faceBoxes,
|
|
|
|
[action.id]: action.faceBox
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
2021-11-17 14:33:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return state;
|
|
|
|
});
|