Ejemplo n.º 1
0
def main():
    config = Config()
    # 关系图中包括(include)哪些函数名。
    #如果是某一类的函数,例如类gobang,则可以直接写'gobang.*',表示以gobang.开头的所有函数。(利用正则表达式)。
    config.trace_filter = GlobbingFilter(include=[
        'main',
        'pycallgraph.*',
        '*.secret_function',
    ])
    graphviz = GraphvizOutput()
    graphviz.output_file = 'basic.png'  #图片名称

    with PyCallGraph(output=graphviz):
        # coco
        modelpath = "model/"
        start = time.time()
        pose_model = general_coco_model(modelpath)  # 1.加载模型
        print("[INFO]Pose Model loads time: ", time.time() - start)
        # yolo
        start = time.time()
        _yolo = YOLO()  # 1.加载模型
        print("[INFO]yolo Model loads time: ", time.time() - start)

        img_path = 'D:/myworkspace/dataset/My_test/img/a_img/airplane_30.jpg'

        getImgInfo(img_path, pose_model, _yolo)
Ejemplo n.º 2
0
        f = os.path.join(path, labelname)
        for i, imgname in enumerate(os.listdir(f)):
            imgpath = os.path.join(f, imgname)
            X.append(imgpath)
            Y.append(labelname)

X = np.array(X)
Y = np.array(Y)

# ----------------------------------------------------------------------------------
# 第二步 识别infolist
# ----------------------------------------------------------------------------------
# coco
modelpath = "model/"
start = time.time()
pose_model = general_coco_model(modelpath)  # 1.加载模型
print("[INFO]Pose Model loads time: ", time.time() - start)
# yolo
start = time.time()
_yolo = YOLO()  # 1.加载模型
print("[INFO]yolo Model loads time: ", time.time() - start)

infolist = []
for i in X:
    hist = getImgInfo(i, pose_model, _yolo)  # 识别
    infolist.append(hist)

# ----------------------------------------------------------------------------------
# 第三步 存储信息docs/feature/features_all.csv
# ----------------------------------------------------------------------------------
# 路径存储到txt
Ejemplo n.º 3
0
 def _loadmodel(self):
     start = time.time()
     self.pose_model = general_coco_model(self.model_path)  # coco加载模型
     self._yolo = YOLO()  # 1.加载模型yolo
     self.tips.SetValue(u"模型加载耗时:{:.2f} s".format(time.time() - start) +
                        "\n")
