Class OpenCVTypeAdapters

java.lang.Object
qupath.opencv.io.OpenCVTypeAdapters

public class OpenCVTypeAdapters extends Object
Helper classes for combining OpenCV's JSON serialization with Gson's.

Sample use:

 Gson gson = new GsonBuilder()
                                .registerTypeAdapterFactory(OpenCVTypeAdapters.getOpenCVTypeAdaptorFactory())
                                .setPrettyPrinting()
                                .create();
 
 Mat mat1 = Mat.eye(3, 3, CV_32F1).asMat();
 String json = gson.toJson(mat1);
 Mat mat2 = gson.fromJson(json, Mat.class);
 
Author:
Pete Bankhead
  • Constructor Details

    • OpenCVTypeAdapters

      public OpenCVTypeAdapters()
  • Method Details

    • getOpenCVTypeAdaptorFactory

      public static TypeAdapterFactory getOpenCVTypeAdaptorFactory()
      Get a TypeAdapterFactory to pass to a GsonBuilder to aid with serializing OpenCV objects (e.g. Mat, StatModel).
      Returns:
    • getTypeAdaptor

      public static <T> TypeAdapter<T> getTypeAdaptor(Class<T> cls)
      Get a TypeAdapter to pass to a GsonBuilder for a specific supported OpenCV class, i.e. Mat, SparseMat or StatModel.
      Parameters:
      cls -
      Returns:
      the required TypeAdaptor, or null if no supported adapter is available for the class.