Target detection-PIL, OpenCV and numpy represent the mutual conversion of image data formats

1 Introduction

PIL, OpenCV and numpy are several data formats commonly used in Python;

2 PIL and OpenCV

2.1 PIL to OpenCV

The storage format after OpenCV reads the image file is np.array ;

You can refer to the following code:

import cv2

# ———— Show pictures with PLT————

img=cv2.imread('1.jpg') #Open the image, opencv reads the data of the image by default: (height, width, channel (B, G, R)).

img = img[:,:, (2, 1, 0)] # Change the order of image channels to: RGB

# PLT default read image data format: (height, width, channel (R, G, B)).

 

img2=img[: , : , : : -1]

Guess you like

Origin blog.csdn.net/songyuc/article/details/107289819