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!

2
  • stackoverflow.com/a/33522724/5008845 Commented Dec 1, 2015 at 0:01
  • thanks, i thought i had already tried that but i guess not! Commented Dec 1, 2015 at 1:00

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

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.
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)

1 Comment

I'm getting: invalid literal for int() with base 10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.