Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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 {

}

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 {

}

but i get this errorerror The error is most probably in the line refKeypoints.get(0, 0, data); how to rectify it?

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 {

}

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 {

}

but i get this errorerror The error is most probably in the line refKeypoints.get(0, 0, data); how to rectify it?

click to hide/show revision 3
None

updated 2018-03-25 05:37:30 -0600

berak gravatar image

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 {

}

but i get this errorerror The error is most probably in the line refKeypoints.get(0, 0, data); how to rectify it?