V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
ne6rd
V2EX  ›  问与答

有能在本地运行,扫描图片中是否有人物/人脸的工具嘛

  •  
  •   ne6rd · 145 天前 · 1498 次点击
    这是一个创建于 145 天前的主题,其中的信息可能已经有所发展或是发生改变。

    需求: 本地运行,不依赖网络服务 Windows 环境 扫描某个文件夹下的所有 jpg/png 照片,分辨率大概从 800px 到 4000px 都有可能,检测是否主要拍摄对象是人物/人脸 硬件是 5800x+3060ti ,效率要能接受

    请问目前的技术可能嘛?现成的或者需要哪些开源库可以自己撸一个?有没有 c#支持的,还是说这方面必须要 python

    13 条回复    2023-12-05 13:40:31 +08:00
    ne6rd
        1
    ne6rd  
    OP
       145 天前   ❤️ 1
    问了 chatgpt ,给了几行代码好像就解决问题了,真香。
    ```
    import cv2

    # Load pre-trained Haar cascade classifier for human detection
    human_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + 'haarcascade_fullbody.xml')

    # Read the image
    image = cv2.imread('C:\\~\\code\\py\\human_detect\\img\\none.jpg')

    # Convert the image to grayscale
    gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

    # Detect human bodies in the image
    humans = human_cascade.detectMultiScale(gray, scaleFactor=1.1, minNeighbors=5)

    if len(humans) > 0:
    print("Human detected!")
    else:
    print("No humans detected.")
    ```
    ne6rd
        2
    ne6rd  
    OP
       144 天前
    然而 haarcascades 检测效果不太行, 也可能是参数调的不对。
    Muniesa
        3
    Muniesa  
       144 天前 via Android
    有好几个 XML ,可以都试试
    tyzandhr
        4
    tyzandhr  
       144 天前 via Android
    OpenCV
    wph95
        5
    wph95  
       144 天前
    mediapipe
    SeaRecluse
        6
    SeaRecluse  
       144 天前   ❤️ 1
    与 New Bing 对话:
    给我是一个使用 insightface 库和 opencv 的 python 脚本对一个文件下的所有图片进行检测,如果图片里有包含人脸,就单独复制到一个文件夹里,加上进度条显示

    ```
    import os
    import cv2
    import shutil
    import insightface
    from tqdm import tqdm

    # 初始化模型
    model = insightface.app.FaceAnalysis()

    # 加载模型
    ctx_id = -1
    model.prepare(ctx_id = ctx_id)

    # 源文件夹和目标文件夹
    src_dir = 'src_dir'
    dst_dir = 'dst_dir'

    # 获取源文件夹中的所有图片
    images = [f for f in os.listdir(src_dir) if os.path.isfile(os.path.join(src_dir, f))]

    # 创建目标文件夹
    os.makedirs(dst_dir, exist_ok=True)

    # 遍历所有图片
    for image in tqdm(images, desc="Processing images"):
    img_path = os.path.join(src_dir, image)
    img = cv2.imread(img_path)

    # 使用模型检测人脸
    faces = model.get(img)

    # 如果检测到人脸,将图片复制到目标文件夹
    if faces:
    print(img_path)
    shutil.copy(img_path, dst_dir)

    ```
    tool2d
        7
    tool2d  
       144 天前
    以前我做过相关调研,很多算法只能统计正脸效果,两个眼睛一个鼻子那种。

    但是需求方说,还要统计后脑勺,这就有点难度了。
    SeaRecluse
        8
    SeaRecluse  
       144 天前
    @tool2d 你的需求方要的是人头检测,而你找的算法是人脸检测当然不行喽。人头检测是从人形检测中分出来的子任务。
    x86
        9
    x86  
       144 天前
    什么库可以做到这种效果
    isquare
        10
    isquare  
       144 天前   ❤️ 1
    AI 人脸检测都快做到头了,没必要用传统检测算法了

    检测只是大多数人脸人物的第一步,就比如这个项目: https://github.com/ageitgey/face_recognition/blob/master/README_Simplified_Chinese.md ,调一个接口检测人脸,只不过用的 dlib ,检测亚洲人效果一般

    还有很多国内开源项目,比如 https://github.com/PaddlePaddle/PaddleDetection/blob/release/2.7/deploy/README.md

    支持部署一个 server ,可以通过网络接口调用
    mekopean
        11
    mekopean  
       144 天前
    retinaface 或者
    yolo 官网下个 pt -> from ultralytics import YOLO - > model = YOLO("cfgs/yolov8l.pt") -> results = model(image, conf=0.8)
    ne6rd
        12
    ne6rd  
    OP
       144 天前
    目前测试 face_recognition 中,同样速度下,比 haarcascades 要准确多了
    ne6rd
        13
    ne6rd  
    OP
       144 天前
    insightface 又远超 face_recognition 速度和准确度
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   910 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 22:24 · PVG 06:24 · LAX 15:24 · JFK 18:24
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.