如何将图像保存到sqlite数据库?

问题描述

我创建了一个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);

    // 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

解决方法

您不应该将图像直接存储在数据库中。我假设您想将其保存为Blob。更好的方法是为图像创建一个单独的文件夹,并将这些图像的路径存储在数据库中。

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...