Skip to content

Commit e5723d0

Browse files
committed
Fixed grayscale image display
1 parent 0afe0b2 commit e5723d0

File tree

3 files changed

+20
-11
lines changed

3 files changed

+20
-11
lines changed

docscanner/__init__.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class ImagePixelFormat:
3434
IPF_BGR_888 = 12
3535

3636
def convertNormalizedImage2Mat(normalized_image):
37+
3738
bytearray = normalized_image.bytearray
3839
width = normalized_image.width
3940
height = normalized_image.height
@@ -42,21 +43,30 @@ def convertNormalizedImage2Mat(normalized_image):
4243
if normalized_image.format == ImagePixelFormat.IPF_BINARY:
4344
channels = 1
4445
all = []
46+
skip = normalized_image.stride * 8 - width
4547

48+
index = 0
49+
n = 1
4650
for byte in bytearray:
4751

4852
byteCount = 7
4953
while byteCount >= 0:
5054
b = (byte & (1 << byteCount)) >> byteCount
51-
if b == 1:
52-
all.append(255)
53-
else:
54-
all.append(0)
55+
56+
if index < normalized_image.stride * 8 * n - skip:
57+
if b == 1:
58+
all.append(255)
59+
else:
60+
all.append(0)
5561

5662
byteCount -= 1
57-
58-
bytearray = all
59-
width = normalized_image.stride * 8
63+
index += 1
64+
65+
if index == normalized_image.stride * 8 * n:
66+
n += 1
67+
68+
mat = np.array(all, dtype=np.uint8).reshape(height, width, channels)
69+
return mat
6070

6171
elif normalized_image.format == ImagePixelFormat.IPF_GRAYSCALED:
6272
channels = 1

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def run(self):
8383

8484

8585
setup(name='document-scanner-sdk',
86-
version='1.0.2',
86+
version='1.0.3',
8787
description='Document Scanner SDK for document edge detection, border cropping, perspective correction and brightness adjustment',
8888
long_description=long_description,
8989
long_description_content_type="text/markdown",

test_api.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
scanner = docscanner.createInstance()
1111

12-
ret = scanner.setParameters(docscanner.Templates.color)
12+
ret = scanner.setParameters(docscanner.Templates.binary)
1313
print(ret)
1414

1515
def showNormalizedImage(name, normalized_image):
@@ -100,5 +100,4 @@ def callback(results):
100100
scanner.detectMatAsync(image)
101101
sleep(3)
102102

103-
104-
103+
test_detectFile()

0 commit comments

Comments
 (0)