Skip to content

Commit

Permalink
Refactor DeepBelief to use RCTCameraModule context
Browse files Browse the repository at this point in the history
  • Loading branch information
nsipplswezey committed Jan 17, 2018
1 parent 30c01f7 commit 9d357fb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
22 changes: 14 additions & 8 deletions android/src/main/java/com/lwansbrough/RCTCamera/DeepBelief.java
Expand Up @@ -19,30 +19,36 @@
import com.sun.jna.ptr.IntByReference;
import com.sun.jna.ptr.PointerByReference;

import com.facebook.react.bridge.ReactContext;
import com.facebook.react.bridge.ReactApplicationContext;

/**
* Created by nsipplswezey on 12/19/17.
*/


public class DeepBelief extends Activity {
public class DeepBelief {

public static final String TAG = "DeepBelief";
static Context ctx;
static Pointer networkHandle = null;
static Pointer predictorHandle = null;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ctx = this;

initDeepBelief();
}
// @Override
// public void onCreate(Bundle savedInstanceState) {
// super.onCreate(savedInstanceState);
// ctx = this;
//
// initDeepBelief();
// }

static void initDeepBelief() {

android.util.Log.d("DeepBelief", "Init deep belief");

ReactContext reactContext = RCTCameraModule.getReactContextSingleton();
ctx = reactContext;

AssetManager am = ctx.getAssets();
String baseFileName = "jetpac.ntwk";
String dataDir = ctx.getFilesDir().getAbsolutePath();
Expand Down
Expand Up @@ -66,8 +66,9 @@ public RCTCameraViewFinder(Context context, int type) {
this.initBarcodeReader(RCTCamera.getInstance().getBarCodeTypes());

//start Deep Belief CNN activity here...
Intent deepBeliefIntent = new Intent(context, DeepBelief.class);
context.startActivity(deepBeliefIntent);
DeepBelief.initDeepBelief();
// Intent deepBeliefIntent = new Intent(context, DeepBelief.class);
// context.startActivity(deepBeliefIntent);
}

@Override
Expand Down Expand Up @@ -336,11 +337,11 @@ protected Void doInBackground(Void... ignored) {
try {
float predictionResult = DeepBelief.classifyBitmap(bmp);

ReactContext reactContext = RCTCameraModule.getReactContextSingleton();
ReactContext reactContext = RCTCameraModule.getReactContextSingleton();
WritableMap event = Arguments.createMap();

event.putString("data", String.valueOf(predictionResult));

reactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class).emit("CameraCNNDetect", event);
} catch (Exception e) {
// meh
Expand Down

0 comments on commit 9d357fb

Please sign in to comment.