当前位置:网站首页>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
边栏推荐
- Object. The disorder of key value array after keys
- Van uploader upload picture implementation process, using native input to upload pictures
- [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
- decast id.var measure.var数据拆分与合并
- 4.22学习记录(你一天只做了水题是吗)
- 有趣的IDEA插件推荐,给你的开发工作增添色彩
- unity常见的问题(一)
- [Blue Bridge Cup] April 17 provincial competition brushing training (the first three questions)
- No idle servers? Import OVF image to quickly experience smartx super fusion community version
- Free and open source agricultural Internet of things cloud platform (version: 3.0.1)
猜你喜欢

About the 'enum' enumeration type and structure.

Pytorch: a pit about the implementation of gradreverselayer

Recovering data with MySQL binlog

Sort out several uses of network IP agent

SSM framework series - JUnit unit test optimization day2-3

Mysql8 installation

世界读书日:我想推荐这几本书

在线计算过往日期天数,计算活了多少天

Record some NPM related problems (messy records)

Free and open source charging pile Internet of things cloud platform
随机推荐
Process virtual address space partition
21 days learning mongodb notes
Go language slicing operation
Temperature and humidity monitoring + timing alarm system based on 51 single chip microcomputer (C51 source code)
Deploying MySQL in cloud native kubesphere
Importerror after tensorflow installation: DLL load failed: the specified module cannot be found, and the domestic installation is slow
Byte warehouse intern interview SQL questions
Record a website for querying compatibility, string Replaceall() compatibility error
Use Proteus to simulate STM32 ultrasonic srf04 ranging! Code+Proteus
The accuracy and speed are perfectly balanced, and the latest image segmentation SOTA model is released!!!
Record the problems encountered in using v-print
Image attribute of input: type attribute of fashion cloud learning -h5
Embrace the new blue ocean of machine vision and hope to open a new "Ji" encounter for the development of digital economy
Go language: passing slices between functions
【蓝桥杯】4月17日省赛刷题训练(前3道题)
Hanlp word splitter (via spark)
Date time type in database
After the data of El table is updated, the data in the page is not updated this$ Forceupdate() has no effect
How to click an object to play an animation
XinChaCha Trust SSL Organization Validated