Skip to content

Commit 2c79daf

Browse files
committed
人脸抽取,支持摄像头分辨率选择
1 parent 58f05a2 commit 2c79daf

11 files changed

Lines changed: 854 additions & 37 deletions

File tree

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
1-
<img width="1800" height="766" alt="新版本" src="https://github.com/SECTL/SecRandom/blob/master/data/assets/icon/secrandom-beta.png" />
1+
<img width="1800" height="766" alt="新版本" src="https://github.com/SECTL/SecRandom/blob/master/data/assets/icon/secrandom-release.png" />
22

3-
v2.3 - Shiroko (砂狼白子) beta 3
3+
v2.3 - Shiroko (砂狼白子) release 1
44

55
## 🚀 主要更新
66

77
- 新增 **设置搜索**,支持子项页定位,且能高亮显示搜索结果
8+
- 新增 **人脸抽取**,支持摄像头分辨率选择
89

910
## 💡 功能优化
1011

11-
-
12+
- 优化 **人脸抽取**,默认模型更改为 version-RFB-640.onnx
1213

1314
## 🐛 修复问题
1415

1516
- 修复 **人脸抽选**,打包后模型无法读取
1617
- 修复 **设置窗口**,最大化侧边栏无法展开
17-
- 修复 **摄像头预热**,退出时 QThread 报错
18+
- 修复 **摄像头预热**,避免 QThread 自等待
19+
- 修复 **人脸抽取**,启动多线程崩溃
1820

1921
## 🔧 其它变更
2022

app/Language/modules/extraction_settings.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1203,6 +1203,11 @@
12031203
"name": "摄像头",
12041204
"description": "选择人脸抽取使用的摄像头设备",
12051205
},
1206+
"camera_display_resolution": {
1207+
"name": "摄像头显示分辨率",
1208+
"description": "选择摄像头预览采集分辨率(默认使用最高)",
1209+
"recommended_suffix": "推荐",
1210+
},
12061211
"detector_type": {
12071212
"name": "检测模型",
12081213
"description": "选择相机预览的人脸检测模型文件(ONNX)",
@@ -1258,6 +1263,11 @@
12581263
"name": "Camera",
12591264
"description": "Select the camera device for face picking",
12601265
},
1266+
"camera_display_resolution": {
1267+
"name": "Camera resolution",
1268+
"description": "Select capture resolution for camera preview (default: highest)",
1269+
"recommended_suffix": "Recommended",
1270+
},
12611271
"detector_type": {
12621272
"name": "Detection model",
12631273
"description": "Select ONNX model file for camera preview",
@@ -1310,6 +1320,11 @@
13101320
"name": "カメラ",
13111321
"description": "顔抽選に使用するカメラデバイスを選択",
13121322
},
1323+
"camera_display_resolution": {
1324+
"name": "カメラ解像度",
1325+
"description": "カメラプレビューの解像度を選択(デフォルトは最大)",
1326+
"recommended_suffix": "推奨",
1327+
},
13131328
"detector_type": {
13141329
"name": "検出モデル",
13151330
"description": "カメラプレビューで使用する ONNX モデルファイルを選択",

app/common/camera_preview_backend/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
from app.common.camera_preview_backend.devices import (
44
CameraDeviceInfo,
55
get_cached_camera_devices,
6+
get_recommended_camera_resolution,
67
list_camera_devices,
8+
list_camera_resolutions,
79
warmup_camera_devices,
810
warmup_camera_devices_async,
911
)
@@ -16,7 +18,9 @@
1618
__all__ = [
1719
"CameraDeviceInfo",
1820
"get_cached_camera_devices",
21+
"get_recommended_camera_resolution",
1922
"list_camera_devices",
23+
"list_camera_resolutions",
2024
"warmup_camera_devices",
2125
"warmup_camera_devices_async",
2226
"OpenCVCaptureWorker",

app/common/camera_preview_backend/detection.py

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations
22

33
import math
4+
import threading
45
from pathlib import Path
56
from typing import Optional, Tuple
67

@@ -10,6 +11,7 @@
1011

1112

1213
Rect = Tuple[int, int, int, int]
14+
_CV2_IMPORT_LOCK = threading.Lock()
1315

1416

1517
def merge_face_rects(frame_size: Tuple[int, int], rects: list[Rect]) -> list[Rect]:
@@ -348,17 +350,12 @@ def _ultralight_input_size_from_name(model_name: str) -> Tuple[int, int]:
348350

349351

350352
def create_ultralight_net(*, model_path: Path):
351-
import cv2
353+
with _CV2_IMPORT_LOCK:
354+
import cv2
352355

353356
if not hasattr(cv2, "dnn"):
354357
raise RuntimeError("OpenCV dnn is not available in this build")
355-
try:
356-
blob = model_path.read_bytes()
357-
if not blob:
358-
raise RuntimeError("ONNX file is empty")
359-
return cv2.dnn.readNetFromONNX(blob)
360-
except Exception:
361-
return cv2.dnn.readNetFromONNX(str(model_path))
358+
return cv2.dnn.readNetFromONNX(str(model_path))
362359

363360

364361
def _generate_ultralight_priors(input_size: Tuple[int, int]):
@@ -631,17 +628,12 @@ def ensure_scrfd_model_path(
631628

632629

633630
def create_scrfd_net(*, model_path: Path):
634-
import cv2
631+
with _CV2_IMPORT_LOCK:
632+
import cv2
635633

636634
if not hasattr(cv2, "dnn"):
637635
raise RuntimeError("OpenCV dnn is not available in this build")
638-
try:
639-
blob = model_path.read_bytes()
640-
if not blob:
641-
raise RuntimeError("ONNX file is empty")
642-
return cv2.dnn.readNetFromONNX(blob)
643-
except Exception:
644-
return cv2.dnn.readNetFromONNX(str(model_path))
636+
return cv2.dnn.readNetFromONNX(str(model_path))
645637

646638

647639
def detect_faces_scrfd(

0 commit comments

Comments
 (0)