This time for everyone to bring Python bulk read the picture and the implementation of the database, Python bulk read the picture and deposit into the database of the attention to what, the following is the actual case, to see together.
This article explains how Python implements bulk-read images and stores them in a MongoDB database. Share to everyone for your reference, as follows:
My picture is placed in E:\image\, and then I use Python to read the picture and then display one, save a picture (which can be commented out), and deposit the image by Gridfs. The code is as follows:
#--* Coding=utf-8 *--from cstringio import stringiofrom pymongo import mongoclientimport gridfsimport osimport matplotlib . Pyplot as Pltimport matplotlib.image as Imingimport bson.binaryimport numpy as npif name = = ' main ': connect = MONGOCL Ient (' 127.0.0.1 ', 27017) # Create connection point db = Connect.mydb print db.collection_names () imgput = Gridfs. GRIDFS (db) dirs = ' G:\image ' files = Os.listdir (dirs) for file in files: filesname = dirs + ' \ \ ' + File
print filesname imgfile=iming.imread (filesname) # iming.imsave (' s.jpg ', imgfile) # Print type ( Imgfile), Imgfile # imgfile.shape () plt.imshow (imgfile) plt.axis (' off ') plt.show () f= File.split ('. ') Print F datatmp=open (Filesname, ' RB ') Data=stringio (Datatmp.read ()) content=bson.binary.binary ( Data.getvalue ()) # Print content insertimg=imgput.put (data,content_type=f[1],filename=f[0]) Datatmp.close ()
Believe that you have read the case of this article you have mastered the method, more exciting please pay attention to the PHP Chinese network other related articles!
Recommended reading:
Python Virtual Tea Party effect
Python3.5 How to install OpenCV in WINDOW10