Sub MatToJSON(myMat As OCVMat) As String
Dim size As Long = myMat.cols * myMat.rows * myMat.elemSize
Dim b(size) As Byte
myMat.get(0, 0, b)
Dim m As Map
m.Initialize
m.Put("rows", myMat.rows)
m.Put("cols", myMat.cols)
m.Put("type", myMat.type)
Dim dataString As String = su.EncodeBase64(b) 'StringUtils
m.Put("data", dataString)
Dim jg As JSONGenerator
jg.Initialize(m)
Return jg.ToString
End Sub
Sub MatFromJSON(jsonMAT As String) As OCVMat
Dim jp As JSONParser
jp.Initialize(jsonMAT)
Dim m As Map = jp.NextObject
Dim cols As Int = m.Get("cols")
Dim rows As Int = m.Get("rows")
Dim typ As Int = m.Get("type")
Dim dataString As String = m.Get("data").As(String)
Dim b() As Byte = su.DecodeBase64(dataString)
Dim myMat As OCVMat
myMat.Initialize2(rows, cols, typ)
myMat.put4(0, 0, b)
Return myMat
End Sub