Ejemplo n.º 4
0
def getVideo_Info(modelpath, video_path, output_path=""):
    from cv2 import cv2
    cap = cv2.VideoCapture(video_path)
    if not cap.isOpened():
        raise IOError("Couldn't open webcam or video")
    video_FourCC = int(cap.get(cv2.CAP_PROP_FOURCC))  # 获取原始视频的信息
    video_fps = cap.get(cv2.CAP_PROP_FPS)
    video_size = (int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)),
                  int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)))
    isOutput = True if output_path != "" else False  # 如果设置了视频保存路径,则保存视频
    if isOutput:
        print("!!! TYPE:", type(output_path), type(video_FourCC),
              type(video_fps), type(video_size))
        out = cv2.VideoWriter(output_path, video_FourCC, video_fps,
                              video_size)  # 根据原视频设置 保存视频的路径、大小、帧数
    accum_time = 0
    curr_fps = 0
    fps = "FPS: ??"
    prev_time = time.time()
    yolo = YOLO()
    pose_model = general_coco_model(modelpath)  # 1.加载模型
    while True:
        return_value, frame = cap.read()

        if return_value:
            # 骨骼
            bone_points = pose_model.getBoneKeypoints(frame)  # 2.骨骼关键点
            lineimage, dotimage = pose_model.vis_bone_pose(
                frame, bone_points)  # 骨骼连线图、标记图显示
            # list1 = getBoneInformation(bone_points)  # 3.骨骼特征

            temp, labelinfo = yolo.detect_image(
                Image.fromarray(frame), Image.fromarray(lineimage))  # 检测PIL格式
            result = np.asarray(temp)  # 画图到全部图上
            curr_time = time.time()
            exec_time = curr_time - prev_time
            prev_time = curr_time
            accum_time = accum_time + exec_time
            curr_fps = curr_fps + 1
            if accum_time > 1:
                accum_time = accum_time - 1
                fps = "FPS: " + str(curr_fps)
                curr_fps = 0
            cv2.putText(result,
                        text=fps,
                        org=(3, 15),
                        fontFace=cv2.FONT_HERSHEY_SIMPLEX,
                        fontScale=0.50,
                        color=(255, 0, 0),
                        thickness=2)
            cv2.putText(result,
                        "q-'quit'",
                        org=(3, 45),
                        fontFace=cv2.FONT_HERSHEY_SIMPLEX,
                        fontScale=0.50,
                        color=(0, 255, 0),
                        thickness=2)  # 标注字体
            cv2.namedWindow("result", cv2.WINDOW_NORMAL)
            cv2.imshow("result", result)
            if isOutput:
                out.write(result)
        else:
            print("Frame is end!")
            break
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break
Ejemplo n.º 5
0
def getImageInfo(img_file, modelpath):
    """获得所有信息

    :param 图片,模型路径
    :return list单图的信息
    """

    print("[INFO]Pose estimation.")
    start = time.time()
    pose_model = general_coco_model(modelpath)  # 1.加载模型

    print("[INFO]Model loads time: ", time.time() - start)

    # 骨骼
    start = time.time()
    img = cv2.imread(img_file)
    bone_points = pose_model.getBoneKeypoints(img)  # 2.骨骼关键点
    print("[INFO]COCO18_Model predicts time: ", time.time() - start)
    lineimage, dotimage, black_np = pose_model.vis_bone_pose(
        img, bone_points)  # 骨骼连线图、标记图显示cv2格式

    list1 = getBoneInformation(bone_points)  # 3.骨骼特征
    #print("[INFO]Model Bone Information[25]: ", list1)

    # yolo
    _yolo = YOLO()
    # cv2图片转PIL
    image = Image.open(img_file)
    lineimage = Image.fromarray(cv2.cvtColor(lineimage, cv2.COLOR_BGR2RGB))
    black_np = Image.fromarray(cv2.cvtColor(black_np, cv2.COLOR_BGR2RGB))
    r_image, labelinfo, hand_ROI_PIL = _yolo.detect_image(
        image, black_np)  # 原图,lineimage线图,黑幕图
    # plt.figure(figsize=[5, 5])
    # plt.subplot(1, 2, 1)
    # plt.imshow(r_image)
    # plt.xlabel(u'线图', fontsize=20)
    # plt.axis("off")
    # plt.subplot(1, 2, 2)
    # plt.imshow(cv2.cvtColor(dotimage, cv2.COLOR_BGR2RGB))
    # plt.xlabel(u'点图', fontsize=20)
    # plt.axis("off")
    # plt.show()

    # # 手势
    # print("[INFO]Hands estimation.by handpose")
    # start = time.time()
    # hand_model = general_hand_model(modelpath)  # 1.加载模型

    # hand_fd = hand_fourierDesciptor()

    # for i,handimg in enumerate(hand_ROI_PIL):
    #     img = cv2.cvtColor(np.asarray(handimg),cv2.COLOR_RGB2BGR)

    #     # hand 模型
    #     onehandpoints = hand_model.getOneHandKeypoints(img)
    #     hand_model.vis_hand_pose(img, onehandpoints)# 显示

    #     # hand_FD 描述子
    #     res1 = hand_fd.skinMask(img)  # 进行肤色检测
    #     ret1, fourier = hand_fd.fourierDesciptor(res1)  # 傅里叶描述子获取轮廓点

    info = []
    for i in range(len(list1)):
        info.append(list1[i])
    for j in range(len(labelinfo)):
        info.append(labelinfo[j])
    print(labelinfo)
    return r_image, info