# Image Crop Implementation with CV2 *author: David Wang*
## Description An image crop operator implementation with OpenCV.
## Code Example Crop the face from 'avengers.jpg'. ``` from towhee 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') ) DataCollection(p('./avengers.jpg')).show() ```
## Factory Constructor Create the operator via the following factory method ***image_crop(clamp = True)*** **Parameters:** **clamp:** *bool* ​ If set True, coordinates of bounding boxes would be clamped into image size.
## Interface An image crop operator takes an image and bounding boxes as input. It cropes the image into ROIs(region of interest). **Parameters:** **img:** *towhee.types.Image (a sub-class of numpy.ndarray)* ​ The image need to be cropped. **bboxes:** *numpy.ndarray* ​ The nx4 numpy tensor for n bounding boxes need to crop, each row is formatted as (x1, y1, x2, y2). **Returns**: *towhee.types.Image (a sub-class of numpy.ndarray)* ​ The cropped image data as numpy.ndarray. # More Resources - [Supercharged Semantic Similarity Search in Production - Zilliz blog](https://zilliz.com/learn/supercharged-semantic-similarity-search-in-production): Building a Blazing Fast, Highly Scalable Text-to-Image Search with CLIP embeddings and Milvus, the most advanced open-source vector database. - [The guide to clip-vit-base-patch32 | OpenAI](https://zilliz.com/ai-models/clip-vit-base-patch32): clip-vit-base-patch32: a CLIP multimodal model variant by OpenAI for image and text embedding. - [Using Vector Search to Better Understand Computer Vision Data - Zilliz blog](https://zilliz.com/blog/use-vector-search-to-better-understand-computer-vision-data): How Vector Search improves your understanding of Computer Vision Data - [Demystifying Color Histograms: A Guide to Image Processing and Analysis - Zilliz blog](https://zilliz.com/learn/demystifying-color-histograms): Mastering color histograms is indispensable for anyone involved in image processing and analysis. By understanding the nuances of color distributions and leveraging advanced techniques, practitioners can unlock the full potential of color histograms in various imaging projects and research endeavors. - [Understanding ImageNet: A Key Resource for Computer Vision and AI Research](https://zilliz.com/glossary/imagenet): The large-scale image database with over 14 million annotated images. Learn how this dataset supports advancements in computer vision. - [From Text to Image: Fundamentals of CLIP - Zilliz blog](https://zilliz.com/blog/fundamentals-of-clip): Search algorithms rely on semantic similarity to retrieve the most relevant results. With the CLIP model, the semantics of texts and images can be connected in a high-dimensional vector space. Read this simple introduction to see how CLIP can help you build a powerful text-to-image service.