当前位置:网站首页>Pyqt5 store opencv pictures into the built-in sqllite database and query
Pyqt5 store opencv pictures into the built-in sqllite database and query
2022-04-23 13:01:00 【Image processing Daniel】
Create an information table for saving pictures
# Initialize database
db = QtSql.QSqlDatabase.addDatabase('QSQLITE')
db.setDatabaseName('user.db')
db.open()
query = QSqlQuery()
# Create picture information table
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(' Create success ')
take opencv The picture is converted to binary sqllite
# Judge whether it exists
sql_code = "select * from img where imgName='{}'".format(imgName)
query.exec_(sql_code)
if query.next():
QMessageBox.information(self, " Tips ", " The picture already exists !", QMessageBox.Yes)
return 0
# Convert picture to byte stream
success, encoded_image = cv2.imencode('.png', self.img)
content = encoded_image.tobytes()
# Insert data into the database
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)
# Save the data
if not query.exec():
QMessageBox.warning(self, ' Submit failed ', ' Please make sure it does not contain special characters !'+query.lastError().text(), QMessageBox.Ok)
return
QMessageBox.information(self, " Tips ", " Upload successful !", QMessageBox.Yes)
Query the image
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():
# Loading pictures
img = np.frombuffer(query.value(0).tobytes())
版权声明
本文为[Image processing Daniel]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231258096808.html
边栏推荐
- The accuracy and speed are perfectly balanced, and the latest image segmentation SOTA model is released!!!
- Install nngraph
- STM32 project transplantation: transplantation between chip projects of different models: Ze to C8
- STM32 tracking based on open MV
- SSM framework series - JUnit unit test optimization day2-3
- [Blue Bridge Cup] April 17 provincial competition brushing training (the first three questions)
- Custom nail robot alarm
- Byte jump 2020 autumn recruitment programming question: quickly find your own ranking according to the job number
- Free and open source charging pile Internet of things cloud platform
- Translation of multi modal visual tracking: review and empirical comparison
猜你喜欢

No idle servers? Import OVF image to quickly experience smartx super fusion community version

Record some NPM related problems (messy records)

Customize classloader and implement hot deployment - use loadclass

Read the data in Presto through sparksql and save it to Clickhouse

31. Next arrangement

教你快速开发一个 狼人杀微信小程序(附源码)

5 free audio material websites, recommended collection

梳理网络IP代理的几大用途

The accuracy and speed are perfectly balanced, and the latest image segmentation SOTA model is released!!!

Use compressorjs to compress pictures, optimize functions, and compress pictures in all formats
随机推荐
Go iris framework implements multi service Demo: start (listen to port 8084) service 2 through the interface in service 1 (listen to port 8083)
Sort out several uses of network IP agent
V-model binding value in El select, data echo only displays value, not label
STM32 control stepper motor (ULN2003 + 28byj)
Important knowledge of network layer (interview, reexamination, term end)
JMeter operation redis
Introduction to kubernetes
Go language slicing operation
Async void provoque l'écrasement du programme
Translation of multi modal visual tracking: review and empirical comparison
World Book Day: I'd like to recommend these books
mysql支持ip访问
Homomorphic encryption technology learning
Golang implements MD5, sha256 and bcrypt encryption
Golang implements a five insurance and one gold calculator with web interface
51 single chip microcomputer stepping motor control system based on LabVIEW upper computer (upper computer code + lower computer source code + ad schematic + 51 complete development environment)
SQL exercise question 1
Temperature and humidity monitoring + timing alarm system based on 51 single chip microcomputer (C51 source code)
Teach you to quickly develop a werewolf killing wechat applet (with source code)
Free and open source charging pile Internet of things cloud platform