Install
- Download
nosmai-camera-sdk-android.aarfrom the Android SDK repository. - Put it in your app module's
libs/folder. - Reference it in Gradle, along with CameraX:
dependencies {
implementation files('libs/nosmai-camera-sdk-android.aar')
implementation 'androidx.camera:camera-core:1.3.0'
implementation 'androidx.camera:camera-camera2:1.3.0'
implementation 'androidx.camera:camera-lifecycle:1.3.0'
implementation 'androidx.camera:camera-view:1.3.0'
}
Requirements: Android API 26+ (Android 8.0+), arm64, Camera2 API, OpenGL ES 3.0.
Permissions (AndroidManifest.xml):
<uses-permission android:name="android.permission.CAMERA" /> <uses-permission android:name="android.permission.RECORD_AUDIO" /> <uses-permission android:name="android.permission.INTERNET" />
Initialize
NosmaiSDK.initialize(this, "YOUR_LICENSE_KEY");
Camera preview
Add a NosmaiPreviewView, start processing, then feed it camera frames with Camera2Helper.
NosmaiPreviewView previewView = new NosmaiPreviewView(this); FrameLayout container = findViewById(R.id.preview_container); container.addView(previewView); NosmaiSDK.startProcessing(previewView); boolean front = true; Camera2Helper camera2Helper = new Camera2Helper(this, front); previewView.setCameraOrientation(front, camera2Helper.getSensorOrientation()); NosmaiSDK.setCameraFacing(front); camera2Helper.startCamera();
Wire the Camera2 frame callback to the preview view (see the demo app for the full Camera2 setup). Switch cameras with NosmaiSDK.setCameraFacing(boolean).
Lifecycle
@Override protected void onResume() {
super.onResume();
previewView.onResume();
NosmaiSDK.startProcessing(previewView);
camera2Helper.startCamera();
}
@Override protected void onPause() {
super.onPause();
previewView.onPause();
NosmaiSDK.stopProcessing();
camera2Helper.stopCamera();
}
@Override protected void onDestroy() {
super.onDestroy();
NosmaiEffects.cleanup();
NosmaiSDK.cleanup();
camera2Helper.stopCamera();
}
Beauty and color
Beauty intensities are 0.0 to 1.0.
NosmaiBeauty.applySkinSmoothing(0.7f); NosmaiBeauty.applySkinWhitening(0.5f); NosmaiBeauty.applyFaceSlimming(0.3f); NosmaiBeauty.applyEyeEnlargement(0.4f); NosmaiBeauty.applyBrightness(0.2f); // -1.0 to 1.0 NosmaiBeauty.applyContrast(1.2f); // 0.0 to 2.0 NosmaiBeauty.removeAllBeautyFilters();
Filters
// List all filters (grouped into "local" and "cloud")
Map<String, List<Map<String, Object>>> filters = NosmaiEffects.getFilters();
// Apply a local filter or effect
NosmaiEffects.applyEffect("filters/vintage.nosmai", new NosmaiEffects.EffectCallback() {
@Override public void onSuccess() { }
@Override public void onError(String message) { }
});
// Remove the current effect
NosmaiEffects.removeEffect(callback);
// Adjustable parameters for the current effect
List<Map<String, Object>> params = NosmaiEffects.getEffectParameters();
NosmaiEffects.setEffectParameter("intensity", 0.8f);
Put local .nosmai files in app/src/main/assets/filters/.
Cloud filters.
if (NosmaiCloud.isEnabled()) {
NosmaiCloud.download("halloween_2024", new NosmaiCloud.DownloadCallback() {
@Override public void onComplete(String id, boolean success, String localPath, String error) {
if (success) NosmaiEffects.applyEffect(localPath, effectCallback);
}
});
}
Recording
NosmaiSDK.startRecording(previewView, outputPath, new RecordingCallback() {
@Override public void onStarted(boolean success, String error) { }
@Override public void onCompleted(String outputPath, boolean success, String error) { }
});
NosmaiSDK.stopRecording(recordingCallback);
[!NOTE] Test on a physical arm64 device with Camera2 support. Emulators and devices without Camera2 are not supported.