Update Image
docs to improve rendering.
The [API docs](https://developers.google.com/mediapipe/api/solutions/python/mp/Image) have a few rendering issues. e.g., the doc generator will turn ``` This block: Anything here ``` Into a table with heading `This block` and `Anything here` as a plain-text cell. In order to render code as code, it needs to be in backticks. They can also be in `>>> code()` format, and we can try to run them ([doctests](https://docs.python.org/3/library/doctest.html)). I'll have a dashboard ready soon that shows areas we can improve. PiperOrigin-RevId: 495715576
This commit is contained in:
parent
62f0034033
commit
8d2473c751
|
@ -48,16 +48,19 @@ void ImageSubmodule(pybind11::module* module) {
|
||||||
become immutable after creation.
|
become immutable after creation.
|
||||||
|
|
||||||
Creation examples:
|
Creation examples:
|
||||||
import cv2
|
|
||||||
cv_mat = cv2.imread(input_file)[:, :, ::-1]
|
|
||||||
rgb_frame = mp.Image(format=ImageFormat.SRGB, data=cv_mat)
|
|
||||||
gray_frame = mp.Image(
|
|
||||||
format=ImageFormat.GRAY, data=cv2.cvtColor(cv_mat, cv2.COLOR_RGB2GRAY))
|
|
||||||
|
|
||||||
from PIL import Image
|
```python
|
||||||
pil_img = Image.new('RGB', (60, 30), color = 'red')
|
import cv2
|
||||||
image = mp.Image(
|
cv_mat = cv2.imread(input_file)[:, :, ::-1]
|
||||||
format=mp.ImageFormat.SRGB, data=np.asarray(pil_img))
|
rgb_frame = mp.Image(format=ImageFormat.SRGB, data=cv_mat)
|
||||||
|
gray_frame = mp.Image(
|
||||||
|
format=ImageFormat.GRAY, data=cv2.cvtColor(cv_mat, cv2.COLOR_RGB2GRAY))
|
||||||
|
|
||||||
|
from PIL import Image
|
||||||
|
pil_img = Image.new('RGB', (60, 30), color = 'red')
|
||||||
|
image = mp.Image(
|
||||||
|
format=mp.ImageFormat.SRGB, data=np.asarray(pil_img))
|
||||||
|
```
|
||||||
|
|
||||||
The pixel data in an Image can be retrieved as a numpy ndarray by calling
|
The pixel data in an Image can be retrieved as a numpy ndarray by calling
|
||||||
`Image.numpy_view()`. The returned numpy ndarray is a reference to the
|
`Image.numpy_view()`. The returned numpy ndarray is a reference to the
|
||||||
|
@ -65,15 +68,18 @@ void ImageSubmodule(pybind11::module* module) {
|
||||||
numpy ndarray, it's required to obtain a copy of it.
|
numpy ndarray, it's required to obtain a copy of it.
|
||||||
|
|
||||||
Pixel data retrieval examples:
|
Pixel data retrieval examples:
|
||||||
for channel in range(num_channel):
|
|
||||||
for col in range(width):
|
|
||||||
for row in range(height):
|
|
||||||
print(image[row, col, channel])
|
|
||||||
|
|
||||||
output_ndarray = image.numpy_view()
|
```python
|
||||||
print(output_ndarray[0, 0, 0])
|
for channel in range(num_channel):
|
||||||
copied_ndarray = np.copy(output_ndarray)
|
for col in range(width):
|
||||||
copied_ndarray[0,0,0] = 0
|
for row in range(height):
|
||||||
|
print(image[row, col, channel])
|
||||||
|
|
||||||
|
output_ndarray = image.numpy_view()
|
||||||
|
print(output_ndarray[0, 0, 0])
|
||||||
|
copied_ndarray = np.copy(output_ndarray)
|
||||||
|
copied_ndarray[0,0,0] = 0
|
||||||
|
```
|
||||||
)doc",
|
)doc",
|
||||||
py::dynamic_attr());
|
py::dynamic_attr());
|
||||||
|
|
||||||
|
@ -156,9 +162,11 @@ void ImageSubmodule(pybind11::module* module) {
|
||||||
An unwritable numpy ndarray.
|
An unwritable numpy ndarray.
|
||||||
|
|
||||||
Examples:
|
Examples:
|
||||||
|
```
|
||||||
output_ndarray = image.numpy_view()
|
output_ndarray = image.numpy_view()
|
||||||
copied_ndarray = np.copy(output_ndarray)
|
copied_ndarray = np.copy(output_ndarray)
|
||||||
copied_ndarray[0,0,0] = 0
|
copied_ndarray[0,0,0] = 0
|
||||||
|
```
|
||||||
)doc");
|
)doc");
|
||||||
|
|
||||||
image.def(
|
image.def(
|
||||||
|
@ -191,10 +199,12 @@ void ImageSubmodule(pybind11::module* module) {
|
||||||
IndexError: If the index is invalid or out of bounds.
|
IndexError: If the index is invalid or out of bounds.
|
||||||
|
|
||||||
Examples:
|
Examples:
|
||||||
|
```
|
||||||
for channel in range(num_channel):
|
for channel in range(num_channel):
|
||||||
for col in range(width):
|
for col in range(width):
|
||||||
for row in range(height):
|
for row in range(height):
|
||||||
print(image[row, col, channel])
|
print(image[row, col, channel])
|
||||||
|
```
|
||||||
)doc");
|
)doc");
|
||||||
|
|
||||||
image
|
image
|
||||||
|
@ -224,7 +234,9 @@ void ImageSubmodule(pybind11::module* module) {
|
||||||
A boolean.
|
A boolean.
|
||||||
|
|
||||||
Examples:
|
Examples:
|
||||||
|
```
|
||||||
image.is_aligned(16)
|
image.is_aligned(16)
|
||||||
|
```
|
||||||
)doc");
|
)doc");
|
||||||
|
|
||||||
image.def_static(
|
image.def_static(
|
||||||
|
|
Loading…
Reference in New Issue
Block a user