提交 eff6bad1 编写于 作者: W weixin_68179602

Auto Commit

上级 ae4a9dd7
......@@ -13,6 +13,7 @@
<input type="file" id="uploadFile" accept="image/png">
<script>
let imgName;
let imgData;
const uploadFileInput = document.getElementById('uploadFile');
uploadFileInput.addEventListener('change', function() {
const files = uploadFileInput.files;
......@@ -20,21 +21,20 @@
imgName = files[0].name;
console.log(imgName);
}
/*
const file = uploadFileInput.files[0];
const reader = new FileReader();
reader.readAsDataURL(file);
reader.onload = function() {
const imagePath = reader.result;
console.log(imagePath);
// 在这里你可以将路径赋值给一个变量、显示到页面上等操作
reader.onloadend = function(e) {
imgData = e.target.result;
};
*/
});
function runPython(){
run = pyscript.interpreter.globals.get("run");
run(imgName);
run(imgData);
}
</script>
<!--<button py-click="run()">RUN</button>-->
......
......@@ -2,11 +2,23 @@ import math
import js
import numpy as np
from PIL import Image
import base64
import io
def extract_image(image_path, count):
def extract_image(image_data, count):
# 从数据 URL 中提取编码后的图片内容部分
image_data = image_data.split(',')[1]
# 将图片内容部分进行 Base64 解码
decoded_image_data = base64.b64decode(image_data)
# 创建内存中的二进制数据流对象
image_stream = io.BytesIO(decoded_image_data)
# 使用 PIL 打开二进制数据流对象,得到 PIL 图像对象
# 打开图片
img = Image.open(image_path)
img = Image.open(image_stream)
# 获取图片的宽度和高度
width, height = img.size
......@@ -62,10 +74,10 @@ def extract_image(image_path, count):
def run(image_path):
print(image_path)
def run(image_data):
#print(image_data)
count = 30
new_image = extract_image(image_path, count)
new_image = extract_image(image_data, count)
display(new_image,target="mpl")
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册