Skip to content

Commit 888618a

Browse files
committed
Update README.md
1 parent fdd67ed commit 888618a

File tree

3 files changed

+68
-81
lines changed

3 files changed

+68
-81
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
strategy:
1010
matrix:
1111
os: [windows-latest, ubuntu-latest]
12-
python-version: ['3.6', '3.7', '3.8', '3.9', '3.10']
12+
python-version: ['3.10']
1313

1414
steps:
1515
- uses: actions/checkout@v2

README.md

Lines changed: 64 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,32 @@
11
# Python Document Scanner SDK
2-
The project is a Python binding to [Dynamsoft C/C++ Document Scanner SDK](https://www.dynamsoft.com/document-normalizer/docs/introduction/?ver=latest). It aims to help developers quickly build desktop document scanner applications in Python on Windows and Linux.
2+
This project provides Python bindings for the [Dynamsoft C/C++ Document Scanner SDK v1.x](https://www.dynamsoft.com/document-normalizer/docs/core/introduction/?ver=latest&ver=latest), enabling developers to quickly create document scanner applications for Windows and Linux desktop environments.
33

44
## About Dynamsoft Document Scanner
5-
Get a [30-day FREE trial license](https://www.dynamsoft.com/customer/license/trialLicense?product=ddn) to activate the SDK.
5+
- Activate the SDK with a [30-day FREE trial license](https://www.dynamsoft.com/customer/license/trialLicense?product=ddn).
66

77

8-
## Supported Python Edition
8+
## Supported Python Versions
99
* Python 3.x
1010

1111
## Dependencies
12+
Install the required dependencies using pip:
1213

1314
```bash
1415
pip install opencv-python
1516
```
1617

1718
## Command-line Usage
18-
```bash
19-
# Scan documents from images
20-
$ scandocument -f <file-name> -l <license-key>
19+
- Scan documents from images:
20+
21+
```bash
22+
scandocument -f <file-name> -l <license-key>
23+
```
2124

22-
# Scan documents from camera video stream
23-
$ scandocument -c 1 -l <license-key>
24-
```
25+
- Scan documents from a camera video stream:
26+
27+
```bash
28+
scandocument -c 1 -l <license-key>
29+
```
2530

2631
## Quick Start
2732
- Scan documents from an image file:
@@ -80,7 +85,7 @@ $ scandocument -c 1 -l <license-key>
8085
8186
# set license
8287
if license == '':
83-
docscanner.initLicense("DLS2eyJoYW5kc2hha2VDb2RlIjoiMjAwMDAxLTE2NDk4Mjk3OTI2MzUiLCJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSIsInNlc3Npb25QYXNzd29yZCI6IndTcGR6Vm05WDJrcEQ5YUoifQ==")
88+
docscanner.initLicense("LICENSE-KEY")
8489
else:
8590
docscanner.initLicense(license)
8691
@@ -112,26 +117,29 @@ $ scandocument -c 1 -l <license-key>
112117
g_results = None
113118
g_normalized_images = []
114119
120+
115121
def callback(results):
116122
global g_results
117123
g_results = results
118124
125+
119126
def showNormalizedImage(name, normalized_image):
120127
mat = docscanner.convertNormalizedImage2Mat(normalized_image)
121128
cv2.imshow(name, mat)
122129
return mat
123-
130+
131+
124132
def process_video(scanner):
125133
scanner.addAsyncListener(callback)
126-
134+
127135
cap = cv2.VideoCapture(0)
128136
while True:
129137
ret, image = cap.read()
130-
138+
131139
ch = cv2.waitKey(1)
132140
if ch == 27:
133141
break
134-
elif ch == ord('n'): # normalize image
142+
elif ch == ord('n'): # normalize image
135143
if g_results != None:
136144
g_normalized_images = []
137145
index = 0
@@ -144,23 +152,25 @@ $ scandocument -c 1 -l <license-key>
144152
y3 = result.y3
145153
x4 = result.x4
146154
y4 = result.y4
147-
148-
normalized_image = scanner.normalizeBuffer(image, x1, y1, x2, y2, x3, y3, x4, y4)
149-
g_normalized_images.append((str(index), normalized_image))
155+
156+
normalized_image = scanner.normalizeBuffer(
157+
image, x1, y1, x2, y2, x3, y3, x4, y4)
158+
g_normalized_images.append(
159+
(str(index), normalized_image))
150160
mat = showNormalizedImage(str(index), normalized_image)
151161
index += 1
152-
elif ch == ord('s'): # save image
162+
elif ch == ord('s'): # save image
153163
for data in g_normalized_images:
154164
# cv2.imwrite('images/' + str(time.time()) + '.png', image)
155165
cv2.destroyWindow(data[0])
156166
data[1].save(str(time.time()) + '.png')
157167
print('Image saved')
158-
168+
159169
g_normalized_images = []
160-
170+
161171
if image is not None:
162172
scanner.detectMatAsync(image)
163-
173+
164174
if g_results != None:
165175
for result in g_results:
166176
x1 = result.x1
@@ -171,71 +181,48 @@ $ scandocument -c 1 -l <license-key>
171181
y3 = result.y3
172182
x4 = result.x4
173183
y4 = result.y4
174-
175-
cv2.drawContours(image, [np.intp([(x1, y1), (x2, y2), (x3, y3), (x4, y4)])], 0, (0, 255, 0), 2)
176-
177-
cv2.putText(image, 'Press "n" to normalize image', (10, 30), cv2.FONT_HERSHEY_SIMPLEX, 0.8, (0, 0, 255), 2)
178-
cv2.putText(image, 'Press "s" to save image', (10, 60), cv2.FONT_HERSHEY_SIMPLEX, 0.8, (0, 0, 255), 2)
179-
cv2.putText(image, 'Press "ESC" to exit', (10, 90), cv2.FONT_HERSHEY_SIMPLEX, 0.8, (0, 0, 255), 2)
184+
185+
cv2.drawContours(
186+
image, [np.intp([(x1, y1), (x2, y2), (x3, y3), (x4, y4)])], 0, (0, 255, 0), 2)
187+
188+
cv2.putText(image, 'Press "n" to normalize image',
189+
(10, 30), cv2.FONT_HERSHEY_SIMPLEX, 0.8, (0, 0, 255), 2)
190+
cv2.putText(image, 'Press "s" to save image', (10, 60),
191+
cv2.FONT_HERSHEY_SIMPLEX, 0.8, (0, 0, 255), 2)
192+
cv2.putText(image, 'Press "ESC" to exit', (10, 90),
193+
cv2.FONT_HERSHEY_SIMPLEX, 0.8, (0, 0, 255), 2)
180194
cv2.imshow('Document Scanner', image)
181195
182-
def scandocument():
183-
"""
184-
Command-line script for scanning documents from camera video stream.
185-
"""
186-
parser = argparse.ArgumentParser(description='Scan documents from camera')
187-
parser.add_argument('-c', '--camera', default=False, type=bool, help='Whether to show the image')
188-
parser.add_argument('-l', '--license', default='', type=str, help='Set a valid license key')
189-
args = parser.parse_args()
190-
# print(args)
191-
try:
192-
license = args.license
193-
camera = args.camera
194-
195-
if camera is False:
196-
parser.print_help()
197-
return
198-
199-
# set license
200-
if license == '':
201-
docscanner.initLicense("DLS2eyJoYW5kc2hha2VDb2RlIjoiMjAwMDAxLTE2NDk4Mjk3OTI2MzUiLCJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSIsInNlc3Npb25QYXNzd29yZCI6IndTcGR6Vm05WDJrcEQ5YUoifQ==")
202-
else:
203-
docscanner.initLicense(license)
204-
205-
# initialize mrz scanner
206-
scanner = docscanner.createInstance()
207-
ret = scanner.setParameters(docscanner.Templates.color)
208196
209-
if camera is True:
210-
process_video(scanner)
211-
212-
except Exception as err:
213-
print(err)
214-
sys.exit(1)
197+
docscanner.initLicense(
198+
"LICENSE-KEY")
199+
200+
scanner = docscanner.createInstance()
201+
ret = scanner.setParameters(docscanner.Templates.color)
202+
process_video(scanner)
215203
216-
scandocument()
217204
```
218205
219206
![python document scanner from camera](https://www.dynamsoft.com/codepool/img/2022/09/python-document-scanner.png)
220207
221-
## Methods
222-
- `docscanner.initLicense('YOUR-LICENSE-KEY')` # set the license key
208+
## API Methods
209+
- `docscanner.initLicense('YOUR-LICENSE-KEY')`: Set the license key.
223210
224211
```python
225-
docscanner.initLicense("DLS2eyJoYW5kc2hha2VDb2RlIjoiMjAwMDAxLTE2NDk4Mjk3OTI2MzUiLCJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSIsInNlc3Npb25QYXNzd29yZCI6IndTcGR6Vm05WDJrcEQ5YUoifQ==")
212+
docscanner.initLicense("LICENSE-KEY")
226213
```
227214
228-
- `docscanner.createInstance()` # create a Document Scanner instance
215+
- `docscanner.createInstance()`: Create a Document Scanner instance.
229216
230217
```python
231218
scanner = docscanner.createInstance()
232219
```
233-
- `detectFile(filename)` # do edge detection from an image file
220+
- `detectFile(filename)`: Perform edge detection from an image file.
234221
235222
```python
236223
results = scanner.detectFile(<filename>)
237224
```
238-
- `detectMat(Mat image)` # do edge detection from Mat
225+
- `detectMat(Mat image)`: Perform edge detection from an OpenCV Mat.
239226
```python
240227
image = cv2.imread(<filename>)
241228
results = scanner.detectMat(image)
@@ -250,14 +237,14 @@ $ scandocument -c 1 -l <license-key>
250237
y4 = result.y4
251238
```
252239
253-
- `setParameters(Template)` # Select color, binary or grayscale template
240+
- `setParameters(Template)`: Select color, binary, or grayscale template.
254241
255242
```python
256243
scanner.setParameters(docscanner.Templates.color)
257244
```
258245
259-
- `addAsyncListener(callback function)` # start a native thread to run document scanning tasks
260-
- `detectMatAsync(<opencv mat data>)` # put a document scanning task into the native queue
246+
- `addAsyncListener(callback function)`: Start a native thread to run document scanning tasks asynchronously.
247+
- `detectMatAsync(<opencv mat data>)`: Queue a document scanning task into the native thread.
261248
```python
262249
def callback(results):
263250
for result in results:
@@ -277,23 +264,23 @@ $ scandocument -c 1 -l <license-key>
277264
sleep(5)
278265
```
279266
280-
- `normalizeBuffer(mat, x1, y1, x2, y2, x3, y3, x4, y4)` # do perspective correction from Mat
267+
- `normalizeBuffer(mat, x1, y1, x2, y2, x3, y3, x4, y4)`: Perform perspective correction from an OpenCV Mat.
268+
281269
```python
282270
normalized_image = scanner.normalizeBuffer(image, x1, y1, x2, y2, x3, y3, x4, y4)
283271
```
284-
- `normalizeFile(filename, x1, y1, x2, y2, x3, y3, x4, y4)` # do perspective correction from a file
272+
- `normalizeFile(filename, x1, y1, x2, y2, x3, y3, x4, y4)`: Perform perspective correction from an image file.
273+
285274
```python
286275
normalized_image = scanner.normalizeFile(<filename>, x1, y1, x2, y2, x3, y3, x4, y4)
287276
```
288-
- `normalized_image.save(filename)` # save the normalized image to a file
277+
- `normalized_image.save(filename)`: Save the normalized image to a file.
289278
```python
290279
normalized_image.save(<filename>)
291280
```
292-
- `normalized_image.recycle()` # release the memory of the normalized image
293-
- `clearAsyncListener()` # stop the native thread and clear the registered Python function
294-
## C/C++ API
295-
To customize Python API based on C/C++, please refer to the
296-
[online documentation](https://www.dynamsoft.com/document-normalizer/docs/programming/c/api-reference/?ver=latest).
281+
- `normalized_image.recycle()`: Release the memory of the normalized image.
282+
- `clearAsyncListener()`: Stop the native thread and clear the registered Python function.
283+
297284
298285
## How to Build the Python Document Scanner Extension
299286
- Create a source distribution:

setup.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def run(self):
8484

8585

8686
setup(name='document-scanner-sdk',
87-
version='1.0.3',
87+
version='1.1.0',
8888
description='Document Scanner SDK for document edge detection, border cropping, perspective correction and brightness adjustment',
8989
long_description=long_description,
9090
long_description_content_type="text/markdown",
@@ -112,8 +112,8 @@ def run(self):
112112
"Programming Language :: Python :: 3.8",
113113
"Programming Language :: Python :: 3.9",
114114
"Programming Language :: Python :: 3.10",
115-
"Programming Language :: Python :: 3.11",
116-
"Programming Language :: Python :: 3.12",
115+
"Programming Language :: Python :: 3.11",
116+
"Programming Language :: Python :: 3.12",
117117
"Programming Language :: C++",
118118
"Programming Language :: Python :: Implementation :: CPython",
119119
"Topic :: Scientific/Engineering",

0 commit comments

Comments
 (0)