android - Convert Mat to Blob and then back to Mat -
android - Convert Mat to Blob and then back to Mat -
basically tring face recognition using opencv android need convert mat image received during face detection via inputframe.gray(); in cvcameraviewframe blob byte[] save sqlite database , while recognition convert byte[] mat file can used in .cpp files in jni folder recognition code native.
[edit] it turned out quite easy androids onboard methods: import org.opencv.core.mat; import android.content.context; import android.content.contentvalues; import android.database.cursor; import android.database.sqlite.sqlitedatabase; import android.database.sqlite.sqlitedatabase.cursorfactory; import android.database.sqlite.sqliteopenhelper; class sqtable extends sqliteopenhelper { string table = "mydb"; public sqltable(context context, string name, cursorfactory factory, int version) { super(context, name, factory, version); } @override public void oncreate(sqlitedatabase db) { db.execsql("create table "+table+" (name text unique, t integer, w integer, h integer, pix blob);"); } @override public void onupgrade(sqlitedatabase arg0, int arg1, int arg2) { } public void dbput(string name, mat m) { long nbytes = m.total() * m.elemsize(); byte[] bytes = new byte[ (int)nbytes ]; m.get(0, 0,bytes); dbput(name, m.type(), m.cols(), m.rows(), bytes); } public void dbput(string name, int t, int w, int h, byte[] bytes) { log.d("dbput", name + " " + t + " " + w + "x" + h); sqlitedatabase db = this.getwritabledatabase(); contentvalues values = new contentvalues(); values.put("name", name); values.put("t", t); values.put("w", w); values.put("h", h); values.put("pix", bytes); db.insert(table, null, values); db.close(); } public mat dbget(string name) { sqlitedatabase db = this.getreadabledatabase(); string [] columns = {"t","w","h","pix"}; cursor cursor = db.query(table,columns," name = ?", new string[] { name }, // d. selections args null, // e. grouping null, // f. having null, // g. order null); // h. limit if (cursor != null) cursor.movetofirst(); int t = cursor.getint(0); int w = cursor.getint(1); int h = cursor.getint(2); byte[] p = cursor.getblob(3); mat m = new mat(h,w,t); m.put(0,0,p); log.d("dbget("+name+")", m.tostring()); homecoming m; } }; // later utilize in activity: sqltable sql = new sqltable(this,"imgs",null,1); mat m = new mat(200,400, cvtype.cv_8uc3,new scalar(0,100,0)); core.puttext(m, "world (~)", new point(30,80), core.font_hershey_script_simplex, 2.2, new scalar(200,200,200)); sql.dbput("hello",m); // mat m = sql.dbget("hello");
android c++ opencv face-recognition mat
Comments
Post a Comment