123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>LineDetect Alpha_v1.02</title>
- <style>
- body {
- font-family: Arial, sans-serif;
- margin: 0;
- padding: 0;
- display: flex;
- justify-content: center;
- align-items: center;
- height: 100vh;
- background-color: #f0f4f8;
- }
- .container {
- text-align: center;
- width: 80%;
- max-width: 2000px;
- background-color: #ffffff;
- border-radius: 8px;
- padding: 40px;
- box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
- overflow: auto; /* ?????? */
- }
- h1 {
- color: #333;
- font-size: 24px;
- margin-bottom: 20px;
- }
- h2.subtitle {
- color: #666;
- font-size: 18px;
- margin-bottom: 20px;
- }
- input[type="file"] {
- margin-bottom: 20px;
- padding: 10px;
- font-size: 16px;
- border: 1px solid #ccc;
- border-radius: 4px;
- }
- button {
- padding: 12px 20px;
- background-color: #4CAF50;
- color: white;
- border: none;
- border-radius: 4px;
- font-size: 16px;
- cursor: pointer;
- transition: background-color 0.3s;
- }
- button:hover {
- background-color: #45a049;
- }
- .result {
- visibility: hidden; /* ??????? */
- display: flex;
- flex-direction: column;
- align-items: center;
- margin-top: 40px;
- max-height: 60vh; /* ?????? */
- overflow-y: auto; /* ??????? */
- }
- .result img {
- max-width: 100%; /* ????????? */
- height: auto; /* ??????????? */
- object-fit: cover;
- border-radius: 8px;
- box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
- margin-bottom: 20px;
- }
- .uploaded-image {
- width: 512px; /* ???? */
- height: 512px; /* ???? */
- object-fit: cover; /* ???????????????? */
- border-radius: 8px;
- box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
- }
- </style>
- </head>
- <body>
- <div class="container">
- <h1>LineDetect Alpha_v1.02</h1> <!-- ???? -->
- <h2 class="subtitle">请上传图片</h2> <!-- ????? -->
- <input type="file" id="fileInput" accept="image/*" />
- <button onclick="uploadImage()">上传</button> <!-- ?????? -->
- <div class="result">
- <div>
- <h2>原图</h2>
- <img id="uploadedImage" class="uploaded-image" src="" alt="Uploaded Image" style="display: none;" />
- </div>
- <div>
- <h2>结果</h2>
- <img id="resultImage" src="" alt="Prediction Result" style="display: none;" />
- </div>
- </div>
- </div>
- <script>
- async function uploadImage() {
- const fileInput = document.getElementById('fileInput');
- const file = fileInput.files[0];
- if (!file) {
- alert("???????????");
- return;
- }
- // ?? canvas ?????? 512x512
- const resizedImageBlob = await resizeImage(file, 512, 512);
- // ???????
- const uploadedImage = document.getElementById('uploadedImage');
- uploadedImage.src = URL.createObjectURL(resizedImageBlob);
- uploadedImage.style.display = 'block';
- // ???????????
- const formData = new FormData();
- formData.append("file", resizedImageBlob, file.name); // ??????
- const response = await fetch('http://192.168.50.100:808/predict', {
- method: 'POST',
- body: formData,
- });
- if (response.ok) {
- const resultBlob = await response.blob();
- const resultImage = document.getElementById('resultImage');
- resultImage.src = URL.createObjectURL(resultBlob);
- resultImage.style.display = 'block';
- document.querySelector('.result').style.visibility = 'visible'; // ????
- } else {
- alert("?????");
- }
- }
- /**
- * ?? canvas ????
- * @param {File} file - ??????
- * @param {number} width - ????
- * @param {number} height - ????
- * @returns {Promise<Blob>} - ???????? Blob
- */
- async function resizeImage(file, width, height) {
- return new Promise((resolve, reject) => {
- const img = new Image();
- img.onload = () => {
- const canvas = document.createElement('canvas');
- canvas.width = width;
- canvas.height = height;
- const ctx = canvas.getContext('2d');
- // ????????????
- ctx.drawImage(img, 0, 0, width, height);
- // ? canvas ??? Blob
- canvas.toBlob(blob => {
- resolve(blob);
- }, file.type || 'image/jpeg');
- };
- img.onerror = reject;
- img.src = URL.createObjectURL(file);
- });
- }
- </script>
- </body>
- </html>
|