Ask Your Question

Mat to String and back in OpenCV4Android

asked 2013-05-24 04:02:12 -0600

agile gravatar image

updated 2013-05-24 04:49:26 -0600

I am doing face recognition using opencv4android and JavaCV.

I did the face detection in OpenCV and created the LBP histogram through JavaCV Face Recognizer class. Now I want to save this histogram in a database.

The histogram itself is in the Matvector type, considering I am saving the model into an xml file using the method. Then I parse the xml and take the histogram into string.

I want to use opencv4android method compareHist(Mat,Mat,int) for comparison so I need to convert this string back to Mat.

How can i do it using OpenCV4andorid?

edit retag flag offensive close merge delete


Can I ask why you would want to parse an xml file into a string, then parse it back? Basically when storing the model (I am guessing here you are talking about the LBP histogram) by using the save functionality, you can just simple load in the xml file again by using the load functionality. XML files are highly optimized for storage, so why trying to parse that?

StevenPuttemans gravatar imageStevenPuttemans ( 2013-05-24 04:52:03 -0600 )edit

I want to send the string to another application and save it in database. The application can only accept it as a string. Now I can convert it to a string by first using the getCVmat of model to extract the Matrix at specific location and then .toString() of CVmat to extract the content of matrix as string. But now I want to convert this string to OpenCV4android Mat type.

agile gravatar imageagile ( 2013-05-24 05:37:02 -0600 )edit

Then you will have to read in the data from the string, seperate it based on a seperation character and then add it manually into a matrix object. This isn't done by the openCV code, but by standard C ++ libraries.

StevenPuttemans gravatar imageStevenPuttemans ( 2013-05-24 07:30:04 -0600 )edit

yes, I am trying to split the string into string array and converting each sub string into double. After I can use the Mat.put(0,0, double) for filling the matrix. and that could be the possible solution.

agile gravatar imageagile ( 2013-05-24 08:34:43 -0600 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2013-08-18 12:47:02 -0600

agile gravatar image

I solved the problem by using the getCVmat of model to extract the Matrix at specific location and then .toString() of CVmat to extract the content of matrix as string. I save the string into database. For Matching, I retrieve the String, converted the string into float array by splitting the string and casting it to float. The values are then putted into new Matrix using Mat.put(0,0,float[]).

edit flag offensive delete link more

Question Tools


Asked: 2013-05-24 04:02:12 -0600

Seen: 1,790 times

Last updated: Aug 18 '13