SQLite Forum

How to read Images from sqlite3 and show via opencv, PIL or Matplot lib ?
Login
Hi, so i can read the images fine ( In bytes mode), but how can i display them ? How to convert the bytes.?
Now one approach is i read the BLOB data and then write the file to hard drive and then load the file and then display it, which can be A lot of overheads. Any other way to do this ?

My code:

import sqlite3

from PIL import Image

import matplotlib.pyplot as plt

import cv2

import numpy


conn = sqlite3.connect("Sneakers.db")

cur = conn.cursor()

m = cur.execute(""" SELECT * FROM PRODS """)

for x in m:

   s = cv2.imread(x[0])

   plt.imshow(s)


   plt.show()



Error:

TypeError: Can't convert object of type 'bytes' to 'str' for 'filename'

and When i use PIL to read the SQL query Data, i get the following error

ValueError: embedded null byte