Skip to content

Commit d7441da

Browse files
committed
Update
1 parent 4ffc8f7 commit d7441da

File tree

1 file changed

+5
-43
lines changed

1 file changed

+5
-43
lines changed

examples/official/file.py

Lines changed: 5 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -3,48 +3,7 @@
33
import sys
44
import cv2
55
import numpy as np
6-
7-
8-
def convertNormalizedImage2Mat(normalized_image):
9-
ba = bytearray(normalized_image.get_bytes())
10-
width = normalized_image.get_width()
11-
height = normalized_image.get_height()
12-
13-
channels = 3
14-
if normalized_image.get_image_pixel_format() == EnumImagePixelFormat.IPF_BINARY:
15-
channels = 1
16-
all = []
17-
skip = normalized_image.stride * 8 - width
18-
19-
index = 0
20-
n = 1
21-
for byte in ba:
22-
23-
byteCount = 7
24-
while byteCount >= 0:
25-
b = (byte & (1 << byteCount)) >> byteCount
26-
27-
if index < normalized_image.stride * 8 * n - skip:
28-
if b == 1:
29-
all.append(255)
30-
else:
31-
all.append(0)
32-
33-
byteCount -= 1
34-
index += 1
35-
36-
if index == normalized_image.stride * 8 * n:
37-
n += 1
38-
39-
mat = np.array(all, dtype=np.uint8).reshape(height, width, channels)
40-
return mat
41-
42-
elif normalized_image.get_image_pixel_format() == EnumImagePixelFormat.IPF_GRAYSCALED:
43-
channels = 1
44-
45-
mat = np.array(ba, dtype=np.uint8).reshape(height, width, channels)
46-
47-
return mat
6+
from utils import *
487

498

509
if __name__ == '__main__':
@@ -64,6 +23,9 @@ def convertNormalizedImage2Mat(normalized_image):
6423
if image_path.lower() == "q":
6524
sys.exit(0)
6625

26+
if image_path == "":
27+
image_path = "../../images/1.png"
28+
6729
if not os.path.exists(image_path):
6830
print("The image path does not exist.")
6931
continue
@@ -84,7 +46,7 @@ def convertNormalizedImage2Mat(normalized_image):
8446
image = item.get_image_data()
8547
if image != None:
8648

87-
mat = convertNormalizedImage2Mat(image)
49+
mat = convertImageData2Mat(image)
8850

8951
# Draw the detected rotation angle on the original image
9052
cv_image = cv2.imread(image_path)

0 commit comments

Comments
 (0)