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

0

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

+12

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) https://code.sololearn.com/cfC86Frt41ob/?ref=app https://code.sololearn.com/csyhsIovmZJ3/?ref=app

+11

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: http://docs.opencv.org/trunk/d7/d8b/tutorial_py_face_detection.html

+9

I am on my mobile right now, but I found a thread on SO that perfectly match your need: https://stackoverflow.com/questions/9308978/saving-image-into-sqlite 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.

+2

can you help me with a small example

+1

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)

+1

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.

0

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

0

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