Package qupath.opencv.io
Class OpenCVTypeAdapters
java.lang.Object
qupath.opencv.io.OpenCVTypeAdapters
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
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
TypeAdapter that helps include OpenCV-based objects within a Java object being serialized to JSON.static class
TypeAdapterFactory that helps make OpenCV's serialization methods more compatible with custom JSON/Gson serialization. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic TypeAdapterFactory
Get a TypeAdapterFactory to pass to a GsonBuilder to aid with serializing OpenCV objects (e.g.static <T> TypeAdapter
<T> getTypeAdaptor
(Class<T> cls) Get a TypeAdapter to pass to a GsonBuilder for a specific supported OpenCV class, i.e.
-
Constructor Details
-
OpenCVTypeAdapters
public OpenCVTypeAdapters()
-
-
Method Details
-
getOpenCVTypeAdaptorFactory
Get a TypeAdapterFactory to pass to a GsonBuilder to aid with serializing OpenCV objects (e.g. Mat, StatModel).- Returns:
-
getTypeAdaptor
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.
-