当前位置:网站首页>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
边栏推荐
- CGC: contractual graph clustering for community detection and tracking
- V-model binding value in El select, data echo only displays value, not label
- STD:: shared of smart pointer_ ptr、std::unique_ ptr
- Synchronously update the newly added and edited data to the list
- Go language array operation
- Remote sensing image classification and recognition system based on convolutional neural network
- MySQL —— 16、索引的数据结构
- Object.keys后key值数组乱序的问题
- 【蓝桥杯】4月17日省赛刷题训练(前3道题)
- Customize classloader and implement hot deployment - use loadclass
猜你喜欢
Process virtual address space partition
Packet capturing and sorting -- TCP protocol [8]
如何实现点击一下物体播放一次动画
Use Proteus to simulate STM32 ultrasonic srf04 ranging! Code+Proteus
Jupiter notebook installation
梳理网络IP代理的几大用途
R语言中dcast 和 melt的使用 简单易懂
8 websites that should be known for product development to enhance work experience
[vulnhub range] - DC2
Recovering data with MySQL binlog
随机推荐
内核错误: No rule to make target ‘debian/canonical-certs.pem‘, needed by ‘certs/x509_certificate_list‘
Get the punch in record of nailing attendance machine
[untitled] make a 0-99 counter, P1 7 connected to key, P2 connected to nixie tube section, common anode nixie tube, P3 0,P3. 1. Connect the nixie tube bit code. Each time you press the key, the nixie
Translation of attention in natural language processing
Record a website for querying compatibility, string Replaceall() compatibility error
MySQL supports IP access
Recovering data with MySQL binlog
Async void provoque l'écrasement du programme
Hanlp word splitter (via spark)
SSM框架系列——数据源配置day2-1
XinChaCha Trust SSL Organization Validated
Install nngraph
Teach you to quickly develop a werewolf killing wechat applet (with source code)
STM32 project transplantation: transplantation between chip projects of different models: Ze to C8
Packet capturing and sorting -- TCP protocol [8]
SSM框架系列——注解开发day2-2
Sort out several uses of network IP agent
Use source insight to view and edit source code
Recommended website for drawing result map
Process virtual address space partition