def color(): if request.method == "POST": password=request.form['password'] image_file = request.files["image"] if password==str(password_hash): image_bytes = image_file.read() image_array = np.frombuffer(image_bytes, dtype=np.uint8) image = cv2.imdecode(image_array, cv2.IMREAD_COLOR) #img = Image.open(io.BytesIO(image_bytes)) data = model_person_data(object_model,image) print("转数据") data1 = pd.DataFrame(data)帮我修改为request接受一个uri值,并转为图片
时间: 2024-02-09 16:07:50 浏览: 182
Django 解决上传文件时,request.FILES为空的问题
当使用URI传递图像时,您需要使用Python的`requests`库向URI发送HTTP请求,将响应作为图像读取,并将其传递给OpenCV以进行处理。下面是一个修改版本的代码,可以实现您的需求:
```python
import requests
import numpy as np
import cv2
def color():
if request.method == "POST":
password = request.form['password']
image_uri = request.form['image_uri']
if password == str(password_hash):
response = requests.get(image_uri)
image_bytes = response.content
image_array = np.frombuffer(image_bytes, dtype=np.uint8)
image = cv2.imdecode(image_array, cv2.IMREAD_COLOR)
data = model_person_data(object_model, image)
print("转数据")
data1 = pd.DataFrame(data)
```
注意,您需要将`image_uri`参数传递给函数作为`request.form`的一部分,它将包含URI字符串。然后,您需要使用Python的`requests`库从URI获取响应。`response.content`将返回响应的字节内容,您可以将其传递给OpenCV进行处理。
阅读全文