python - 如何从 dlib.simple_object_detector 获得置信度

标签 python opencv dlib

我已经训练了自己的模型来识别一种模式,我将其作为 .svm,并且在我没有好的轨迹时通过跟踪运动来支持它。这很好用,但我遇到的问题是有时我会收到误报,有时会覆盖最近启动的运动轨迹。

我尝试使用 dir() 记录检测器,但找不到任何置信度字段,并检查了引用,但我找不到如何让此跟踪器输出其置信度级别。

我想做的是基本上有一个系统愿意使用的轨道质量阈值,随着时间的推移逐渐降低。 IE,如果它丢失了我的模式轨迹并立即选择图像的某个随机角来获得低置信度轨迹,它不会覆盖我最近(因此质量)的运动轨迹。而如果运动轨迹已经运行了很长时间,它就更有可能滑落,我更倾向于相信低质量的轨迹。

长话短说;我怎样才能得到这个检测器的置信水平?非常感谢您能给我的任何帮助。

我在下面附上了我的代码以显示上下文

import os
import sys
import glob
import dlib
import cv2


detector_path = sys.argv[1] #first point towards the detector to use
video_path = sys.argv[2] #then point it towards a folder filled with images. Doesn't need to be drawn from video


win = dlib.image_window()
files_to_test = os.listdir(video_path)

detector = dlib.simple_object_detector(detector_path)

tracker = None
tracker_age = 0
for file in files_to_test:
    img = dlib.load_rgb_image(video_path + "/" + file)
    dets = detector(img)
    print("Number of faces detected: {}".format(len(dets)))
    for k, d in enumerate(dets):
        print("Detection {}: Left: {} Top: {} Right: {} Bottom: {}".format(
            k, d.left(), d.top(), d.right(), d.bottom()))
    if len(dets) > 0:
        tracker = dlib.correlation_tracker()
        d = dets[0]
        print(dir(d))
        x = d.left()
        y = d.top()
        x2 = d.right() 
        y2 = d.bottom()
        rect = dlib.rectangle(x,y,x2,y2)
        tracker.start_track(img,rect)
        tracker_age = 0
        win.clear_overlay()
        win.add_overlay(dets)
    else:
        print("relying on motion track for the past {} frames".format(tracker_age))
        if not tracker == None:
            tracker.update(img)
            pos = tracker.get_position()
            startX = int(pos.left())
            startY = int(pos.top())
            endX = int(pos.right())
            endY = int(pos.bottom())
            # draw the bounding box from the correlation object tracker
            cv2.rectangle(img, (startX, startY), (endX, endY),
                (0, 255, 0), 2)

    win.set_image(img)
    dlib.hit_enter_to_continue()

最佳答案

使用 dlib.simple_object_detector 你不会得到你需要的,试试下面的函数:

[框,置信度,detector_idxs] = dlib.fhog_object_detector.run_multiple(检测器,图像,upsample_num_times=1,adjust_threshold=0.0)

参见 http://dlib.net/train_object_detector.py.html了解更多信息

关于python - 如何从 dlib.simple_object_detector 获得置信度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54283017/

相关文章:

python - 如何使用 python 和 opencv 检测图像中的水平线并获取其 y 坐标?

python - OpenCV检测摄像头但不返回图像提要,而guvcview却

python-3.x - Dlib(支持GPU)无法正常工作,不确定吗?

python - 使用OpenCV从图像识别地标和裁剪嘴的脚本看不到面孔

python - Windows 10.0.105 Pro 上的 Pip 问题

c++ - Opencv如何使用MatIterator迭代具有浮点RGB值的彩色图像?

python - 在 Django 中扩展 AbstractUser

python - 如何使用Python和DLib找到在线左侧或右侧的点?

python - 如何使用 POST 方法自动进行网站交互

python - Django 项目无法强制 Google Appengine 重定向到 https