Skip to content

Instantly share code, notes, and snippets.

View tcw165's full-sized avatar
💭
building AI

TC Wang tcw165

💭
building AI
View GitHub Profile
extern "C" JNIEXPORT jbyteArray JNICALL
JNI_METHOD(detectFacesAndLandmarks)(JNIEnv *env,
jobject thiz,
jobject bitmap) {
if (sFaceDetector.num_detectors() == 0) {
LOGI("L%d: sFaceDetector is not initialized!", __LINE__);
throwException(env, "sFaceDetector is not initialized!");
return NULL;
}
if (sFaceLandmarksDetector.num_parts() == 0) {
public class FaceLandmarksDetector68 {
public FaceLandmarksDetector68() {
// Load STL library.
try {
System.loadLibrary("c++_shared");
Log.d("jni", "libc++_shared.so is loaded");
} catch (UnsatisfiedLinkError error) {
throw new RuntimeException(
"\"c++_shared\" not found; check that the correct native " +
// Activity or Fragment ::onResume
// 1. Wait for the surface ready.
mTextureView.setSurfaceTextureListener(new TextureView.SurfaceTextureListener() {
@Override
public void onSurfaceTextureAvailable(SurfaceTexture texture,
int width, int height) {
// 2. Open the camera.
manager.openCamera(
cameraId,
// Activity or Fragment ::onResume
mDisposables = new CompositeDisposable();
mDisposables.add(
grantPermission()
// Step 1, use TextureViewObservable to wait for the surface ready.
.compose(waitForTextureSurfaceReady())
// Step 2, use Camera2Observable to wait for the device opened.
.compose(openCameraToGetCameraDevice())
// Step 3, use Camera2CaptureSessionObservable and Camera2ImageReaderObservable
// to wait for the session configured.
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Transparent Window Activity -->
<style name="AppTheme.TransparentWindow" parent="AppTheme.CustomToolbar">
<!--
We want the translucent background painted by the root layout instead
of painted by the window.
-->
<item name="android:windowIsTranslucent">true</item>
// Hold the disposable in order to cancel the operation later.
val sharingDisposable = mView
.onClickStart()
.switchMap { _ ->
// 1. Generate BMP
getGenBmpObservable()
// 2. Show dialog
.switchMap { _ ->
getDialogSingle().toObservable()
}
private val mDisposablesOnCreate = CompositeDisposable()
private val INTENT_OF_DO_SOMETHING = 0
private val INTENT_OF_CANCEL_EVERYTHING = 1
// Activity onCreate().
override fun onCreate() {
// Share and cancel input:
//
// start +
private fun toShareAction(): Observable<ShareProgressState> {
// 1. Generate BMP
return getGenBmpObservable()
// 2. Show dialog
.switchMap { _ ->
getDialogSingle()
.toObservable()
}
// 3. Share
.switchMap { dialogPayload ->
// This is the snippet of SwitchMapObserver code.
// 1. The inner observer #1 's onNext, this function is called when it
// receives the data from upstream.
@Override
public void onNext(T t) {
long c = unique + 1;
unique = c;
// 2. Cancel (dispose) the given Observable from your mapper funtion.
public int largestRectanglularAreaInHistogram(int[] hist) {
int maxArea = 0;
// Iterate through the histogram.
for (int i = 0; i < hist.length; ++i) {
int h = hist[i];
maxArea = Math.max(maxArea, h);
for (int j = i - 1; j >= 0; --j) {