Can anyone help me how to store images in python SQLite3 database and read back from it | Sololearn: Learn to code for FREE!


Can anyone help me how to store images in python SQLite3 database and read back from it

9/21/2017 6:50:46 PM

Rajkumar Yadav

8 Answers

New Answer


You should create a column of BLOB type and store the data you read from a file there. Of course, more reasonable would be to normally store images as files and keep only links to them in the db, but I assumed you figured that out and there is still some reason for which you want to store images not links to them, anyway :) Check out how you can start by linking to sqlite3 database with Python. The only difference would be to add a column of BLOB type, read the file and write the data you receive to the new BLOB column (perhaps storing the filename as a referrer somewhere in the db, too)


Now that's another story. You'll need a matrix-transformation specialized library like numpy and you might want to import pandas, too, in order to facilitate file reading and data storing (pandas' DataFrames are powerful!) Of course, you'll need to import the CV as well. Take a look at the official opencv tutorial doc, it's not that difficult:


I am on my mobile right now, but I found a thread on SO that perfectly match your need: BTW, I still think it's a bad idea to store images as such in the database. Way better would be to store links to them rather than pure image data.


can you help me with a small example


Yes, because it will give a high (higher) load to you DBMS (MySQL, or other DBMS used). And it will be slower than accessing files stored in the file system of your OS. (And you still haven't cleared out why do you need to store images in your DB, or do you really need it that way at all)


Image is a file, at least if you are not talking about drawing or generating image and not saving it... but then you also need to encode it in some format (BMP, PNG, JPG) before storing it in your DB too. You shouldn't _prefer_ it... Only if you'd like to try it for some instance... for an unlikely case that you'll have someday store some (not too many!) images inside a database.


i can store file too but i am trying to prefer image


else can you tell me how to train image using haar cascade algorithm in OpenCV3