SoFunction
Updated on 2024-11-16

and Usage and differences

For the path contains Chinese images, directly with the read will report an error, the last time I saw a big brother use can be read normally, a little curious, so today to record the two uses and differences.

1. Comparison of the two ways of reading images

Normal reading of the image

import cv2
path = '/data/Beijing/'
img = (path)

Running the above code willReport an error!

Reading images from memory

import cv2
path = '/data/Beijing/'
arr = (path, dtype=np.uint8)
img = (arr, flags=cv2.IMREAD_COLOR)

Running the above code, theSuccess!

And the image band order obtained by imdecode is RGB, not BGR, which is the difference with opencv.

Function Description:

Reads an image from a buffer in memory

  Constructs data from text or binary files into arrays

2. Comparison of the two ways of saving images

Normal reading of the image
import cv2
out_path = '/data/Beijing/'
(out_path,img)

Running the above code willReport an error!

Reading images from memory

import cv2
out_path = '/data/Beijing/'
arr = ('png',img)
out[1].tofile(out_path)

Running the above code, theSuccess!

Function Description:

  Encoding images into a memory buffer

  Write data from an array to a file in binary format

To this article on and the use of this article is introduced to this, more related and content please search for my previous articles or continue to browse the following related articles I hope you will support me more in the future!