@@ -30,60 +30,59 @@ unsigned char file[14] = {
30
30
};
31
31
32
32
unsigned char info[40 ] = {
33
- 40 ,
34
- 0 ,
35
- 0 ,
36
- 0 , // info hd size
37
- 0 ,
38
- 0 ,
39
- 0 ,
40
- 0 , // width
41
- 0 ,
42
- 0 ,
43
- 0 ,
44
- 0 , // height
45
- 1 ,
46
- 0 , // number color planes
47
- 24 ,
48
- 0 , // bits per pixel
49
- 0 ,
50
- 0 ,
51
- 0 ,
52
- 0 , // compression is none
53
- 0 ,
54
- 0 ,
55
- 0 ,
56
- 0 , // image bits size
57
- 0x13 ,
58
- 0x0B ,
59
- 0 ,
60
- 0 , // horz resolution in pixel / m
61
- 0x13 ,
62
- 0x0B ,
63
- 0 ,
64
- 0 , // vert resolution (0x03C3 = 96 dpi, 0x0B13 = 72
65
- // dpi)
66
- 0 ,
67
- 0 ,
68
- 0 ,
69
- 0 , // #colors in palette
70
- 0 ,
71
- 0 ,
72
- 0 ,
73
- 0 , // #important colors
74
- };
75
-
76
- }
77
-
78
- void imwrite (const std::string& name, ov::Tensor image, bool convert_bgr2rgb) {
79
- std::ofstream output_file (name, std::ofstream::binary);
80
- OPENVINO_ASSERT (output_file.is_open (), " Failed to open the output BMP image path" );
33
+ 40 ,
34
+ 0 ,
35
+ 0 ,
36
+ 0 , // info hd size
37
+ 0 ,
38
+ 0 ,
39
+ 0 ,
40
+ 0 , // width
41
+ 0 ,
42
+ 0 ,
43
+ 0 ,
44
+ 0 , // height
45
+ 1 ,
46
+ 0 , // number color planes
47
+ 24 ,
48
+ 0 , // bits per pixel
49
+ 0 ,
50
+ 0 ,
51
+ 0 ,
52
+ 0 , // compression is none
53
+ 0 ,
54
+ 0 ,
55
+ 0 ,
56
+ 0 , // image bits size
57
+ 0x13 ,
58
+ 0x0B ,
59
+ 0 ,
60
+ 0 , // horz resolution in pixel / m
61
+ 0x13 ,
62
+ 0x0B ,
63
+ 0 ,
64
+ 0 , // vert resolution (0x03C3 = 96 dpi, 0x0B13 = 72
65
+ // dpi)
66
+ 0 ,
67
+ 0 ,
68
+ 0 ,
69
+ 0 , // #colors in palette
70
+ 0 ,
71
+ 0 ,
72
+ 0 ,
73
+ 0 , // #important colors
74
+ };
81
75
76
+ void imwrite_single_image (const std::string& name, ov::Tensor image, bool convert_bgr2rgb) {
82
77
const ov::Shape shape = image.get_shape ();
83
78
const size_t width = shape[2 ], height = shape[1 ], channels = shape[3 ];
84
79
OPENVINO_ASSERT (image.get_element_type () == ov::element::u8 &&
85
80
shape.size () == 4 && shape[0 ] == 1 && channels == 3 ,
86
- " Image of u8 type and [1, H, W, 3] shape is expected" );
81
+ " Image of u8 type and [1, H, W, 3] shape is expected." ,
82
+ " Given image has shape " , shape, " and element type " , image.get_element_type ());
83
+
84
+ std::ofstream output_file (name, std::ofstream::binary);
85
+ OPENVINO_ASSERT (output_file.is_open (), " Failed to open the output BMP image path" );
87
86
88
87
int padSize = static_cast <int >(4 - (width * channels) % 4 ) % 4 ;
89
88
int sizeData = static_cast <int >(width * height * channels + height * padSize);
@@ -131,3 +130,19 @@ void imwrite(const std::string& name, ov::Tensor image, bool convert_bgr2rgb) {
131
130
output_file.write (reinterpret_cast <const char *>(pad), padSize);
132
131
}
133
132
}
133
+
134
+ } // namespace
135
+
136
+
137
+ void imwrite (const std::string& name, ov::Tensor images, bool convert_bgr2rgb) {
138
+ const ov::Shape shape = images.get_shape (), img_shape = {1 , shape[1 ], shape[2 ], shape[3 ]};
139
+ uint8_t * img_data = images.data <uint8_t >();
140
+
141
+ for (int img_num = 0 , num_images = shape[0 ], img_size = ov::shape_size (img_shape); img_num < num_images; ++img_num, img_data += img_size) {
142
+ char img_name[25 ];
143
+ sprintf (img_name, name.c_str (), img_num);
144
+
145
+ ov::Tensor image (images.get_element_type (), img_shape, img_data);
146
+ imwrite_single_image (img_name, image, true );
147
+ }
148
+ }
0 commit comments