Skip to content

Commit 51638cc

Browse files
committed
2 parents 3cc4bf6 + 2bd5fb8 commit 51638cc

20 files changed

+387
-93
lines changed

Process_Image/.coverage

52 KB
Binary file not shown.

Process_Image/API.ipynb

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,18 +1031,18 @@
10311031
{
10321032
"metadata": {
10331033
"ExecuteTime": {
1034-
"end_time": "2025-05-25T05:53:25.542254Z",
1035-
"start_time": "2025-05-25T05:53:22.499891Z"
1034+
"end_time": "2025-05-25T16:21:02.485162Z",
1035+
"start_time": "2025-05-25T16:20:54.661065Z"
10361036
}
10371037
},
10381038
"cell_type": "code",
10391039
"source": [
10401040
"import requests\n",
10411041
"# url = \"http://localhost:8123/generate_capetion/\"\n",
1042-
"url = \"http://localhost:8123/auto_tag/\"\n",
1042+
"# url = \"http://localhost:8123/auto_tag/\"\n",
10431043
"# url = \"http://localhost:8123/extract_exif/\"\n",
10441044
"# url = \"http://localhost:8123/face_recognition/\"\n",
1045-
"# url = \"http://localhost:8123/process_image/\"\n",
1045+
"url = \"http://localhost:8123/process_image/\"\n",
10461046
"files = {'file': open('photos/25.jpg', 'rb')}\n",
10471047
"response = requests.post(url, files=files)\n",
10481048
"print(response.json())"
@@ -1053,28 +1053,28 @@
10531053
"name": "stdout",
10541054
"output_type": "stream",
10551055
"text": [
1056-
"{'tags': ['computer', 'monitor']}\n"
1056+
"{'Timestamp': '2025-05-25 01:01:41', 'Latitude': None, 'Longitude': None, 'Address': None, 'Camera/Device': 'Xiaomi 23013RK75C', 'Caption': 'a computer monitor', 'AutoTags': ['monitor', 'computer'], 'PersonLabel': []}\n"
10571057
]
10581058
}
10591059
],
1060-
"execution_count": 63
1060+
"execution_count": 11
10611061
},
10621062
{
10631063
"metadata": {
10641064
"ExecuteTime": {
1065-
"end_time": "2025-05-25T08:05:36.461104Z",
1066-
"start_time": "2025-05-25T08:05:19.547419Z"
1065+
"end_time": "2025-05-25T13:42:42.232445Z",
1066+
"start_time": "2025-05-25T13:42:33.238079Z"
10671067
}
10681068
},
10691069
"cell_type": "code",
10701070
"source": [
10711071
"import requests\n",
10721072
"\n",
10731073
"# 替换为你本地或线上 FastAPI 服务的地址\n",
1074-
"url = \"http://localhost:8123/style_transfer/\"\n",
1074+
"url = \"http://10.16.60.67:8123/style_transfer/\"\n",
10751075
"\n",
10761076
"# 要使用的风格编号\n",
1077-
"style_index = 0 # 可以修改为你想测试的风格编号\n",
1077+
"style_index = 1 # 可以修改为你想测试的风格编号\n",
10781078
"\n",
10791079
"# 打开图片并构造 multipart/form-data 请求\n",
10801080
"# with open(image_path, \"rb\") as image_file:\n",
@@ -1104,11 +1104,11 @@
11041104
"output_type": "stream",
11051105
"text": [
11061106
"风格化任务提交成功:\n",
1107-
"{'task_id': '46733e90-ef4d-4a9b-b5dc-15082cd3cd88', 'result_url': 'https://dashscope-result-wlcb.oss-cn-wulanchabu.aliyuncs.com/1d/06/20250525/81750fc9/20250525160537191180_style0_q0laxient5.jpg?Expires=1748246743&OSSAccessKeyId=LTAI5tQZd8AEcZX6KZV4G8qL&Signature=nwrlcZ6tRjivk5D7VD%2FJwI5wxyg%3D'}\n"
1107+
"{'task_id': 'bababc39-a67b-495a-bb96-ed5ef6e57f73', 'result_url': 'https://dashscope-result-wlcb.oss-cn-wulanchabu.aliyuncs.com/1d/be/20250525/81750fc9/20250525214243526580_style0_20hetuzcym.jpg?Expires=1748266969&OSSAccessKeyId=LTAI5tQZd8AEcZX6KZV4G8qL&Signature=13B1BEq0ty1UAUsF0vDUQ73rHZ8%3D'}\n"
11081108
]
11091109
}
11101110
],
1111-
"execution_count": 7
1111+
"execution_count": 10
11121112
},
11131113
{
11141114
"metadata": {

Process_Image/process_image.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,8 +396,24 @@ def generate_video(image_paths: list[str]) -> str:
396396

397397
for idx, img_path in enumerate(image_paths):
398398
im = Image.open(img_path)
399+
# max_size = (1920, 1080)
400+
# im.thumbnail(max_size, Image.Resampling.LANCZOS)
399401
max_size = (1920, 1080)
402+
min_size = (1920, 1080) # 建议设为较合理的最低值
403+
404+
# 先缩小到不超过 max_size,保持比例
400405
im.thumbnail(max_size, Image.Resampling.LANCZOS)
406+
407+
# 如果太小,再放大(保持比例)
408+
width, height = im.size
409+
if width < min_size[0] or height < min_size[1]:
410+
scale_w = min_size[0] / width
411+
scale_h = min_size[1] / height
412+
scale = max(scale_w, scale_h) # 保证放大后两个维度都 ≥ 最小尺寸
413+
new_width = int(width * scale)
414+
new_height = int(height * scale)
415+
im = im.resize((new_width, new_height), Image.Resampling.LANCZOS)
416+
401417
effect_type = random.choice([0, 1])
402418
if effect_type == 0:
403419
x_speed = (im.width - im.width * 0.8) / duration
8.96 KB
Binary file not shown.

Process_Image/tests/sample.jpg

1.94 MB
Loading

Process_Image/tests/test_api.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import os
2+
from fastapi.testclient import TestClient
3+
from process_image import app
4+
5+
client = TestClient(app)
6+
7+
SAMPLE_IMAGE = os.path.join(os.path.dirname(__file__), "sample.jpg")
8+
9+
10+
def test_extract_exif():
11+
with open(SAMPLE_IMAGE, "rb") as f:
12+
response = client.post("/extract_exif/", files={"file": ("sample.jpg", f, "image/jpeg")})
13+
assert response.status_code == 200
14+
data = response.json()
15+
assert "Timestamp" in data
16+
assert "Latitude" in data
17+
assert "Longitude" in data
18+
19+
20+
def test_generate_caption():
21+
with open(SAMPLE_IMAGE, "rb") as f:
22+
response = client.post("/generate_caption/", files={"file": ("sample.jpg", f, "image/jpeg")})
23+
assert response.status_code == 200
24+
assert "caption" in response.json()
25+
26+
27+
def test_auto_tag():
28+
with open(SAMPLE_IMAGE, "rb") as f:
29+
response = client.post("/auto_tag/", files={"file": ("sample.jpg", f, "image/jpeg")})
30+
assert response.status_code == 200
31+
assert "tags" in response.json()
32+
assert isinstance(response.json()["tags"], list)
33+
34+
35+
def test_process_image():
36+
with open(SAMPLE_IMAGE, "rb") as f:
37+
response = client.post("/process_image", files={"file": ("sample.jpg", f, "image/jpeg")})
38+
assert response.status_code == 200
39+
data = response.json()
40+
assert "Caption" in data
41+
assert "AutoTags" in data
42+
assert "PersonLabel" in data

backend/backend.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010

1111
![img.png](backend.assets/img.png)
1212

13+
[🖼️ 图像智能处理后端 API - Swagger UI](http://10.16.60.67:8123/docs)
14+
15+
![image-20250525221802032](backend/image-20250525221802032.png)
16+
1317
## Tests for backend
1418

1519
Technology: jcoco
173 KB
Loading
191 KB
Loading

0 commit comments

Comments
 (0)