Visual Intelligence Summit: Oct 22 in San Francisco Get your ticket

Convert PIL Image to cv2 image

Tutorial

You can convert a PIL image to a cv2 image in one line of code. This involves creating a new NumPy array and, often, shuffling the channels of the PIL object from RGB (the format commonly used with PIL) to BGR (the cv2 format).

To convert your image, use the following code:

Python
pil_data = PIL.Image.open('Image.jpg').convert('RGB')
image = numpy.array(pil_data)[:, :, ::-1].copy()

OpenCV can be used with the open source supervision Python package.

supervision provides an extensive range of functionalities for working with computer vision models. With supervision, you can:

1. Process and filter detections and segmentation masks from a range of popular models (YOLOv5, Ultralytics YOLOv8, MMDetection, and more).
2. Process and filter classifications.
3. Compute confusion matrices.

And more! To learn about the full range of functionality in supervision, check out the supervision documentation.

Start where you are

Speak with an AI expert

Our team will help you start solving business problems on the first call.

  • Solution architecting
  • Live demonstration
  • Pricing and specifications
  • Feasibility assessment

Over 16,000 organizations build with Roboflow.

Rivian
Pella
Chobani
USG Corporation
BNSF Railway
American Woodmark
Outcomes
Patrick Industries
Peer Robotics