[英]How to save image into sqlite database?
我創建了一個 php 文件index.php
用於面罩檢測程序,一旦用戶按下按鈕,它將在本地保存到桌面。 我的問題是如何將其保存到數據庫中並在index.php
中通知?
我的index.php
文件
<!DOCTYPE html>
<h1>COVID-19 Mask Detection<h1>
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.9.0/p5.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.9.0/addons/p5.dom.min.js"></script>
<script src="https://unpkg.com/ml5@latest/dist/ml5.min.js"></script>
<button type="button" onclick="save()">Save Now</button>
<script type="text/javascript">
// Classifier Variable
let classifier;
// Model URL
let imageModelURL = 'https://teachablemachine.withgoogle.com/models/QLX6cenjl/';
// Video
let video;
let flippedVideo;
// To store the classification
let label = "";
// Load the model first
function preload() {
classifier = ml5.imageClassifier(imageModelURL + 'model.json');
}
function setup() {
createCanvas(1920, 750);
// Create the video
video = createCapture(VIDEO);
video.size(1920, 750);
video.hide();
flippedVideo = ml5.flipImage(video);
// Start classifying
classifyVideo();
}
function save() {
<?php
$database = SQLITE3_OPEN_READWRITE('data.db');
?>
}
function draw() {
background(0);
// Draw the video
image(flippedVideo, 0, 0);
// Draw the label
fill(255);
textSize(16);
textAlign(CENTER);
text(label, width / 2, height - 4);
}
// Get a prediction for the current video frame
function classifyVideo() {
flippedVideo = ml5.flipImage(video);
classifier.classify(flippedVideo, gotResult);
flippedVideo.remove();
}
// When we get a result
function gotResult(error, results) {
// If there is an error
if (error) {
console.error(error);
return;
}
// The results are in an array ordered by confidence.
// console.log(results[0]);
label = results[0].label;
// Classifiy again!
classifyVideo();
}
</script>
在function save()
是用於保存圖像的回調 function。 但現在我被困在如何將圖像保存到 sqlite 數據庫中。
錯誤日志:
Fatal error: Uncaught Error: Call to undefined function SQLITE3_OPEN_READWRITE() in C:\wamp64\www\Tester\index.php on line 80
Error: Call to undefined function SQLITE3_OPEN_READWRITE() in C:\wamp64\www\Tester\index.php on line 80
您不應該將圖像直接存儲在數據庫中。 我假設您想將其保存為 blob。 更好的方法是為圖像創建一個單獨的文件夾並將這些圖像的路徑存儲在數據庫中。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.