Reference for ultralytics/utils/patches.py
Note
Full source code for this file is available at https://github.com/ultralytics/ultralytics/blob/main/ultralytics/utils/patches.py. Help us fix any issues you see by submitting a Pull Request 🛠️. Thank you 🙏!
ultralytics.utils.patches.imread(filename, flags=cv2.IMREAD_COLOR)
Read an image from a file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filename |
str
|
Path to the file to read. |
required |
flags |
int
|
Flag that can take values of cv2.IMREAD_*. Defaults to cv2.IMREAD_COLOR. |
IMREAD_COLOR
|
Returns:
Type | Description |
---|---|
ndarray
|
The read image. |
Source code in ultralytics/utils/patches.py
ultralytics.utils.patches.imwrite(filename, img, params=None)
Write an image to a file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filename |
str
|
Path to the file to write. |
required |
img |
ndarray
|
Image to write. |
required |
params |
list of ints
|
Additional parameters. See OpenCV documentation. |
None
|
Returns:
Type | Description |
---|---|
bool
|
True if the file was written, False otherwise. |
Source code in ultralytics/utils/patches.py
ultralytics.utils.patches.imshow(winname, mat)
Displays an image in the specified window.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
winname |
str
|
Name of the window. |
required |
mat |
ndarray
|
Image to be shown. |
required |
ultralytics.utils.patches.torch_save(*args, **kwargs)
Use dill (if exists) to serialize the lambda functions where pickle does not do this.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*args |
tuple
|
Positional arguments to pass to torch.save. |
()
|
**kwargs |
dict
|
Keyword arguments to pass to torch.save. |
{}
|