0

I'm trying to convert this string in base64 (http://pastebin.com/uz4ta0RL) to something usable by OpenCV. Currently I am using this code (img_temp is the string) to use the OpenCV functions by converting it to a temp image(imagetosave.jpg) then loading the temp image with cv2.imread.

    fh = open('imagetosave.jpg','wb')
    fh.write(img_temp.decode('base64'))
    fh.close()

    img = cv2.imread('imagetosave.jpg',-1)

Though this method works, I would like to be able to use the OpenCV functions without using a temp image. Help would be much appreciated, thanks!

user3547372
  • 21
  • 1
  • 4

2 Answers2

0

To convert string from base64 to normal you can use

import base64
base64.b64decode("TGlrZSB0aGF0Cg==")

but it itsn't unclear if is what you need.

  • So I'd like to be able to use the string from base64 to a format useable by OpenCV without having to write over imagetosave.jpg since its acting as a temporary image. – user3547372 Nov 30 '15 at 23:14
0

You can convert your decoded string to a list of integers, which you can then pass to the imdecode function:

img_array = map(int, img_temp.decode('base64'))
img = cv2.imdecode(img_array, -1)
Sajjan Singh
  • 2,523
  • 2
  • 27
  • 34