3
3
import sys
4
4
import cv2
5
5
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 *
48
7
49
8
50
9
if __name__ == '__main__' :
@@ -64,6 +23,9 @@ def convertNormalizedImage2Mat(normalized_image):
64
23
if image_path .lower () == "q" :
65
24
sys .exit (0 )
66
25
26
+ if image_path == "" :
27
+ image_path = "../../images/1.png"
28
+
67
29
if not os .path .exists (image_path ):
68
30
print ("The image path does not exist." )
69
31
continue
@@ -84,7 +46,7 @@ def convertNormalizedImage2Mat(normalized_image):
84
46
image = item .get_image_data ()
85
47
if image != None :
86
48
87
- mat = convertNormalizedImage2Mat (image )
49
+ mat = convertImageData2Mat (image )
88
50
89
51
# Draw the detected rotation angle on the original image
90
52
cv_image = cv2 .imread (image_path )
0 commit comments