当前位置:网站首页>pyqt5 将opencv图片存入内置SQLlite数据库,并查询
pyqt5 将opencv图片存入内置SQLlite数据库,并查询
2022-04-23 12:58:00 【图像处理大大大大大牛啊】
创建一个保存图片的信息表
# 初始化数据库
db = QtSql.QSqlDatabase.addDatabase('QSQLITE')
db.setDatabaseName('user.db')
db.open()
query = QSqlQuery()
# 创建图片信息表
if not query.exec_("create table img(id integer primary key autoincrement,userName TEXT, imgName TEXT,time TEXT,place TEXT,author TEXT,imgType TEXT,imgDesc TEXT,image blob)"):
print( query.lastError().text())
else:
print('创建成功')
将opencv图片转换为二进制存入sqllite
# 判断是否存在
sql_code = "select * from img where imgName='{}'".format(imgName)
query.exec_(sql_code)
if query.next():
QMessageBox.information(self, "提示", "图片已存在!", QMessageBox.Yes)
return 0
# 转换图片为字节流
success, encoded_image = cv2.imencode('.png', self.img)
content = encoded_image.tobytes()
# 将数据插入数据库
query.prepare("insert into img (userName,imgName,time,place,author,imgType,imgDesc,image) values(?,?,?,?,?,?,?,?)")
query.addBindValue(self.username)
query.addBindValue(imgName)
query.addBindValue(time)
query.addBindValue(place)
query.addBindValue(author)
query.addBindValue(imgType)
query.addBindValue(imgDesc)
query.addBindValue(content)
# 保存数据
if not query.exec():
QMessageBox.warning(self, '提交失败', '请确定不包含特殊字符!'+query.lastError().text(), QMessageBox.Ok)
return
QMessageBox.information(self, "提示", "上传成功!", QMessageBox.Yes)
对图像进行查询
sql_code = 'select image from img where userName=="%{}%" and (imgName like "%{}%" or time like "%{}%" or place like "%{}%" or imgDesc like "%{}%" or author like "%{}%" or imgType like "%{}%")'.format(self.username,keyword,keyword,keyword,keyword,keyword,keyword)
query.exec_(sql_code)
while query.next():
# 加载图片
img = np.frombuffer(query.value(0).tobytes())
版权声明
本文为[图像处理大大大大大牛啊]所创,转载请带上原文链接,感谢
https://blog.csdn.net/qq_26696715/article/details/124361028
边栏推荐
- Analysis of InnoDB execution process in MySQL
- Golang implements MD5, sha256 and bcrypt encryption
- Use source insight to view and edit source code
- BUUCTF WEB [BUUCTF 2018]Online Tool
- Sort out several uses of network IP agent
- Pytorch: a pit about the implementation of gradreverselayer
- jmeter操作redis
- 将新增和编辑的数据同步更新到列表
- XinChaCha Trust SSL Organization Validated
- MySQL supports IP access
猜你喜欢
[csnote] ER diagram
Aviation core technology sharing | overview of safety characteristics of acm32 MCU
leetcode:437. 路径总和 III【dfs 选还是不选?】
If you were a golang interviewer, what questions would you ask?
[vulnhub range] - DC2
[Blue Bridge Cup] April 17 provincial competition brushing training (the first three questions)
Huawei cloud MVP email
Try the server for one month for free, and attach the tutorial
Remote sensing image classification and recognition system based on convolutional neural network
Trier les principales utilisations de l'Agent IP réseau
随机推荐
Read the data in Presto through sparksql and save it to Clickhouse
(1) Openjuterpyrab comparison scheme
V-model binding value in El select, data echo only displays value, not label
CVPR 2022&NTIRE 2022|首个用于高光谱图像重建的 Transformer
Unable to create servlet under SRC subfile of idea
Customize the shortcut options in El date picker, and dynamically set the disabled date
Start mqbroker CMD failure resolution
解决disagrees about version of symbol device_create
leetcode-791. 自定义字符串排序
Record a website for querying compatibility, string Replaceall() compatibility error
Go language slicing operation
HQL find the maximum value in a range
If you were a golang interviewer, what questions would you ask?
Importerror after tensorflow installation: DLL load failed: the specified module cannot be found, and the domestic installation is slow
The accuracy and speed are perfectly balanced, and the latest image segmentation SOTA model is released!!!
Object. The disorder of key value array after keys
XinChaCha Trust SSL Organization Validated
SSM framework series - data source configuration day2-1
Idea的src子文件下无法创建servlet
Aviation core technology sharing | overview of safety characteristics of acm32 MCU