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

86 lines
1.3 KiB

3 years ago
# Image Crop Implementation with CV2
*author: David Wang*
<br />
## Description
3 years ago
An image crop operator implementation with OpenCV.
<br />
## Code Example
Crop the face from 'avengers.jpg'.
3 years ago
```
from towhee.dc2 import pipe, ops, DataCollection
p = (
pipe.input('path')
.map('path', 'img', ops.image_decode())
.map('img', ('box','score'), ops.face_detection.retinaface())
.map(('img', 'box'), 'crop', ops.image_crop(clamp = True))
.output('img', 'crop')
)
3 years ago
DataCollection(p('./avengers.jpg')).show()
```
3 years ago
<img src="./result2.png" height="150px"/>
3 years ago
<br />
## Factory Constructor
Create the operator via the following factory method
***image_crop(clamp = True)***
3 years ago
**Parameters:**
**clamp:** *bool*
​ If set True, coordinates of bounding boxes would be clamped into image size.
3 years ago
<br />
## Interface
An image crop operator takes an image and bounding boxes as input. It cropes the image into ROIs(region of interest).
3 years ago
**Parameters:**
**img:** *towhee.types.Image (a sub-class of numpy.ndarray)*
3 years ago
​ The image need to be cropped.
3 years ago
**bboxes:** *numpy.ndarray*
3 years ago
​ The nx4 numpy tensor for n bounding boxes need to crop, each row is formatted as (x1, y1, x2, y2).
3 years ago
**Returns**: *towhee.types.Image (a sub-class of numpy.ndarray)*
​ The cropped image data as numpy.ndarray.
3 years ago
3 years ago