-1

Suppose there exists a numpy array, data. I am trying to do the equivalent of the following

cv2.imwrite(filename, data)
with open(filename, 'rb') as fp:
     data_compressed = filename.read()

without having to write to a file. Is there a way to convert numpy array to its equivalent PNG/JPG... representation without having to write to a file and read it as binary?

Makketronix
  • 1,389
  • 1
  • 11
  • 31

1 Answers1

0

As Miki pointed out, imencode(...) is the solution.

Makketronix
  • 1,389
  • 1
  • 11
  • 31