0

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

21st Sep 2017, 6:50 PM
Rajkumar Yadav
Rajkumar Yadav - avatar
8 Respostas
+ 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
21st Sep 2017, 7:25 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 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
21st Sep 2017, 7:52 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 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.
21st Sep 2017, 7:36 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 2
can you help me with a small example
21st Sep 2017, 7:30 PM
Rajkumar Yadav
Rajkumar Yadav - avatar
+ 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)
21st Sep 2017, 7:38 PM
Andrew Harchenko (Tomsk)
Andrew Harchenko (Tomsk) - avatar
+ 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.
21st Sep 2017, 7:47 PM
Andrew Harchenko (Tomsk)
Andrew Harchenko (Tomsk) - avatar
0
i can store file too but i am trying to prefer image
21st Sep 2017, 7:43 PM
Rajkumar Yadav
Rajkumar Yadav - avatar
0
else can you tell me how to train image using haar cascade algorithm in OpenCV3
21st Sep 2017, 7:44 PM
Rajkumar Yadav
Rajkumar Yadav - avatar