To reduce memory usage, we choose to store the jpeg strings of image instead of the numpy array in the buffer. This function decodes the observation numpy arr from the jpeg strings Parameters ---------- s: string the inputs gray_scale: bool True -> the inputs obse
(s, gray_scale=False)
| 329 | |
| 330 | |
| 331 | def str_to_arr(s, gray_scale=False): |
| 332 | """To reduce memory usage, we choose to store the jpeg strings of image instead of the numpy array in the buffer. |
| 333 | This function decodes the observation numpy arr from the jpeg strings |
| 334 | Parameters |
| 335 | ---------- |
| 336 | s: string |
| 337 | the inputs |
| 338 | gray_scale: bool |
| 339 | True -> the inputs observation is gray not RGB. |
| 340 | """ |
| 341 | nparr = np.frombuffer(s, np.uint8) |
| 342 | if gray_scale: |
| 343 | arr = cv2.imdecode(nparr, cv2.IMREAD_GRAYSCALE) |
| 344 | arr = np.expand_dims(arr, -1) |
| 345 | else: |
| 346 | arr = cv2.imdecode(nparr, cv2.IMREAD_COLOR) |
| 347 | |
| 348 | return arr |