dynamsoft-capture-vision-bundle 3.4.1000__cp314-cp314-win_amd64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- dynamsoft_capture_vision_bundle/ConfusableChars.data +0 -0
- dynamsoft_capture_vision_bundle/DynamicPdfx64.dll +0 -0
- dynamsoft_capture_vision_bundle/DynamsoftBarcodeReaderx64.dll +0 -0
- dynamsoft_capture_vision_bundle/DynamsoftCaptureVisionRouterx64.dll +0 -0
- dynamsoft_capture_vision_bundle/DynamsoftCodeParserDedicatorx64.dll +0 -0
- dynamsoft_capture_vision_bundle/DynamsoftCodeParserx64.dll +0 -0
- dynamsoft_capture_vision_bundle/DynamsoftCorex64.dll +0 -0
- dynamsoft_capture_vision_bundle/DynamsoftDocumentNormalizerx64.dll +0 -0
- dynamsoft_capture_vision_bundle/DynamsoftIdentityUtilityx64.dll +0 -0
- dynamsoft_capture_vision_bundle/DynamsoftImageProcessingx64.dll +0 -0
- dynamsoft_capture_vision_bundle/DynamsoftLabelRecognizerx64.dll +0 -0
- dynamsoft_capture_vision_bundle/DynamsoftLicensex64.dll +0 -0
- dynamsoft_capture_vision_bundle/DynamsoftNeuralNetworkx64.dll +0 -0
- dynamsoft_capture_vision_bundle/DynamsoftUtilityx64.dll +0 -0
- dynamsoft_capture_vision_bundle/Models/Code128Decoder.data +0 -0
- dynamsoft_capture_vision_bundle/Models/Code39ITFDecoder.data +0 -0
- dynamsoft_capture_vision_bundle/Models/DataMatrixQRCodeDeblur.data +0 -0
- dynamsoft_capture_vision_bundle/Models/DataMatrixQRCodeLocalization.data +0 -0
- dynamsoft_capture_vision_bundle/Models/EAN13Decoder.data +0 -0
- dynamsoft_capture_vision_bundle/Models/LetterCharRecognition.data +0 -0
- dynamsoft_capture_vision_bundle/Models/LowercaseCharRecognition.data +0 -0
- dynamsoft_capture_vision_bundle/Models/MRZCharRecognition.data +0 -0
- dynamsoft_capture_vision_bundle/Models/MRZLocalization.data +0 -0
- dynamsoft_capture_vision_bundle/Models/MRZTextLineRecognition.data +0 -0
- dynamsoft_capture_vision_bundle/Models/NumberCharRecognition.data +0 -0
- dynamsoft_capture_vision_bundle/Models/NumberLetterCharRecognition.data +0 -0
- dynamsoft_capture_vision_bundle/Models/NumberLowercaseCharRecognition.data +0 -0
- dynamsoft_capture_vision_bundle/Models/NumberUppercaseCharRecognition.data +0 -0
- dynamsoft_capture_vision_bundle/Models/OneDDeblur.data +0 -0
- dynamsoft_capture_vision_bundle/Models/OneDLocalization.data +0 -0
- dynamsoft_capture_vision_bundle/Models/PDF417Deblur.data +0 -0
- dynamsoft_capture_vision_bundle/Models/PDF417Localization.data +0 -0
- dynamsoft_capture_vision_bundle/Models/UppercaseCharRecognition.data +0 -0
- dynamsoft_capture_vision_bundle/Models/VINCharRecognition.data +0 -0
- dynamsoft_capture_vision_bundle/OverlappingChars.data +1 -0
- dynamsoft_capture_vision_bundle/ParserResources/AADHAAR.data +0 -0
- dynamsoft_capture_vision_bundle/ParserResources/AAMVA_DL_ID.data +1 -0
- dynamsoft_capture_vision_bundle/ParserResources/GS1_AI.data +66 -0
- dynamsoft_capture_vision_bundle/ParserResources/MRTD.data +1 -0
- dynamsoft_capture_vision_bundle/ParserResources/SOUTH_AFRICA_DL.data +1 -0
- dynamsoft_capture_vision_bundle/ParserResources/VIN.data +0 -0
- dynamsoft_capture_vision_bundle/Templates/DBR-PresetTemplates.json +546 -0
- dynamsoft_capture_vision_bundle/Templates/DDN-PresetTemplates.json +316 -0
- dynamsoft_capture_vision_bundle/Templates/DLR-PresetTemplates.json +471 -0
- dynamsoft_capture_vision_bundle/Templates/DriverLicenseScanner.json +94 -0
- dynamsoft_capture_vision_bundle/Templates/MRZScanner.json +804 -0
- dynamsoft_capture_vision_bundle/Templates/VINScanner.json +299 -0
- dynamsoft_capture_vision_bundle/_DynamsoftBarcodeReader.cp314-win_amd64.pyd +0 -0
- dynamsoft_capture_vision_bundle/_DynamsoftCaptureVisionRouter.cp314-win_amd64.pyd +0 -0
- dynamsoft_capture_vision_bundle/_DynamsoftCodeParser.cp314-win_amd64.pyd +0 -0
- dynamsoft_capture_vision_bundle/_DynamsoftCodeParserDedicator.cp314-win_amd64.pyd +0 -0
- dynamsoft_capture_vision_bundle/_DynamsoftCore.cp314-win_amd64.pyd +0 -0
- dynamsoft_capture_vision_bundle/_DynamsoftDocumentNormalizer.cp314-win_amd64.pyd +0 -0
- dynamsoft_capture_vision_bundle/_DynamsoftIdentityUtility.cp314-win_amd64.pyd +0 -0
- dynamsoft_capture_vision_bundle/_DynamsoftImageProcessing.cp314-win_amd64.pyd +0 -0
- dynamsoft_capture_vision_bundle/_DynamsoftLabelRecognizer.cp314-win_amd64.pyd +0 -0
- dynamsoft_capture_vision_bundle/_DynamsoftLicense.cp314-win_amd64.pyd +0 -0
- dynamsoft_capture_vision_bundle/_DynamsoftUtility.cp314-win_amd64.pyd +0 -0
- dynamsoft_capture_vision_bundle/__init__.py +13 -0
- dynamsoft_capture_vision_bundle/core.py +2785 -0
- dynamsoft_capture_vision_bundle/cvr.py +1347 -0
- dynamsoft_capture_vision_bundle/dbr.py +1223 -0
- dynamsoft_capture_vision_bundle/dcp.py +208 -0
- dynamsoft_capture_vision_bundle/dcpd.py +21 -0
- dynamsoft_capture_vision_bundle/ddn.py +985 -0
- dynamsoft_capture_vision_bundle/dip.py +24 -0
- dynamsoft_capture_vision_bundle/dlr.py +1136 -0
- dynamsoft_capture_vision_bundle/id_utility.py +98 -0
- dynamsoft_capture_vision_bundle/license.py +146 -0
- dynamsoft_capture_vision_bundle/utility.py +835 -0
- dynamsoft_capture_vision_bundle-3.4.1000.dist-info/METADATA +89 -0
- dynamsoft_capture_vision_bundle-3.4.1000.dist-info/RECORD +75 -0
- dynamsoft_capture_vision_bundle-3.4.1000.dist-info/WHEEL +5 -0
- dynamsoft_capture_vision_bundle-3.4.1000.dist-info/licenses/LICENSE.txt +1 -0
- dynamsoft_capture_vision_bundle-3.4.1000.dist-info/top_level.txt +12 -0
|
@@ -0,0 +1,835 @@
|
|
|
1
|
+
__version__ = "2.0.40.7449"
|
|
2
|
+
|
|
3
|
+
if __package__ or "." in __name__:
|
|
4
|
+
from .cvr import *
|
|
5
|
+
else:
|
|
6
|
+
from cvr import *
|
|
7
|
+
|
|
8
|
+
if __package__ or "." in __name__:
|
|
9
|
+
from .core import *
|
|
10
|
+
else:
|
|
11
|
+
from core import *
|
|
12
|
+
|
|
13
|
+
if __package__ or "." in __name__:
|
|
14
|
+
from . import _DynamsoftUtility
|
|
15
|
+
else:
|
|
16
|
+
import _DynamsoftUtility
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
from abc import ABC, abstractmethod
|
|
20
|
+
from typing import List, Tuple, Union
|
|
21
|
+
from enum import IntEnum
|
|
22
|
+
|
|
23
|
+
class FilterType(IntEnum):
|
|
24
|
+
FT_HIGH_PASS = _DynamsoftUtility.FT_HIGH_PASS
|
|
25
|
+
FT_SHARPEN = _DynamsoftUtility.FT_SHARPEN
|
|
26
|
+
FT_SMOOTH = _DynamsoftUtility.FT_SMOOTH
|
|
27
|
+
|
|
28
|
+
class UtilityModule:
|
|
29
|
+
"""
|
|
30
|
+
The UtilityModule class contains utility functions.
|
|
31
|
+
|
|
32
|
+
Methods:
|
|
33
|
+
get_version() -> str: Returns the version of the utility module.
|
|
34
|
+
"""
|
|
35
|
+
_thisown = property(
|
|
36
|
+
lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag"
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
@staticmethod
|
|
40
|
+
def get_version() -> str:
|
|
41
|
+
"""
|
|
42
|
+
Returns the version of the utility module.
|
|
43
|
+
|
|
44
|
+
Returns:
|
|
45
|
+
A string representing the version of the utility module.
|
|
46
|
+
"""
|
|
47
|
+
return __version__ + " (Algorithm " + _DynamsoftUtility.CUtilityModule_GetVersion() + ")"
|
|
48
|
+
|
|
49
|
+
def __init__(self):
|
|
50
|
+
_DynamsoftUtility.Class_init(
|
|
51
|
+
self, _DynamsoftUtility.new_CUtilityModule()
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
__destroy__ = _DynamsoftUtility.delete_CUtilityModule
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
_DynamsoftUtility.CUtilityModule_register(UtilityModule)
|
|
58
|
+
|
|
59
|
+
class MultiFrameResultCrossFilter(CapturedResultFilter):
|
|
60
|
+
"""
|
|
61
|
+
The MultiFrameResultCrossFilter class is responsible for filtering captured results.
|
|
62
|
+
It contains several callback functions for different types of results, including raw image, decoded barcodes, recognized text lines, detected quads, deskewed images, and parsed results.
|
|
63
|
+
|
|
64
|
+
Methods:
|
|
65
|
+
enable_result_cross_verification(self, result_item_types: int, enabled: bool) -> None: Enables result cross verification feature to improve the accuracy of video streaming recognition results.
|
|
66
|
+
is_result_cross_verification_enabled(self, type: int) -> bool: Determines whether the result cross verification feature is enabled for the specific captured result item type.
|
|
67
|
+
enable_result_deduplication(self, result_item_types: int, enabled: bool) -> None: Enables result deduplication feature to filter out the duplicate results in the period of duplicateForgetTime for video streaming recognition.
|
|
68
|
+
is_result_deduplication_enabled(self, type: int) -> bool: Determines whether the result deduplication feature is enabled for the specific result item type.
|
|
69
|
+
set_duplicate_forget_time(self, result_item_types: int, duplicate_forget_time: int) -> None: Sets the duplicate forget time for the specific captured result item types.
|
|
70
|
+
get_duplicate_forget_time(self, type: int) -> int: Gets the duplicate forget time for a specific captured result item type.
|
|
71
|
+
set_max_overlapping_frames(self, result_item_types: int, max_overlapping_frames: int) -> None: Sets the max referencing frames count for the to-the-latest overlapping feature.
|
|
72
|
+
get_max_overlapping_frames(self, type: int) -> int: Gets the max referencing frames count for the to-the-latest overlapping feature.
|
|
73
|
+
enable_latest_overlapping(self, result_item_types: int, enable: bool) -> None: Enables to-the-latest overlapping feature. The output decoded barcode result will become a combination of the recent results if the latest frame is proved to be similar with the previous.
|
|
74
|
+
is_latest_overlapping_enabled(self, type: int) -> bool: Determines whether the to-the-latest overlapping feature is enabled for the specific result item type.
|
|
75
|
+
"""
|
|
76
|
+
_thisown = property(
|
|
77
|
+
lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag"
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
def __init__(self, cvr: CaptureVisionRouter = None):
|
|
81
|
+
_DynamsoftUtility.Class_init(
|
|
82
|
+
self, _DynamsoftUtility.new_CMultiFrameResultCrossFilter(cvr)
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
__destroy__ = _DynamsoftUtility.delete_CMultiFrameResultCrossFilter
|
|
86
|
+
|
|
87
|
+
def enable_result_cross_verification(
|
|
88
|
+
self, result_item_types: int, enabled: bool
|
|
89
|
+
) -> None:
|
|
90
|
+
"""
|
|
91
|
+
Enables result cross verification feature to improve the accuracy of video streaming recognition results.
|
|
92
|
+
|
|
93
|
+
Args:
|
|
94
|
+
result_item_types (int): A bitwise OR combination of one or more values from the EnumCapturedResultItemType enumeration.
|
|
95
|
+
enabled (bool): Set whether to enable result verification.
|
|
96
|
+
"""
|
|
97
|
+
return _DynamsoftUtility.CMultiFrameResultCrossFilter_EnableResultCrossVerification(
|
|
98
|
+
self, result_item_types, enabled
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
def is_result_cross_verification_enabled(self, type: int) -> bool:
|
|
102
|
+
"""
|
|
103
|
+
Determines whether the result cross verification feature is enabled for the specific captured result item type.
|
|
104
|
+
|
|
105
|
+
Args:
|
|
106
|
+
type (int): The specific captured result item type. It is a value from the EnumCapturedResultItemType enumeration.
|
|
107
|
+
|
|
108
|
+
Returns:
|
|
109
|
+
A bool value indicating whether result verification is enabled for the specific captured result item type.
|
|
110
|
+
"""
|
|
111
|
+
return _DynamsoftUtility.CMultiFrameResultCrossFilter_IsResultCrossVerificationEnabled(
|
|
112
|
+
self, type
|
|
113
|
+
)
|
|
114
|
+
|
|
115
|
+
def enable_result_deduplication(self, result_item_types: int, enabled: bool) -> None:
|
|
116
|
+
"""
|
|
117
|
+
Enables result deduplication feature to filter out the duplicate results in the period of duplicateForgetTime for video streaming recognition.
|
|
118
|
+
|
|
119
|
+
Args:
|
|
120
|
+
result_item_types (int): A bitwise OR combination of one or more values from the EnumCapturedResultItemType enumeration.
|
|
121
|
+
enabled (bool): Set whether to enable result result deduplication.
|
|
122
|
+
"""
|
|
123
|
+
return _DynamsoftUtility.CMultiFrameResultCrossFilter_EnableResultDeduplication(
|
|
124
|
+
self, result_item_types, enabled
|
|
125
|
+
)
|
|
126
|
+
|
|
127
|
+
def is_result_deduplication_enabled(self, type: int) -> bool:
|
|
128
|
+
"""
|
|
129
|
+
Determines whether the result deduplication feature is enabled for the specific result item type.
|
|
130
|
+
|
|
131
|
+
Args:
|
|
132
|
+
type (int): The specific captured result item type. It is a value from the EnumCapturedResultItemType enumeration.
|
|
133
|
+
|
|
134
|
+
Returns:
|
|
135
|
+
A bool value indicating whether result deduplication is enabled for the specific result item type.
|
|
136
|
+
"""
|
|
137
|
+
return (
|
|
138
|
+
_DynamsoftUtility.CMultiFrameResultCrossFilter_IsResultDeduplicationEnabled(
|
|
139
|
+
self, type
|
|
140
|
+
)
|
|
141
|
+
)
|
|
142
|
+
|
|
143
|
+
def set_duplicate_forget_time(self, result_item_types: int, time: int) -> None:
|
|
144
|
+
"""
|
|
145
|
+
Sets the duplicate forget time for the specific captured result item types. The same captured result item will be returned only once during the period if deduplication feature is enabled. The default value is 3000ms.
|
|
146
|
+
|
|
147
|
+
Args:
|
|
148
|
+
result_item_types (int): A bitwise OR combination of one or more values from the EnumCapturedResultItemType enumeration.
|
|
149
|
+
time (int): The duplicate forget time measured in milliseconds. The value rang is [1, 180000].
|
|
150
|
+
"""
|
|
151
|
+
|
|
152
|
+
return _DynamsoftUtility.CMultiFrameResultCrossFilter_SetDuplicateForgetTime(
|
|
153
|
+
self, result_item_types, time
|
|
154
|
+
)
|
|
155
|
+
|
|
156
|
+
def get_duplicate_forget_time(self, type: int) -> int:
|
|
157
|
+
"""
|
|
158
|
+
Gets the duplicate forget time for a specific captured result item type.
|
|
159
|
+
|
|
160
|
+
Args:
|
|
161
|
+
type (int): The specific captured result item type. It is a value from the EnumCapturedResultItemType enumeration.
|
|
162
|
+
|
|
163
|
+
Returns:
|
|
164
|
+
The duplicate forget time for the specific captured result item type.
|
|
165
|
+
"""
|
|
166
|
+
return _DynamsoftUtility.CMultiFrameResultCrossFilter_GetDuplicateForgetTime(
|
|
167
|
+
self, type
|
|
168
|
+
)
|
|
169
|
+
|
|
170
|
+
def set_max_overlapping_frames(self, result_item_types: int, max_overlapping_frames: int) -> None:
|
|
171
|
+
"""
|
|
172
|
+
Sets the max referencing frames count for the to-the-latest overlapping feature.
|
|
173
|
+
|
|
174
|
+
Args:
|
|
175
|
+
result_item_types (int): Specifies one or multiple specific result item types, which can be defined using CapturedResultItemType.
|
|
176
|
+
max_overlapping_frames (int): The max referencing frames count for the to-the-latest overlapping feature.
|
|
177
|
+
"""
|
|
178
|
+
return _DynamsoftUtility.CMultiFrameResultCrossFilter_SetMaxOverlappingFrames(
|
|
179
|
+
self, result_item_types, max_overlapping_frames
|
|
180
|
+
)
|
|
181
|
+
|
|
182
|
+
def get_max_overlapping_frames(self, type: int) -> int:
|
|
183
|
+
"""
|
|
184
|
+
Gets the max referencing frames count for the to-the-latest overlapping feature.
|
|
185
|
+
|
|
186
|
+
Args:
|
|
187
|
+
type (int): Specifies a specific result item type, which can be defined using CapturedResultItemType.
|
|
188
|
+
|
|
189
|
+
Returns:
|
|
190
|
+
The max referencing frames count for the to-the-latest overlapping feature.
|
|
191
|
+
"""
|
|
192
|
+
return _DynamsoftUtility.CMultiFrameResultCrossFilter_GetMaxOverlappingFrames(
|
|
193
|
+
self, type
|
|
194
|
+
)
|
|
195
|
+
|
|
196
|
+
def enable_latest_overlapping(self, result_item_types: int, enabled: bool) -> None:
|
|
197
|
+
"""
|
|
198
|
+
Enables to-the-latest overlapping feature. The output decoded barcode result will become a combination of the recent results if the latest frame is proved to be similar with the previous.
|
|
199
|
+
|
|
200
|
+
Args:
|
|
201
|
+
result_item_types (int): The or value of the captured result item types.
|
|
202
|
+
enable (bool): Set whether to enable to-the-latest overlapping.
|
|
203
|
+
"""
|
|
204
|
+
return _DynamsoftUtility.CMultiFrameResultCrossFilter_EnableLatestOverlapping(
|
|
205
|
+
self, result_item_types, enabled
|
|
206
|
+
)
|
|
207
|
+
|
|
208
|
+
def is_latest_overlapping_enabled(self, type: int) -> bool:
|
|
209
|
+
"""
|
|
210
|
+
Determines whether the to-the-latest overlapping feature is enabled for the specific result item type.
|
|
211
|
+
|
|
212
|
+
Args:
|
|
213
|
+
type (int): The specific captured result item type.
|
|
214
|
+
|
|
215
|
+
Returns:
|
|
216
|
+
A bool value indicating whether to-the-latest overlapping is enabled for the specific captured result item type.
|
|
217
|
+
"""
|
|
218
|
+
return _DynamsoftUtility.CMultiFrameResultCrossFilter_IsLatestOverlappingEnabled(
|
|
219
|
+
self, type
|
|
220
|
+
)
|
|
221
|
+
|
|
222
|
+
def set_result_cross_verification_criteria(self, result_item_types: int, frame_window: int, min_consistent_frames: int) -> None:
|
|
223
|
+
"""
|
|
224
|
+
This function allows customization of the multi-frame verification parameters,
|
|
225
|
+
controlling how many frames are analyzed and how many consistent results are required.
|
|
226
|
+
|
|
227
|
+
Args:
|
|
228
|
+
result_item_types (int): A bitwise OR combination of one or more values from the EnumCapturedResultItemType enumeration.
|
|
229
|
+
frame_window (int): The number of frames to consider for cross-verification.
|
|
230
|
+
min_consistent_frames (int): The minimum number of frames that must contain consistent results for verification to succeed.
|
|
231
|
+
"""
|
|
232
|
+
return _DynamsoftUtility.CMultiFrameResultCrossFilter_SetResultCrossVerificationCriteria(self, result_item_types, frame_window, min_consistent_frames)
|
|
233
|
+
|
|
234
|
+
def get_result_cross_verification_criteria(self, result_item_type: EnumCapturedResultItemType) -> Tuple[int, int]:
|
|
235
|
+
"""
|
|
236
|
+
Gets the cross-verification criteria for a specified result item type.
|
|
237
|
+
|
|
238
|
+
Args:
|
|
239
|
+
result_item_type (int): The result item type to query (CapturedResultItemType value).
|
|
240
|
+
|
|
241
|
+
Returns:
|
|
242
|
+
A tuple containing the frame window size and the minimum consistent frames.
|
|
243
|
+
"""
|
|
244
|
+
return _DynamsoftUtility.CMultiFrameResultCrossFilter_GetResultCrossVerificationCriteria(self, result_item_type)
|
|
245
|
+
|
|
246
|
+
_DynamsoftUtility.CMultiFrameResultCrossFilter_register(MultiFrameResultCrossFilter)
|
|
247
|
+
|
|
248
|
+
class ProactiveImageSourceAdapter(ImageSourceAdapter, ABC):
|
|
249
|
+
"""
|
|
250
|
+
The ProactiveImageSourceAdapter class is an abstract class that extends the ImageSourceAdapter class. It provides classs for proactively fetching images in a separate thread.
|
|
251
|
+
|
|
252
|
+
Methods:
|
|
253
|
+
_fetch_image(): This method needs to be implemented in the derived class. It is called in a loop in the Fetching thread to obtain images.
|
|
254
|
+
set_image_fetch_interval(self, milliseconds: int) -> None: Sets the time interval for the ImageSource to wait before attempting to fetch another image to put in the buffer.
|
|
255
|
+
get_image_fetch_interval(self) -> int: Gets the time interval for the ImageSource to wait before attempting to fetch another image to put in the buffer.
|
|
256
|
+
has_next_image_to_fetch(self) -> bool: Determines whether there are more images left to fetch.
|
|
257
|
+
start_fetching(self) -> None: Starts fetching images.
|
|
258
|
+
stop_fetching(self) -> None: Stops fetching images.
|
|
259
|
+
"""
|
|
260
|
+
_thisown = property(
|
|
261
|
+
lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag"
|
|
262
|
+
)
|
|
263
|
+
|
|
264
|
+
def __init__(self):
|
|
265
|
+
_DynamsoftUtility.Class_init(
|
|
266
|
+
self, _DynamsoftUtility.new_CProactiveImageSourceAdapter(self)
|
|
267
|
+
)
|
|
268
|
+
|
|
269
|
+
__destroy__ = _DynamsoftUtility.delete_CProactiveImageSourceAdapter
|
|
270
|
+
|
|
271
|
+
@abstractmethod
|
|
272
|
+
def _fetch_image():
|
|
273
|
+
"""
|
|
274
|
+
This method needs to be implemented in the derived class. It is called in a loop in the Fetching thread to obtain images.
|
|
275
|
+
"""
|
|
276
|
+
pass
|
|
277
|
+
|
|
278
|
+
def has_next_image_to_fetch(self) -> bool:
|
|
279
|
+
"""
|
|
280
|
+
Determines whether there are more images left to fetch.
|
|
281
|
+
|
|
282
|
+
Returns:
|
|
283
|
+
True if there are more images left to fetch, false otherwise.
|
|
284
|
+
"""
|
|
285
|
+
return _DynamsoftUtility.CProactiveImageSourceAdapter_HasNextImageToFetch(self)
|
|
286
|
+
|
|
287
|
+
def set_image_fetch_interval(self, milliseconds: int) -> None:
|
|
288
|
+
"""
|
|
289
|
+
Sets the time interval for the ImageSource to wait before attempting to fetch another image to put in the buffer.
|
|
290
|
+
|
|
291
|
+
Args:
|
|
292
|
+
milliseconds (int): Specifies the wait time in milliseconds. If setting to -1, the ImageSource does not proactively fetch images.
|
|
293
|
+
"""
|
|
294
|
+
return _DynamsoftUtility.CProactiveImageSourceAdapter_SetImageFetchInterval(
|
|
295
|
+
self, milliseconds
|
|
296
|
+
)
|
|
297
|
+
|
|
298
|
+
def get_image_fetch_interval(self) -> int:
|
|
299
|
+
"""
|
|
300
|
+
Gets the time interval for the ImageSource to wait before attempting to fetch another image to put in the buffer.
|
|
301
|
+
|
|
302
|
+
Returns:
|
|
303
|
+
The wait time in milliseconds. If the value is -1, the ImageSource does not proactively fetch images.
|
|
304
|
+
"""
|
|
305
|
+
return _DynamsoftUtility.CProactiveImageSourceAdapter_GetImageFetchInterval(
|
|
306
|
+
self
|
|
307
|
+
)
|
|
308
|
+
|
|
309
|
+
def start_fetching(self) -> None:
|
|
310
|
+
"""
|
|
311
|
+
Starts fetching images.
|
|
312
|
+
"""
|
|
313
|
+
return _DynamsoftUtility.CProactiveImageSourceAdapter_StartFetching(self)
|
|
314
|
+
|
|
315
|
+
def stop_fetching(self) -> None:
|
|
316
|
+
"""
|
|
317
|
+
Stops fetching images.
|
|
318
|
+
"""
|
|
319
|
+
return _DynamsoftUtility.CProactiveImageSourceAdapter_StopFetching(self)
|
|
320
|
+
|
|
321
|
+
|
|
322
|
+
_DynamsoftUtility.CProactiveImageSourceAdapter_register(ProactiveImageSourceAdapter)
|
|
323
|
+
|
|
324
|
+
class DirectoryFetcher(ProactiveImageSourceAdapter):
|
|
325
|
+
"""
|
|
326
|
+
The DirectoryFetcher class is a utility class that retrieves a list of files from a specified directory based on certain criteria. It inherits from the ProactiveImageSourceAdapter class.
|
|
327
|
+
|
|
328
|
+
Methods:
|
|
329
|
+
set_directory(self, path: str, filter: str) -> Tuple[int, str]: Sets the directory path and filter for the file search.
|
|
330
|
+
set_pdf_reading_parameter(self, para: PDFReadingParameter) -> Tuple[int, str]: Sets the parameters for reading PDF files.
|
|
331
|
+
set_pages(self, pages: List[int]) -> Tuple[int, str]: Sets the 0-based page indexes of a file (.tiff or .pdf) for barcode searching.
|
|
332
|
+
has_next_image_to_fetch(self) -> bool: Determines whether there are more images left to fetch.
|
|
333
|
+
"""
|
|
334
|
+
_thisown = property(
|
|
335
|
+
lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag"
|
|
336
|
+
)
|
|
337
|
+
|
|
338
|
+
def __init__(self):
|
|
339
|
+
_DynamsoftUtility.Class_init(
|
|
340
|
+
self, _DynamsoftUtility.new_CDirectoryFetcher()
|
|
341
|
+
)
|
|
342
|
+
|
|
343
|
+
__destroy__ = _DynamsoftUtility.delete_CDirectoryFetcher
|
|
344
|
+
|
|
345
|
+
def _fetch_image():
|
|
346
|
+
pass
|
|
347
|
+
def set_directory(self, *args) -> Tuple[int, str]:
|
|
348
|
+
"""
|
|
349
|
+
Sets the directory path and filter for the file search.
|
|
350
|
+
|
|
351
|
+
Args:
|
|
352
|
+
path (str): The path of the directory to search.
|
|
353
|
+
filter (str, optional): A string that specifies file extensions. For example: "*.BMP;*.JPG;*.GIF", or "*.*", etc. The default value is "*.bmp;*.jpg;*.jpeg;*.tif;*.png;*.tiff;*.gif;*.pdf".
|
|
354
|
+
recursive (bool, optional): Specifies whether to load files recursively. The default value is False.
|
|
355
|
+
|
|
356
|
+
Returns:
|
|
357
|
+
A tuple containing following elements:
|
|
358
|
+
- error_code (int): The error code indicating the status of the operation.
|
|
359
|
+
- error_message <str>: A descriptive message explaining the error.
|
|
360
|
+
"""
|
|
361
|
+
return _DynamsoftUtility.CDirectoryFetcher_SetDirectory(self, *args)
|
|
362
|
+
|
|
363
|
+
def set_pdf_reading_parameter(self, para: PDFReadingParameter) -> Tuple[int, str]:
|
|
364
|
+
"""
|
|
365
|
+
Sets the parameters for reading PDF files.
|
|
366
|
+
|
|
367
|
+
Args:
|
|
368
|
+
para (PDFReadingParameter): A PDFReadingParameter object with PDF files reading parameters.
|
|
369
|
+
|
|
370
|
+
Returns:
|
|
371
|
+
A tuple containing following elements:
|
|
372
|
+
- error_code (int): The error code indicating the status of the operation.
|
|
373
|
+
- error_message <str>: A descriptive message explaining the error.
|
|
374
|
+
"""
|
|
375
|
+
return _DynamsoftUtility.CDirectoryFetcher_SetPDFReadingParameter(self, para)
|
|
376
|
+
|
|
377
|
+
def has_next_image_to_fetch(self) -> bool:
|
|
378
|
+
"""
|
|
379
|
+
Determines whether there are more images left to fetch.
|
|
380
|
+
|
|
381
|
+
Returns:
|
|
382
|
+
True if there are more images left to fetch, false otherwise.
|
|
383
|
+
"""
|
|
384
|
+
return _DynamsoftUtility.CDirectoryFetcher_HasNextImageToFetch(self)
|
|
385
|
+
|
|
386
|
+
def set_pages(self, pages: List[int]) -> Tuple[int, str]:
|
|
387
|
+
"""
|
|
388
|
+
Sets the 0-based page indexes of a file (.tiff or .pdf). By default, there is no restriction on the number of pages that can be processed in a single file.
|
|
389
|
+
|
|
390
|
+
Args:
|
|
391
|
+
pages (List[int]): An integer list containing the page information to be set.
|
|
392
|
+
|
|
393
|
+
Returns:
|
|
394
|
+
A tuple containing following elements:
|
|
395
|
+
- error_code (int): The error code indicating the status of the operation.
|
|
396
|
+
- error_message <str>: A descriptive message explaining the error.
|
|
397
|
+
"""
|
|
398
|
+
return _DynamsoftUtility.CDirectoryFetcher_SetPages(self, pages, len(pages))
|
|
399
|
+
|
|
400
|
+
|
|
401
|
+
_DynamsoftUtility.CDirectoryFetcher_register(DirectoryFetcher)
|
|
402
|
+
|
|
403
|
+
|
|
404
|
+
class FileFetcher(ImageSourceAdapter):
|
|
405
|
+
"""
|
|
406
|
+
The FileFetcher class is a utility class that partitions a multi-page image file into multiple independent ImageData objects. It inherits from the ImageSourceAdapter class.
|
|
407
|
+
|
|
408
|
+
Methods:
|
|
409
|
+
set_file(self, path: str) -> Tuple[int, str]: Sets the file using a file path.
|
|
410
|
+
set_pdf_reading_parameter(self, para: PDFReadingParameter) -> Tuple[int, str]: Sets the parameters for reading PDF files.
|
|
411
|
+
set_pages(self, pages: List[int]) -> Tuple[int, str]: Sets the 0-based page indexes of a file (.tiff or .pdf) for barcode searching.
|
|
412
|
+
has_next_image_to_fetch(self) -> bool: Determines whether there are more images left to fetch.
|
|
413
|
+
get_image(self) -> ImageData: Gets the next image.
|
|
414
|
+
"""
|
|
415
|
+
|
|
416
|
+
_thisown = property(
|
|
417
|
+
lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag"
|
|
418
|
+
)
|
|
419
|
+
|
|
420
|
+
def __init__(self):
|
|
421
|
+
_DynamsoftUtility.Class_init(self, _DynamsoftUtility.new_CFileFetcher())
|
|
422
|
+
|
|
423
|
+
__destroy__ = _DynamsoftUtility.delete_CFileFetcher
|
|
424
|
+
|
|
425
|
+
def set_file(self, *args) -> Tuple[int, str]:
|
|
426
|
+
"""
|
|
427
|
+
Sets the file using a file path, file bytes or an ImageData object.
|
|
428
|
+
|
|
429
|
+
Args:
|
|
430
|
+
A variable-length argument list. Can be one of the following:
|
|
431
|
+
- file_path (str): Specifies the path of the file to process.
|
|
432
|
+
- file_bytes (bytes): Specifies the image file bytes in memory to process.
|
|
433
|
+
- image_data (ImageData): Specifies the image data to process.
|
|
434
|
+
|
|
435
|
+
Returns:
|
|
436
|
+
A tuple containing following elements:
|
|
437
|
+
- error_code (int): The error code indicating the status of the operation.
|
|
438
|
+
- error_message <str>: A descriptive message explaining the error.
|
|
439
|
+
"""
|
|
440
|
+
return _DynamsoftUtility.CFileFetcher_SetFile(self, *args)
|
|
441
|
+
|
|
442
|
+
def set_pdf_reading_parameter(self, para: PDFReadingParameter) -> Tuple[int, str]:
|
|
443
|
+
"""
|
|
444
|
+
Sets the parameters for reading PDF files.
|
|
445
|
+
|
|
446
|
+
Args:
|
|
447
|
+
para (PDFReadingParameter): A PDFReadingParameter object with PDF files reading parameters.
|
|
448
|
+
|
|
449
|
+
Returns:
|
|
450
|
+
A tuple containing following elements:
|
|
451
|
+
- error_code (int): The error code indicating the status of the operation.
|
|
452
|
+
- error_message <str>: A descriptive message explaining the error.
|
|
453
|
+
"""
|
|
454
|
+
return _DynamsoftUtility.CFileFetcher_SetPDFReadingParameter(self, para)
|
|
455
|
+
|
|
456
|
+
def has_next_image_to_fetch(self) -> bool:
|
|
457
|
+
"""
|
|
458
|
+
Determines whether there are more images left to fetch.
|
|
459
|
+
|
|
460
|
+
Returns:
|
|
461
|
+
True if there are more images left to fetch, False otherwise.
|
|
462
|
+
"""
|
|
463
|
+
return _DynamsoftUtility.CFileFetcher_HasNextImageToFetch(self)
|
|
464
|
+
|
|
465
|
+
def get_image(self) -> ImageData:
|
|
466
|
+
"""
|
|
467
|
+
Gets the next image.
|
|
468
|
+
|
|
469
|
+
Returns:
|
|
470
|
+
The next image.
|
|
471
|
+
"""
|
|
472
|
+
return _DynamsoftUtility.CFileFetcher_GetImage(self)
|
|
473
|
+
|
|
474
|
+
def set_pages(self, pages: List[int]) -> Tuple[int, str]:
|
|
475
|
+
"""
|
|
476
|
+
Sets the 0-based page indexes of a file (.tiff or .pdf). By default, there is no restriction on the number of pages that can be processed in a single file.
|
|
477
|
+
|
|
478
|
+
Args:
|
|
479
|
+
pages (List[int]): An integer list containing the page information to be set.
|
|
480
|
+
|
|
481
|
+
Returns:
|
|
482
|
+
A tuple containing following elements:
|
|
483
|
+
- error_code (int): The error code indicating the status of the operation.
|
|
484
|
+
- error_message <str>: A descriptive message explaining the error.
|
|
485
|
+
"""
|
|
486
|
+
return _DynamsoftUtility.CFileFetcher_SetPages(self, pages, len(pages))
|
|
487
|
+
|
|
488
|
+
|
|
489
|
+
_DynamsoftUtility.CFileFetcher_register(FileFetcher)
|
|
490
|
+
|
|
491
|
+
|
|
492
|
+
class ImageIO:
|
|
493
|
+
"""
|
|
494
|
+
The ImageIO class is a utility class for reading and writing images.
|
|
495
|
+
|
|
496
|
+
Methods:
|
|
497
|
+
save_to_file(self, image_data: ImageData, path: str, overwrite: bool = True) -> Tuple[int, str]: Saves an image to a file.
|
|
498
|
+
read_from_file(self, file_path: str) -> Tuple[int, ImageData]: Reads an image from a file.
|
|
499
|
+
read_from_memory(self, image_file_bytes: bytes) -> Tuple[int, ImageData]: Reads an image from a file in memory.
|
|
500
|
+
save_to_memory(self, image_data: ImageData,image_format: EnumImageFileFormat) -> Tuple[int, bytes]: Saves an image to memory in the specified format.
|
|
501
|
+
read_from_numpy(self, image: "np.ndarray", image_pixel_format: EnumImagePixelFormat) -> Tuple[int, str, ImageData]: Reads an image from a numpy array.
|
|
502
|
+
save_to_numpy(self, image_data: ImageData) -> Tuple[int, str, "np.ndarray"]: Saves an image to a numpy array.
|
|
503
|
+
"""
|
|
504
|
+
|
|
505
|
+
_thisown = property(
|
|
506
|
+
lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag"
|
|
507
|
+
)
|
|
508
|
+
|
|
509
|
+
def __init__(self):
|
|
510
|
+
_DynamsoftUtility.Class_init(
|
|
511
|
+
self, _DynamsoftUtility.new_CImageIO()
|
|
512
|
+
)
|
|
513
|
+
def save_to_file(
|
|
514
|
+
self, image_data: ImageData, path: str, overwrite: bool = True
|
|
515
|
+
) -> Tuple[int, str]:
|
|
516
|
+
"""
|
|
517
|
+
Saves an image to a file.
|
|
518
|
+
|
|
519
|
+
Args:
|
|
520
|
+
image_data (ImageData): The image data to be saved.
|
|
521
|
+
path (str): The targeting file path with the file name and extension name.
|
|
522
|
+
overwrite (bool, optional): A flag indicating whether to overwrite the file if it already exists. Defaults to true.
|
|
523
|
+
|
|
524
|
+
Returns:
|
|
525
|
+
A tuple containing following elements:
|
|
526
|
+
- error_code (int): The error code indicating the status of the operation.
|
|
527
|
+
- error_message <str>: A descriptive message explaining the error.
|
|
528
|
+
"""
|
|
529
|
+
return _DynamsoftUtility.CImageIO_SaveToFile(
|
|
530
|
+
self, image_data, path, overwrite
|
|
531
|
+
)
|
|
532
|
+
|
|
533
|
+
def read_from_file(self, file_path: str) -> Tuple[int, ImageData]:
|
|
534
|
+
"""
|
|
535
|
+
Reads an image from a file.
|
|
536
|
+
If the file format is gif, pdf or tiff, we read the first page of the image file.
|
|
537
|
+
The caller is responsible for freeing the memory allocated for the image.
|
|
538
|
+
|
|
539
|
+
Args:
|
|
540
|
+
file_path (str): The path of the image file.
|
|
541
|
+
|
|
542
|
+
Returns:
|
|
543
|
+
A tuple containing following elements:
|
|
544
|
+
- error_code (int): The error code indicating the status of the operation.
|
|
545
|
+
- image_data (ImageData): An ImageData object representing the image if succeeds, None otherwise.
|
|
546
|
+
"""
|
|
547
|
+
return _DynamsoftUtility.CImageIO_ReadFromFile(self, file_path)
|
|
548
|
+
|
|
549
|
+
def read_from_memory(self, image_file_bytes: bytes) -> Tuple[int, ImageData]:
|
|
550
|
+
"""
|
|
551
|
+
Reads an image from a file in memory.
|
|
552
|
+
If the file format is gif, pdf or tiff, we read the first page of the image file.
|
|
553
|
+
The caller is responsible for freeing the memory allocated for the image.
|
|
554
|
+
|
|
555
|
+
Args:
|
|
556
|
+
image_file_bytes (bytes): A bytes representing the image file in memory.
|
|
557
|
+
|
|
558
|
+
Returns:
|
|
559
|
+
A tuple containing following elements:
|
|
560
|
+
- error_code (int): The error code indicating the status of the operation.
|
|
561
|
+
- image_data (ImageData): An ImageData object representing the image if succeeds, None otherwise.
|
|
562
|
+
"""
|
|
563
|
+
return _DynamsoftUtility.CImageIO_ReadFromMemory(self, image_file_bytes)
|
|
564
|
+
|
|
565
|
+
def save_to_memory(self, image_data: ImageData,image_format: EnumImageFileFormat) -> Tuple[int, bytes]:
|
|
566
|
+
"""
|
|
567
|
+
Saves an image to memory in the specified format.
|
|
568
|
+
|
|
569
|
+
Args:
|
|
570
|
+
image_data (ImageData): The image data to be saved.
|
|
571
|
+
image_format (EnumImageFileFormat): The desired image format.
|
|
572
|
+
|
|
573
|
+
Returns:
|
|
574
|
+
A tuple containing following elements:
|
|
575
|
+
- error_code (int): The error code indicating the status of the operation.
|
|
576
|
+
- image_file_bytes (bytes): The byte array representing the saved image file if succeeds, None otherwise.
|
|
577
|
+
"""
|
|
578
|
+
return _DynamsoftUtility.CImageIO_SaveToMemory(self, image_data, image_format)
|
|
579
|
+
|
|
580
|
+
def read_from_numpy(self, image: "numpy.ndarray", image_pixel_format: EnumImagePixelFormat) -> Tuple[int, str, ImageData]:
|
|
581
|
+
"""
|
|
582
|
+
Reads an image from a numpy array.
|
|
583
|
+
|
|
584
|
+
Args:
|
|
585
|
+
image (np.ndarray): A numpy array representing the image.
|
|
586
|
+
image_pixel_format (EnumImagePixelFormat): The pixel format of the numpy array.
|
|
587
|
+
|
|
588
|
+
Returns:
|
|
589
|
+
A tuple containing following elements:
|
|
590
|
+
- error_code (int): The error code indicating the status of the operation.
|
|
591
|
+
- error_message <str>: A descriptive message explaining the error.
|
|
592
|
+
- image_data (ImageData): An ImageData object representing the image if succeeds, None otherwise.
|
|
593
|
+
"""
|
|
594
|
+
return 0, "Success.", ImageData(image.tobytes(),image.shape[1],image.shape[0],image.strides[0], image_pixel_format)
|
|
595
|
+
|
|
596
|
+
def save_to_numpy(self, image_data: ImageData) -> Tuple[int, str, "numpy.ndarray"]:
|
|
597
|
+
"""
|
|
598
|
+
Saves an image to a numpy array.
|
|
599
|
+
|
|
600
|
+
Args:
|
|
601
|
+
image_data (ImageData): The image data to be saved.
|
|
602
|
+
|
|
603
|
+
Returns:
|
|
604
|
+
A tuple containing following elements:
|
|
605
|
+
- error_code (int): The error code indicating the status of the operation.
|
|
606
|
+
- error_message <str>: A descriptive message explaining the error.
|
|
607
|
+
- image (np.ndarray): A numpy array representing the saved image if succeeds, None otherwise.
|
|
608
|
+
"""
|
|
609
|
+
import numpy as np
|
|
610
|
+
width = image_data.get_width()
|
|
611
|
+
height = image_data.get_height()
|
|
612
|
+
image_bytes = image_data.get_bytes()
|
|
613
|
+
format = image_data.get_image_pixel_format()
|
|
614
|
+
err = 0
|
|
615
|
+
err_str = "Success."
|
|
616
|
+
if format == EnumImagePixelFormat.IPF_RGB_888:
|
|
617
|
+
arr = np.frombuffer(image_bytes, dtype=np.uint8).reshape((height, width, 3))
|
|
618
|
+
elif format == EnumImagePixelFormat.IPF_BGR_888:
|
|
619
|
+
arr = np.frombuffer(image_bytes, dtype=np.uint8).reshape((height, width, 3))
|
|
620
|
+
arr = arr[:, :, ::-1]
|
|
621
|
+
elif format == EnumImagePixelFormat.IPF_GRAYSCALED \
|
|
622
|
+
or format == EnumImagePixelFormat.IPF_BINARY \
|
|
623
|
+
or format == EnumImagePixelFormat.IPF_BINARYINVERTED \
|
|
624
|
+
or format == EnumImagePixelFormat.IPF_BINARY_8 \
|
|
625
|
+
or format == EnumImagePixelFormat.IPF_BINARY_8_INVERTED:
|
|
626
|
+
arr = np.frombuffer(image_bytes, dtype=np.uint8).reshape((height, width))
|
|
627
|
+
else:
|
|
628
|
+
err = EnumErrorCode.EC_IMAGE_PIXEL_FORMAT_NOT_MATCH
|
|
629
|
+
if __package__ or "." in __name__:
|
|
630
|
+
from . import _DynamsoftCore
|
|
631
|
+
else:
|
|
632
|
+
import _DynamsoftCore
|
|
633
|
+
err_str = _DynamsoftCore.DC_GetErrorString(err)
|
|
634
|
+
arr = None
|
|
635
|
+
return err, err_str, arr
|
|
636
|
+
|
|
637
|
+
__destroy__ = _DynamsoftUtility.delete_CImageIO
|
|
638
|
+
|
|
639
|
+
_DynamsoftUtility.CImageIO_register(ImageIO)
|
|
640
|
+
|
|
641
|
+
class ImageDrawer:
|
|
642
|
+
"""
|
|
643
|
+
The ImageDrawer class provides methods for drawing various shapes on an image.
|
|
644
|
+
|
|
645
|
+
Attributes:
|
|
646
|
+
AnyShape: A type representing any shape that can be drawn on an image.
|
|
647
|
+
|
|
648
|
+
Methods:
|
|
649
|
+
draw_on_image(self, image: ImageData, shapes: List[AnyShape], color: int = 0xFFFF0000, thickness: int = 1) -> ImageData: Draws various shapes on an image.
|
|
650
|
+
"""
|
|
651
|
+
_thisown = property(
|
|
652
|
+
lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag"
|
|
653
|
+
)
|
|
654
|
+
def __init__(self):
|
|
655
|
+
_DynamsoftUtility.Class_init(
|
|
656
|
+
self, _DynamsoftUtility.new_CImageDrawer()
|
|
657
|
+
)
|
|
658
|
+
|
|
659
|
+
def draw_on_image(
|
|
660
|
+
self,
|
|
661
|
+
image: ImageData,
|
|
662
|
+
shapes: Union[
|
|
663
|
+
List[Quadrilateral],
|
|
664
|
+
List[LineSegment],
|
|
665
|
+
List[Contour],
|
|
666
|
+
List[Corner],
|
|
667
|
+
List[Edge],
|
|
668
|
+
],
|
|
669
|
+
color: int = 0xFFFF0000,
|
|
670
|
+
thickness: int = 1,
|
|
671
|
+
) -> ImageData:
|
|
672
|
+
"""
|
|
673
|
+
Draws various shapes on an image.
|
|
674
|
+
|
|
675
|
+
Args:
|
|
676
|
+
image (ImageData): The image to draw on.
|
|
677
|
+
shapes (Union[Quadrilateral, LineSegment, Contour, Corner, Edge]): The shapes to draw.
|
|
678
|
+
color (int, optional): The color of the shapes. Defaults to 0xFFFF0000 (red).
|
|
679
|
+
thickness (int, optional): The thickness of the lines. Defaults to 1.
|
|
680
|
+
|
|
681
|
+
Returns:
|
|
682
|
+
An ImageData object to the modified image data.
|
|
683
|
+
"""
|
|
684
|
+
return _DynamsoftUtility.CImageDrawer_DrawOnImage(self, image, shapes, color, thickness)
|
|
685
|
+
|
|
686
|
+
__destroy__ = _DynamsoftUtility.delete_CImageDrawer
|
|
687
|
+
|
|
688
|
+
_DynamsoftUtility.CImageDrawer_register(ImageDrawer)
|
|
689
|
+
|
|
690
|
+
class ImageProcessor:
|
|
691
|
+
_thisown = property(
|
|
692
|
+
lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag"
|
|
693
|
+
)
|
|
694
|
+
|
|
695
|
+
def __init__(self):
|
|
696
|
+
_DynamsoftUtility.Class_init(
|
|
697
|
+
self, _DynamsoftUtility.new_CImageProcessor()
|
|
698
|
+
)
|
|
699
|
+
|
|
700
|
+
def crop_image(self, image_data:ImageData, crop_form: Union[Rect,Quadrilateral]) -> Tuple[int, ImageData]:
|
|
701
|
+
"""
|
|
702
|
+
Crops an image.
|
|
703
|
+
The caller is resposible for freeing the memory allocated for the cropped image.
|
|
704
|
+
The function will automatically calculate the perspective transform matrix and use it to crop the image.
|
|
705
|
+
|
|
706
|
+
Args:
|
|
707
|
+
image_data (ImageData): The image data to be cropped.
|
|
708
|
+
crop_form (Union[Rect, Quadrilateral]): The cropping form.
|
|
709
|
+
|
|
710
|
+
Returns:
|
|
711
|
+
A tuple containing following elements:
|
|
712
|
+
- error_code (int): The error code indicating the status of the operation.
|
|
713
|
+
- cropped_image_data (ImageData): An ImageData object representing the cropped image if succeeds, None otherwise.
|
|
714
|
+
"""
|
|
715
|
+
if isinstance(crop_form, Rect):
|
|
716
|
+
return _DynamsoftUtility.CImageProcessor_CropImageWithRect(self, image_data, crop_form)
|
|
717
|
+
elif isinstance(crop_form, Quadrilateral):
|
|
718
|
+
import warnings
|
|
719
|
+
warnings.warn(
|
|
720
|
+
"Function 'crop_image' with parameter type `Quadrilateral` is deprecated and will be removed in future versions. Please use `crop_and_deskew_image` function instead.",
|
|
721
|
+
DeprecationWarning,
|
|
722
|
+
stacklevel=2
|
|
723
|
+
)
|
|
724
|
+
return _DynamsoftUtility.CImageProcessor_CropImageWithQuadrilateral(self, image_data, crop_form)
|
|
725
|
+
else:
|
|
726
|
+
raise TypeError("Unsupported crop form type")
|
|
727
|
+
|
|
728
|
+
def crop_and_deskew_image(self, image_data: ImageData, crop_form: Quadrilateral, destination_width: int = 0, destination_height: int = 0, padding: int = 0) -> Tuple[int, ImageData]:
|
|
729
|
+
"""
|
|
730
|
+
Crops and deskews a region from the input image based on the specified quadrilateral.
|
|
731
|
+
|
|
732
|
+
Args:
|
|
733
|
+
image_data (ImageData): The image data to be cropped and deskewed.
|
|
734
|
+
crop_form (Quadrilateral): Quad A quadrilateral defining the region of interest to extract.
|
|
735
|
+
destination_width (int, optional): The width of the output image. If set to 0, the width and height will be automatically calculated.
|
|
736
|
+
destination_height (int, optional): The height of the output image. If set to 0, the width and height will be automatically calculated.
|
|
737
|
+
padding (int, optional): Extra padding (in pixels) applied to expand the boundaries of the extracted region. Default is 0.
|
|
738
|
+
|
|
739
|
+
Returns:
|
|
740
|
+
A tuple containing following elements:
|
|
741
|
+
- error_code (int): The error code indicating the status of the operation.
|
|
742
|
+
- cropped_image_data (ImageData): An ImageData object representing the cropped and deskewed image if succeeds, None otherwise.
|
|
743
|
+
|
|
744
|
+
Notes:
|
|
745
|
+
The caller is responsible for freeing the memory allocated for the cropped image.
|
|
746
|
+
The function will automatically calculate the perspective transform matrix and use it to crop the image.
|
|
747
|
+
If the specified quadrilateral exceeds the image boundaries, white will be used to fill the exceeding area.
|
|
748
|
+
"""
|
|
749
|
+
return _DynamsoftUtility.CImageProcessor_CropAndDeskewImage(self, image_data, crop_form, destination_width, destination_height, padding)
|
|
750
|
+
def adjust_brightness(self, image_data: ImageData, brightness: int) -> ImageData:
|
|
751
|
+
"""
|
|
752
|
+
Adjusts the brightness of the image.
|
|
753
|
+
|
|
754
|
+
Args:
|
|
755
|
+
image_data (ImageData): The image data to be adjusted.
|
|
756
|
+
brightness (int): The brightness adjustment value (positive values increase brightness, negative values decrease brightness).
|
|
757
|
+
|
|
758
|
+
Returns:
|
|
759
|
+
An ImageData object after brightness adjustment.
|
|
760
|
+
"""
|
|
761
|
+
return _DynamsoftUtility.CImageProcessor_AdjustBrightness(self, image_data, brightness)
|
|
762
|
+
|
|
763
|
+
def adjust_contrast(self, image_data: ImageData, contrast: int) -> ImageData:
|
|
764
|
+
"""
|
|
765
|
+
Adjusts the contrast of the image.
|
|
766
|
+
|
|
767
|
+
Args:
|
|
768
|
+
image_data (ImageData): The image data to be adjusted.
|
|
769
|
+
contrast (int): The contrast adjustment value (positive values enhance, negative values reduce contrast).
|
|
770
|
+
|
|
771
|
+
Returns:
|
|
772
|
+
An ImageData object after contrast adjustment.
|
|
773
|
+
"""
|
|
774
|
+
return _DynamsoftUtility.CImageProcessor_AdjustContrast(self, image_data, contrast)
|
|
775
|
+
|
|
776
|
+
def filter_image(self, image_data: ImageData, filter_type: FilterType) -> ImageData:
|
|
777
|
+
"""
|
|
778
|
+
Applies a specified image filter to an input image and returns the filtered result.
|
|
779
|
+
|
|
780
|
+
Args:
|
|
781
|
+
image_data (ImageData): The image data to be filtered.
|
|
782
|
+
filter_type (FilterType): Specifies the type of filter to apply to the input image.
|
|
783
|
+
|
|
784
|
+
Returns:
|
|
785
|
+
An ImageData object after filtering operation.
|
|
786
|
+
"""
|
|
787
|
+
return _DynamsoftUtility.CImageProcessor_FilterImage(self, image_data, filter_type)
|
|
788
|
+
|
|
789
|
+
def convert_to_gray(self, image_data: ImageData, r: float = 0.3, g: float = 0.59, b: float = 0.11) -> ImageData:
|
|
790
|
+
"""
|
|
791
|
+
Converts a colour image to grayscale using the given weights.
|
|
792
|
+
|
|
793
|
+
Args:
|
|
794
|
+
image_data (ImageData): The image data to be converted.
|
|
795
|
+
r (float): Weight for red channel (default value: 0.3).
|
|
796
|
+
g (float): Weight for green channel (default value: 0.59).
|
|
797
|
+
b (float): Weight for blue channel (default value: 0.11).
|
|
798
|
+
|
|
799
|
+
Returns:
|
|
800
|
+
An ImageData object after grayscale conversion.
|
|
801
|
+
"""
|
|
802
|
+
return _DynamsoftUtility.CImageProcessor_ConvertToGray(self, image_data, r, g, b)
|
|
803
|
+
|
|
804
|
+
def convert_to_binary_global(self, image_data: ImageData, threshold: int = -1, invert: bool = False) -> ImageData:
|
|
805
|
+
"""
|
|
806
|
+
Converts a grayscale image to binary image using a global threshold.
|
|
807
|
+
|
|
808
|
+
Args:
|
|
809
|
+
image_data (ImageData): The image data to be converted.
|
|
810
|
+
threshold (int): Global threshold for binarization (default is -1, automatic calculate the threshold).
|
|
811
|
+
invert (bool): If true, invert the binary image (black becomes white and white becomes black).
|
|
812
|
+
|
|
813
|
+
Returns:
|
|
814
|
+
An ImageData object after binary conversion.
|
|
815
|
+
"""
|
|
816
|
+
return _DynamsoftUtility.CImageProcessor_ConvertToBinaryGlobal(self, image_data, threshold, invert)
|
|
817
|
+
|
|
818
|
+
def convert_to_binary_local(self, image_data: ImageData, block_size: int = 0, compensation: int = 10, invert: bool = False) ->ImageData:
|
|
819
|
+
"""
|
|
820
|
+
Converts a grayscale image to binary image using local (adaptive) binarization.
|
|
821
|
+
|
|
822
|
+
Args:
|
|
823
|
+
image_data (ImageData): The image data to be converted.
|
|
824
|
+
block_size (int): Size of the block for local binarization (default is 0).
|
|
825
|
+
compensation (int): Adjustment value to modify the threshold (default is 10).
|
|
826
|
+
invert (bool): If true, invert the binary image (black becomes white and white becomes black).
|
|
827
|
+
|
|
828
|
+
Returns:
|
|
829
|
+
An ImageData object after binary conversion.
|
|
830
|
+
"""
|
|
831
|
+
return _DynamsoftUtility.CImageProcessor_ConvertToBinaryLocal(self, image_data, block_size, compensation, invert)
|
|
832
|
+
__destroy__ = _DynamsoftUtility.delete_CImageProcessor
|
|
833
|
+
|
|
834
|
+
|
|
835
|
+
_DynamsoftUtility.CImageProcessor_register(ImageProcessor)
|