|
|
|
# Image Decode Implementation with CV2
|
|
|
|
|
|
|
|
*author: Kaiyuan Hu, Rentong Guo*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<br />
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## Desription
|
|
|
|
|
|
|
|
An image decode operator implementation with OpenCV.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<br />
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## Code Example
|
|
|
|
|
|
|
|
Load a image from path './dog.jpg'.
|
|
|
|
|
|
|
|
*Write the pipeline in simplified style*:
|
|
|
|
|
|
|
|
```python
|
|
|
|
import towhee
|
|
|
|
|
|
|
|
towhee.glob('./dog.jpg') \
|
|
|
|
.image_decode.cv2() \
|
|
|
|
.show()
|
|
|
|
```
|
|
|
|
|
|
|
|
*Write a same pipeline with explicit inputs/outputs name specifications:*
|
|
|
|
|
|
|
|
```python
|
|
|
|
import towhee
|
|
|
|
|
|
|
|
towhee.glob['path']('./dog.jpg') \
|
|
|
|
.image_decode.cv2['path', 'img']() \
|
|
|
|
.select('img') \
|
|
|
|
.show()
|
|
|
|
```
|
|
|
|
|
|
|
|
<img src="./show_result.jpg" align='left' style="height: 150px; "/>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<br />
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## Factory Constructor
|
|
|
|
|
|
|
|
Create the operator via the following factory method
|
|
|
|
|
|
|
|
***image_decode.cv2()***
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<br />
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## Interface
|
|
|
|
|
|
|
|
An image decode operator takes an image path as input. It decodes the image back to ndarray.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
**Parameters:**
|
|
|
|
|
|
|
|
***img***: *str*
|
|
|
|
|
|
|
|
Image file path.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
**Returns**: *numpy.ndarray*
|
|
|
|
|
|
|
|
The decoded image data.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|