opencv访问mysql_使用Python和OpenCV将捕获的图像保存到MySQL数据库

我有一段代码,可以从笔记本电脑的内部摄像头捕捉图像。有了这个图片,我想直接把它发送到我的MySQL数据库。这是密码。在import cv2

import mysql.connector

from mysql.connector import errorcode

from time import sleep

import serial

# Obtain connection string information from the portal

config = {

'host':'oursystem.mysql.database.azure.com',

'user':'user',

'password':'pass',

'database':'projectdb'

}

try:

conn = mysql.connector.connect(**config)

print("Connection established")

except mysql.connector.Error as err:

if err.errno == errorcode.ER_ACCESS_DENIED_ERROR:

print("Something is wrong with the user name or password")

elif err.errno == errorcode.ER_BAD_DB_ERROR:

print("Database does not exist")

else:

print(err)

cursor = conn.cursor()

cursor.execute("CREATE TABLE if not exists Camera (img BLOB);")

cap = cv2.VideoCapture(0)

# Check if the webcam is opened correctly

if not cap.isOpened():

raise IOError("Cannot open webcam")

frame = cap.read()[1]

cursor.execute("INSERT INTO Camera (img) VALUES %s",frame)

cap.release()

正如你们看到的,我试图直接发送一个图像,它被捕捉并保存在我数据库的“frame”变量中,但它不起作用。在

请有人帮帮我

错误

^{pr2}$

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值