SQLite Forum

How to read Images from sqlite3 and show via opencv, PIL or Matplot lib ?
Login
As mentioned by Ryan Smith, this is a question that's outside the domain of SQLite.  You asked SQLite for bytes, and it gave you bytes back, what you do with those bytes to display them is very much not something SQLite handles.

That said, the issue is because you're passing the bytes to a function that expects a filename.  If you insist on using OpenCV to decode the image, you need to follow an explicit decode path:

```
for x in m:
    # Convert the image to a numpy array
    image = numpy.asarray(bytearray(x[0]), dtype="uint8")
    # Decode the image to a cv2 image
    s = cv2.imdecode(image, cv2.IMREAD_COLOR)
    # Convert the image from cv2's BGR to RGB that matplotlib expects
    s = cv2.cvtColor(s, cv2.COLOR_BGR2RGB)

    # s = mpimg.imread(io.BytesIO(x[0]))
    plt.imshow(s)
    plt.show()
```

If the goal is actually to just display the image, it's much easier to just use matplotlib directly instead of taking a detour into OpenCV:
```
import matplotlib.image as mpimg
import io
for x in m:
    # Just use matplotlib to decode the image
    plt.imshow(mpimg.imread(io.BytesIO(x[0])))
    plt.show()
```