import Globals from "./Globals";
import { MountFileWithProgress } from "./Utility/MountFileWithProgress";
/**
* Provides light conditions estimation functionality.
* To enable this module pass the ShadeFinder license to the SDKProvider.
*/
export class LightConditionsAnalyzer {
static async Create(modulesManager, uniformityThreshold, backlightThreshold, onProgress) {
const bsc = modulesManager.modules.visage.module;
await bsc.MountFile("Light Conditions.cfg", Globals.pathToAssets + "Assets/Plugins/Light Conditions.cfg");
const uniformity = uniformityThreshold;
const backlight = backlightThreshold;
if (onProgress) {
onProgress({
contentLength: 0,
receivedLength: 0,
progress: 1,
done: true,
});
}
const bscAnalyzer = bsc.GetLightConditionsAnalysis("Light Conditions.cfg", uniformity, backlight);
return new LightConditionsAnalyzer(bscAnalyzer, bsc, uniformity, backlight);
}
constructor(bscAnalyzer, bsc, uniformityThreshold, backlightThreshold) {
this.bscAnalyzer = bscAnalyzer;
this.bsc = bsc;
this.uniformityThreshold = uniformityThreshold
this.backlightThreshold = backlightThreshold
}
/**
*@callback LightConditionsCallback
*@param {Object} LightConditionsAnalyzerResult - Analyzed light conditions
*@param {float} LightConditionsAnalyzerResult.hasNoBacklight - Boolean value indicating the presence or absence of backlight in the analyzed image.
*@param {float} LightConditionsAnalyzerResult.hasNoBacklightProbability - float value ranging from 0-1 representing model's confidence that backlight is present in the image.
*@param {boolean} LightConditionsAnalyzerResult.isFaceUniformlyLit - Boolean value indicating whether the face in the image is uniformly lit.
*@param {boolean} LightConditionsAnalyzerResult.isFaceUniformlyLitProbability - float value ranging from 0-1 representing model's confidence that the face in the image is uniformly lit.
*@param {number} LightConditionsAnalyzerResult.frameIndex - Index of the frame that has been analyzed.
*/
/**
* Initiates the light conditions analysis. When a frame has been analyzed a call to the {@link LightConditionsCallback}
* function is issued, with the analysis results passed as the argument.
* <br/>
* @param {LightConditionsCallback} LightConditionsCallback - callback which will be called every time a new frame is analyzed
*/
StartAnalysis(LightConditionsCallback) {
this.bscAnalyzer.SetCallback(LightConditionsCallback);
this.bscAnalyzer.StartAnalysis();
}
/**
* Stops the light conditions analysis and stops issuing calls to the callback given as a argument to the
* {@link StartAnalysis} function.
* <br/>
*/
StopAnalysis() {
this.bscAnalyzer.StopAnalysis();
}
/**
* Resets the internal state of the light conditions analyzer. This is useful when switching between frames of different people.
*/
Reset() {
this.bscAnalyzer.Reset();
}
}