【发布时间】:2020-11-30 10:04:51
【问题描述】:
我创建了一个 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()是保存图片的回调函数。但现在我被困在如何将图像保存到 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
【问题讨论】:
-
"如何将图像保存到 sqlite 数据库中?"你会接受“一点也不”。作为答案?我的意思是不要将图像存储在数据库中,而是将路径/URL 存储到合适的存储位置。如果您不能接受作为答案,请解释是什么阻止您这样做,因为我认为我们可能正在查看 meta.stackexchange.com/questions/66377/what-is-the-xy-problem
-
@Yunnosch 我看过很多关于如何将 sqlite 与 php 集成的在线网站。但我对如何将图像保存到 sqlite 表中感到困惑。因为我不知道要包含在我的 sqlite __function() 中的变量是哪个。你能告诉我如何将它保存到数据库中吗?
-
我的印象是,您实际阅读的评论中只有我的名字。这是因为我觉得我可以通过逐字重复我的第一条评论来回答您的评论。
-
让我修改一下
-
您正在混合服务器端语言 php 和客户端语言:js。如果要将图像保存到数据库中,则需要使用 Ajax
标签: javascript php html sqlite