我這裡有一段代碼,可以從筆記本電腦的内部網絡攝像頭捕捉圖像。我想把我的圖檔直接發送到MySQL資料庫。這是密碼。在import numpy as np
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'中的圖像發送到我的資料庫中,但它不起作用。有什麼想法嗎?在