您可以使用PHP+Python的组合创建该解决方案,有几个库可以操作图像以获得所需的结果,在员工ID验证的情况下,Python脚本应该能够识别正在查看的内容,例如,让我们公司里有一个同事,一个相机设备或类似设备拍摄了ID的照片:
客户端应用程序需要不断读取相机或图片,以下是相机和本地保存图片的代码:
Python条形码阅读器:(引入Numpy是增强cv2条形码识别的好主意)
import sys
import cv2
import time
camera = cv2.VideoCapture(0)
if (camera.isOpened() == False):
print("Can not open camera #0.")
sys.exit(0)
print("Camera ready")
doAgain = True
while doAgain:
ret, image = camera.read()
if ret:
qrCodeDetector = cv2.QRCodeDetector()
text, points, _ = qrCodeDetector.detectAndDecode(image)
if points is not None:
print(text)
cv2.imwrite("./result.jpg",image)
else:
print("QR code not detected")
cv2.imshow("Image", image)
key = cv2.waitKey(1) & 0xFF
if key == 27:
cv2.destroyAllWindows()
doAgain = False
camera.release()
服务器端应用程序(PHP):
<?php
$target_dir = "uploads/";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$file = $_FILES["picture"];
if ($file["type"] != "image/jpeg" && $file["type"] != "image/png" && $file["type"] != "image/gif") {
echo "This file is not allowed! IMages only please";
exit();
}
if ($file["size"] > 1000000) {
echo "Error: File size is too large.";
exit();
}
$filename = basename($file["name"]);
$target_path = $target_dir . $filename;
move_uploaded_file($file["tmp_name"], $target_path);
echo "THanks for uploading the image, Barcode is being recognized!";
} else {
echo "No file was uploaded. Try again please";
}
if (move_uploaded_file($file["tmp_name"], $target_path)) {
$python_script = "python /securepathtothescriptorsomeonecouldfindit/to/your/python/script.py " . $target_path;
$output = shell_exec($python_script);
echo "Barcode generated successfully!";
} else {
echo "There was an error processing your image, please contact support";
}
?>
客户端(访问您的网站或网络应用程序的用户):
<!DOCTYPE html>
<html>
<head>
<title>User will upload Picture</title>
<style>
.card {width: 900px;background-color: #f9f9f9;border: 1px solid #ddd;border-radius: 10px;box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);padding: 20px;margin: 40px auto;}
</style>
</head>
<body>
<div class="card">
<h2>Upload Picture</h2>
<form action="action.php" method="post" enctype="multipart/form-data">
<input type="file" name="picture" accept="image/*">
<button type="submit">Upload</button>
</form>
<div id="image-preview"></div>
</div>
<script>
const fileInput = document.querySelector('input[type="file"]');
fileInput.addEventListener('change', (event) => {
const file = event.target.files[0];
const reader = new FileReader();
reader.onload = (event) => {
const imageDataUrl = event.target.result;
document.getElementById('image-preview').innerHTML = `<img src="${imageDataUrl}" alt="Uploaded Image width=200 height=550">`;
};
reader.readAsDataURL(file);
});
</script>
</div>
</body>
</html>
结果:
为了测试这一点,您可以安装XAMPP或类似的工具来本地运行PHP服务器并在没有云的情况下离线测试,或者您可以使用与PHP兼容的公共主机进行测试。