kbmp-
kbmp-

Reputation: 1

Saving IMAQ image as PNG in MongoDB and exporting it with Python

I am aquiring image data with the LabView IMAQ module. I convert the acquired image to a png string with IMAQ Write String VI and store that string in a MongoDB database. If I fetch this string back from the database, write it to a file with Write to Binary File VI and read that file with IMAQ Read from File, I can display that image.

I can also open the created png file in Windows without problems.

Mock up VI

The string gets send to a REST API written in Python. There I encode the string in utf-8 and store it in gridfs of my MongoDB instance.

I can fetch the png string from the database in LabView without problems and write it into a binary file with the LabView internal vis. I can open this image without problems. But I want to be able to access those images from Python as well without going the route via LabView.

If I fetch the png string from the database through the REST API, where the string gets decoded from utf-8 and send it to Python via the requests.get method and do basically the same procedure to write the string to a binary file with:

raw_string_from_db = 'pngstringdata'
encoded_data = raw.encode('utf-8')
with open('test.png', 'wb') as png_file:
    png_file.write(encoded_data)

I can't open the image in windows or display it in any other way. I have tried converting it to base64, latin1, cp1252, and probably 10 more different encodings, nothing helps. I also tried writing the string directly to a text file, doesn't work either.

Does anybody have an idea what might be the problem here?

Upvotes: 0

Views: 47

Answers (0)

Related Questions