1

I have an app that measures the distance between colored circles in live camera feed. I'm able to get the string from JNI here. Now, I want to save that string into my database but I can't make it work.

this is my db helper class:

public class DatabaseHelperUBack extends SQLiteOpenHelper {

    public static final String DATABASE_NAME="ubackrecords.db";
    public static final String TABLE_NAME="records_table";
    public static final String COL_0="ID";
    public static final String COL_1="UBack";

    public DatabaseHelperUBack(Context context) {
        super(context, DATABASE_NAME, null, 1);


    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL("create table " + TABLE_NAME + " (ID INTEGER PRIMARY KEY AUTOINCREMENT, UBack TEXT) ");
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        db.execSQL("DROP TABLE IF EXIST "+TABLE_NAME);
    }


    //public boolean insertData(String name, String date_today, String sleeve, String shoulder, String body_length, String cross_back, String bw_length, String bn_cuff, String inseam, String outseam){

    public boolean insertData(String uback){

        SQLiteDatabase db=this.getWritableDatabase();

        ContentValues contentValues = new ContentValues();
        contentValues.put(COL_1,uback);

        long result = db.insert(TABLE_NAME, null, contentValues);

        if(result == -1)
            return false;
        else
            return true;

    }

    public boolean updateData(String id, String uback){

        SQLiteDatabase db=this.getWritableDatabase();

        ContentValues contentValues = new ContentValues();
        contentValues.put(COL_0,id);
        contentValues.put(COL_1,uback);

        db.update(TABLE_NAME, contentValues, "ID = ?", new String[] { id } );

            return true;

    }

    public Cursor getAllData(){

        SQLiteDatabase db=this.getWritableDatabase();

        Cursor res = db.rawQuery("select * from "+TABLE_NAME,null);
        return res;

    }


}

I made it work on the following class but i only made it work for the ID=1 of the table. I do not know how to retrieve the last row of the table so it will be the one to be updated/replaced (because it is a live camera feed).

public class UBackTrackViewer extends SampleViewBase{


    DatabaseHelperUBack myDb;

    private Context mContext;

    private int mFrameSize;
    private Bitmap mBitmap;
    private int[] mRGBA;


    public UBackTrackViewer(Context context) {
        super(context);

        this.mContext = context;

        myDb = new DatabaseHelperUBack(mContext);
    }


    public String messageMe2(String text) {
        System.out.println(text);

        myDb.updateData("1", text);

        return text;
    }



    @Override
    public boolean onTouchEvent(MotionEvent event){

        switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:

                myDb.insertData("");


    }


    static {
        System.loadLibrary("objtrack_opencv_jnii_uback");
    }



    @Override
    protected void onPreviewStared(int previewWidtd, int previewHeight) {
        mFrameSize = previewWidtd * previewHeight;
        mRGBA = new int[mFrameSize];
        mBitmap = Bitmap.createBitmap(previewWidtd, previewHeight, Bitmap.Config.ARGB_8888);
    }


    @Override
    protected void onPreviewStopped() {
        if(mBitmap != null) {
            mBitmap.recycle();
            mBitmap = null;
        }
        mRGBA = null;

    }



    @Override
    protected Bitmap processFrame(byte[] data) {
        int[] rgba = mRGBA;

        UBackObjectTrack(getFrameWidth(), getFrameHeight(), data, rgba, LowerActivity.bShowTresholded);

        //returnUback3(getFrameWidth(), getFrameHeight(), data, rgba, LowerActivity.bShowTresholded);
       // returnUback(getFrameWidth(), getFrameHeight(), data, rgba, LowerActivity.bShowTresholded);
        //returnUback2(getFrameWidth(), getFrameHeight(), data, rgba, LowerActivity.bShowTresholded);

        Bitmap bmp = mBitmap;
        bmp.setPixels(rgba, 0/* offset */, getFrameWidth() /* stride */, 0, 0, getFrameWidth(), getFrameHeight());
        return bmp;
    }

    //public native void returnUback(int width, int height, byte yuv[], int[] rgba, boolean debug);
   // public native void returnUback2(int width, int height, byte yuv[], int[] rgba, boolean debug);
    //public native void returnUback3(int width, int height, byte yuv[], int[] rgba, boolean debug);

    public native void UBackObjectTrack(int width, int height, byte yuv[], int[] rgba, boolean debug);

    public native String UBackObjectTrack();

    static {
        System.loadLibrary("objtrack_opencv_jnii_uback");
    }
}
Community
  • 1
  • 1
alexies
  • 31
  • 6

0 Answers0