error while converting MatOfKeyPoints to json string
i am trying to convert a MatOfKeyPoints object in opencv android to json string .
MatOfKeyPoint refKeypoints = new MatOfKeyPoint();
Mat refDescriptors = new Mat();
FeatureDetector orbFeatureDetector = FeatureDetector.create(FeatureDetector.ORB);
orbFeatureDetector.detect(grayMat, refKeypoints);
Mat Out = new Mat();
DescriptorExtractor descriptorExtractor = DescriptorExtractor.create(DescriptorExtractor.ORB);
descriptorExtractor.compute(grayMat, refKeypoints, refDescriptors);
Features2d.drawKeypoints(grayMat, refKeypoints, Out,new Scalar(2,254,255),Features2d.DRAW_RICH_KEYPOINTS);
//System.out.println(refKeypoints);
Utils.matToBitmap(Out,grayBitmap);
imageView.setImageBitmap(grayBitmap);
JsonObject obj = new JsonObject();
if(refKeypoints.isContinuous()){
int cols = refKeypoints.cols();
int rows = refKeypoints.rows();
int elemSize = (int) refKeypoints.elemSize();
byte[] data = new byte[cols * rows * elemSize];
refKeypoints.get(0, 0, data);
obj.addProperty("rows", refKeypoints.rows());
obj.addProperty("cols", refKeypoints.cols());
obj.addProperty("type", refKeypoints.type());
// We cannot set binary data to a json object, so:
// Encoding data byte array to Base64.
String dataString = new String(Base64.encode(data, Base64.DEFAULT));
obj.addProperty("data", dataString);
Gson gson = new Gson();
String json = gson.toJson(obj);
} else {
}
The error is most probably in the line refKeypoints.get(0, 0, data); how to rectify it?
i removed your screenshot.
please edit your question, and add the resp. information as text
what is the purpose of it ? do you really need the whole keypoint infpormation ?
you can't use
byte
here. try something like:i need to save the whole keypoints information in database . for that reason i need to convert into json string . how to do it?
why do you need to save the keypoints ? what are you trying to do with that ?
databases like sqlite do support binary blobs, no need for json or base64.
i have a main server running with python . the android devices need to process an image to find keypoints and send it back to python server .so i need to convert keypoints to json