-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathcvMat.bas
More file actions
130 lines (106 loc) · 2.99 KB
/
cvMat.bas
File metadata and controls
130 lines (106 loc) · 2.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
B4J=true
Group=Default Group
ModulesStructureVersion=1
Type=Class
Version=7.8
@EndOfDesignText@
Sub Class_Globals
Private fx As JFX
Private matJO As JavaObject
End Sub
'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize(params() As Object)
matJO.InitializeNewInstance("org.opencv.core.Mat",params)
End Sub
Public Sub copyTo(roi As cvMat,mask As cvMat)
matJO.RunMethod("copyTo",Array(roi.JO,mask.JO))
End Sub
Public Sub release
matJO.RunMethod("release",Null)
End Sub
Public Sub getJO As JavaObject
Return matJO
End Sub
Public Sub setJO(mat As JavaObject)
matJO=mat
End Sub
Public Sub get(indexes() As Int) As Double()
Return matJO.RunMethod("get",Array(indexes))
End Sub
Public Sub put(indexes() As Int, data() As Double) As Int
Return matJO.RunMethod("put",Array(indexes,data))
End Sub
Public Sub clone As cvMat
Return matJO2mat(matJO.RunMethodJO("clone",Null))
End Sub
Sub matJO2mat(jo As JavaObject) As cvMat
Dim mat As cvMat
mat.Initialize(Null)
mat.JO=jo
Return mat
End Sub
Sub mat2bytes As Byte()
Dim matOfByte As JavaObject
matOfByte.InitializeNewInstance("org.opencv.core.MatOfByte",Null)
'Dim bytes(Cols*Rows*Channels) As Byte
'matJO.RunMethod("get",Array(0,0,bytes))
cv2.imencode(".jpg", matJO, matOfByte)
Dim bytes() As Byte
bytes=matOfByte.RunMethod("toArray",Null)
Return bytes
End Sub
Sub mat2bytesPNG As Byte()
Dim matOfByte As JavaObject
matOfByte.InitializeNewInstance("org.opencv.core.MatOfByte",Null)
'Dim bytes(Cols*Rows*Channels) As Byte
'matJO.RunMethod("get",Array(0,0,bytes))
cv2.imencode(".png", matJO, matOfByte)
Dim bytes() As Byte
bytes=matOfByte.RunMethod("toArray",Null)
Return bytes
End Sub
Sub mat2bytesWebP(quality As Int) As Byte()
Dim matOfByte As JavaObject
matOfByte.InitializeNewInstance("org.opencv.core.MatOfByte",Null)
Dim params As JavaObject
params.InitializeNewInstance("org.opencv.core.MatOfInt",Null)
Dim imgcodecs As JavaObject
imgcodecs.InitializeStatic("org.opencv.imgcodecs.Imgcodecs")
Dim list1 As List
list1.Initialize
list1.Add(imgcodecs.GetField("IMWRITE_WEBP_QUALITY"))
list1.Add(quality)
params.RunMethod("fromList",Array(list1))
imgcodecs.RunMethod("imencode",Array(".webp", matJO, matOfByte, params))
Dim bytes() As Byte
bytes=matOfByte.RunMethod("toArray",Null)
Return bytes
End Sub
Public Sub mat2mat2f As JavaObject
Dim mat2f As JavaObject
mat2f.InitializeNewInstance("org.opencv.core.MatOfPoint2f",Array(matJO.RunMethod("toArray",Null)))
Return mat2f
End Sub
Sub Channels As Int
Return matJO.RunMethod("channels",Null)
End Sub
Sub Size As JavaObject
Return matJO.RunMethodJO("size",Null)
End Sub
Public Sub dtype As Int
Return matJO.RunMethod("type",Null)
End Sub
Sub Cols As Int
Return matJO.RunMethod("cols",Null)
End Sub
Sub Rows As Int
Return matJO.RunMethod("rows",Null)
End Sub
'cv rect
Public Sub submat(roi As JavaObject) As cvMat
Dim jo As JavaObject = matJO.RunMethod("submat",Array(roi))
Dim mat As cvMat
mat.Initialize(Null)
mat.JO = jo
Return mat
End Sub