如何将图像编码保存到mysql数据库中?
How to save image encoding into mysql database?
我正在使用 python 人脸识别库来识别未知面孔。
我在 face_encoding 中得到这种类型的编码。它是什么以及如何将此编码存储到 MySQL 数据库中。
[-0.07152465 0.10215988 0.01136428 -0.0308747 -0.16287753 -0.03153189
-0.06578728 -0.14805837 0.15640661 -0.07523477 0.14867496 0.04072035
-0.16808468 -0.00982519 -0.02270632 0.08025806 -0.20561409 -0.12184067
-0.11708203 -0.09774955 -0.06495257 0.02422624 0.00922573 0.01991012
-0.13370116 -0.20686181 -0.1488608 -0.12282808 0.18252769 -0.08956295
0.0171157 0.07873753 -0.1460952 -0.09000996 0.06861175 0.13834456
-0.07108913 -0.01959831 0.20239949 0.05026209 -0.15374154 -0.01580941
0.06390329 0.27492422 0.25704402 0.08602936 0.03448958 -0.04159172
0.14044689 -0.21021228 0.06922252 0.15272671 0.21329369 0.10292344
0.08227161 -0.22346584 0.09088185 0.14461374 -0.1744801 0.11717336
0.13315231 -0.16698143 0.00260702 0.07305491 0.18898451 0.10911863
-0.01746466 -0.16348183 0.23652273 -0.22252038 -0.06905969 0.12435962
-0.07139365 -0.08369306 -0.24058753 -0.06713018 0.39160824 0.16331878
-0.09675828 -0.01672895 -0.0439845 -0.05550656 0.00398231 0.04980896
-0.17432253 -0.07968439 -0.12069637 -0.02069626 0.22844598 -0.00178664
0.06633241 0.1762405 0.02624917 -0.00859033 0.03681781 -0.02436156
-0.13713233 -0.03320267 -0.03164122 -0.09198754 0.03632114 -0.15644331
0.04891206 0.11745825 -0.20992307 0.17861255 -0.07077605 0.00281386
-0.03633321 -0.04432689 -0.02048816 0.02499891 0.28510362 -0.21085122
0.21044926 0.21076941 -0.06554883 0.08499552 0.05917196 0.1140425
-0.05485246 -0.04627831 -0.15220977 -0.10018148 -0.06419093 -0.15043713
0.02276208 0.0441333 ]
我想将这种类型的编码存储到数据库中。
使用 pickle.dumps 序列化此数据并将其传递到数据库的 BLOB 字段。然后使用pickle.loads()
反序列化存储的数据。
示例:
import pickle
import MySQLdb
## Pickle the list into a string
face_pickled_data = pickle.dumps(face_encoding)
## Connect to the database
connection = MySQLdb.connect('localhost','user','pass','myDatabase')
## Create a cursor for interacting
cursor = connection.cursor()
## Add the information to the database table
cursor.execute("""INSERT INTO faces VALUES (NULL, 'faceName', %s)""", (face_pickled_data, ))
## Select what we just added
cursor.execute("""SELECT data FROM faces WHERE name = 'faceName'""")
## Dump the results to a string
rows = cursor.fetchall()
## Get the results
for each in rows:
## The result is also in a tuple
for face_stored_pickled_data in each:
face_data = pickle.loads(face_stored_pickled_data)
我正在使用 python 人脸识别库来识别未知面孔。 我在 face_encoding 中得到这种类型的编码。它是什么以及如何将此编码存储到 MySQL 数据库中。
[-0.07152465 0.10215988 0.01136428 -0.0308747 -0.16287753 -0.03153189
-0.06578728 -0.14805837 0.15640661 -0.07523477 0.14867496 0.04072035
-0.16808468 -0.00982519 -0.02270632 0.08025806 -0.20561409 -0.12184067
-0.11708203 -0.09774955 -0.06495257 0.02422624 0.00922573 0.01991012
-0.13370116 -0.20686181 -0.1488608 -0.12282808 0.18252769 -0.08956295
0.0171157 0.07873753 -0.1460952 -0.09000996 0.06861175 0.13834456
-0.07108913 -0.01959831 0.20239949 0.05026209 -0.15374154 -0.01580941
0.06390329 0.27492422 0.25704402 0.08602936 0.03448958 -0.04159172
0.14044689 -0.21021228 0.06922252 0.15272671 0.21329369 0.10292344
0.08227161 -0.22346584 0.09088185 0.14461374 -0.1744801 0.11717336
0.13315231 -0.16698143 0.00260702 0.07305491 0.18898451 0.10911863
-0.01746466 -0.16348183 0.23652273 -0.22252038 -0.06905969 0.12435962
-0.07139365 -0.08369306 -0.24058753 -0.06713018 0.39160824 0.16331878
-0.09675828 -0.01672895 -0.0439845 -0.05550656 0.00398231 0.04980896
-0.17432253 -0.07968439 -0.12069637 -0.02069626 0.22844598 -0.00178664
0.06633241 0.1762405 0.02624917 -0.00859033 0.03681781 -0.02436156
-0.13713233 -0.03320267 -0.03164122 -0.09198754 0.03632114 -0.15644331
0.04891206 0.11745825 -0.20992307 0.17861255 -0.07077605 0.00281386
-0.03633321 -0.04432689 -0.02048816 0.02499891 0.28510362 -0.21085122
0.21044926 0.21076941 -0.06554883 0.08499552 0.05917196 0.1140425
-0.05485246 -0.04627831 -0.15220977 -0.10018148 -0.06419093 -0.15043713
0.02276208 0.0441333 ]
我想将这种类型的编码存储到数据库中。
使用 pickle.dumps 序列化此数据并将其传递到数据库的 BLOB 字段。然后使用pickle.loads()
反序列化存储的数据。
示例:
import pickle import MySQLdb ## Pickle the list into a string face_pickled_data = pickle.dumps(face_encoding) ## Connect to the database connection = MySQLdb.connect('localhost','user','pass','myDatabase') ## Create a cursor for interacting cursor = connection.cursor() ## Add the information to the database table cursor.execute("""INSERT INTO faces VALUES (NULL, 'faceName', %s)""", (face_pickled_data, )) ## Select what we just added cursor.execute("""SELECT data FROM faces WHERE name = 'faceName'""") ## Dump the results to a string rows = cursor.fetchall() ## Get the results for each in rows: ## The result is also in a tuple for face_stored_pickled_data in each: face_data = pickle.loads(face_stored_pickled_data)