2022-08-09 12:22:18 +00:00
|
|
|
import ReducerRegistry from '../base/redux/ReducerRegistry';
|
2021-11-17 14:33:03 +00:00
|
|
|
|
|
|
|
import {
|
2022-04-06 09:10:31 +00:00
|
|
|
ADD_FACE_EXPRESSION,
|
|
|
|
ADD_TO_FACE_EXPRESSIONS_BUFFER,
|
|
|
|
CLEAR_FACE_EXPRESSIONS_BUFFER,
|
2022-04-04 13:09:14 +00:00
|
|
|
UPDATE_FACE_COORDINATES
|
2021-11-17 14:33:03 +00:00
|
|
|
} from './actionTypes';
|
2022-09-14 12:42:46 +00:00
|
|
|
import { FaceBox } from './types';
|
2021-11-17 14:33:03 +00:00
|
|
|
|
|
|
|
const defaultState = {
|
2022-04-04 13:09:14 +00:00
|
|
|
faceBoxes: {},
|
2022-04-06 09:10:31 +00:00
|
|
|
faceExpressions: {
|
2021-11-17 14:33:03 +00:00
|
|
|
happy: 0,
|
|
|
|
neutral: 0,
|
|
|
|
surprised: 0,
|
|
|
|
angry: 0,
|
|
|
|
fearful: 0,
|
|
|
|
disgusted: 0,
|
|
|
|
sad: 0
|
|
|
|
},
|
2022-04-06 09:10:31 +00:00
|
|
|
faceExpressionsBuffer: [],
|
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-08-09 12:22:18 +00:00
|
|
|
faceExpressions: {
|
|
|
|
angry: number;
|
|
|
|
disgusted: number;
|
|
|
|
fearful: number;
|
|
|
|
happy: number;
|
|
|
|
neutral: number;
|
|
|
|
sad: number;
|
|
|
|
surprised: number;
|
|
|
|
};
|
|
|
|
faceExpressionsBuffer: Array<{
|
|
|
|
emotion: string;
|
|
|
|
timestamp: string;
|
|
|
|
}>;
|
|
|
|
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-04-06 09:10:31 +00:00
|
|
|
case ADD_FACE_EXPRESSION: {
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
faceExpressions: {
|
|
|
|
...state.faceExpressions,
|
2022-08-09 12:22:18 +00:00
|
|
|
[action.faceExpression]: state.faceExpressions[
|
|
|
|
action.faceExpression as keyof typeof state.faceExpressions] + action.duration
|
2022-04-06 09:10:31 +00:00
|
|
|
}
|
|
|
|
};
|
2021-11-17 14:33:03 +00:00
|
|
|
}
|
2022-04-06 09:10:31 +00:00
|
|
|
case ADD_TO_FACE_EXPRESSIONS_BUFFER: {
|
2021-12-21 11:46:54 +00:00
|
|
|
return {
|
|
|
|
...state,
|
2022-04-06 09:10:31 +00:00
|
|
|
faceExpressionsBuffer: [ ...state.faceExpressionsBuffer, action.faceExpression ]
|
2021-12-21 11:46:54 +00:00
|
|
|
};
|
|
|
|
}
|
2022-04-06 09:10:31 +00:00
|
|
|
case CLEAR_FACE_EXPRESSIONS_BUFFER: {
|
2021-12-21 11:46:54 +00:00
|
|
|
return {
|
|
|
|
...state,
|
2022-04-06 09:10:31 +00:00
|
|
|
faceExpressionsBuffer: []
|
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;
|
|
|
|
});
|