logo
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Readme
Files and versions

104 lines
1.4 KiB

# Image Decode Implementation with CV2
*author: Kaiyuan Hu, Rentong Guo*
3 years ago
<br />
## Description
2 years ago
An image decode operator implementation with OpenCV.
3 years ago
<br />
3 years ago
## Code Example
Load a image from path './src_dog.jpg'.
the src picture:
<br />
<img src="./src_dog.jpg" height="150px"/>
3 years ago
*Write the pipeline in simplified style:*
3 years ago
```python
from towhee.dc2 import pipe, ops, DataCollection
3 years ago
2 years ago
# decode image, in bgr channel order
p = (
pipe.input('url')
.map('url', 'image', ops.image_decode.cv2())
.output('image')
)
2 years ago
# decode image, in rgb channel order
p2 = (
pipe.input('url')
.map('url', 'image', ops.image_decode.cv2('rgb'))
.output('image')
)
2 years ago
# decode from path
DataCollection(p('./src_dog.jpg')).show()
2 years ago
# decode from bytes
with open('./src_dog.jpg', 'rb') as f:
2 years ago
DataCollection(p2(f.read())).show()
```
<br />
<img src="./dog.png" height="150px"/>
2 years ago
<img src="./src_dog.jpg" height="150px"/>
3 years ago
<br />
## Factory Constructor
Create the operator via the following factory method:
2 years ago
***ops.image_decode.cv2()***
**mode**: *str*
2 years ago
BGR or RGB, default is BGR
3 years ago
<br />
## Interface
2 years ago
An image decode operator takes an image path as input. It decodes the image back to ndarray.
**Parameters:**
**img**: *str*
2 years ago
​ Local file path/http url/image bytes.
3 years ago
**Returns**: *towhee.types.Image (a sub-class of numpy.ndarray)*
3 years ago
​ The decoded image data as numpy.ndarray.
3 years ago