Пример #1
0
def get_bbox_dict(txtpath):
    det_dict = {}

    txtfile = open(txtpath, 'r')
    txt = txtfile.readlines()

    for tx in txt:
        txx = tx.split('\n')[0]
        txx = txx.split(',')
        # idx, x1, y1, x2, y2, conf, cls_conf, cls_pred = txx

        idx, x1, y1, x2, y2 = int2round(txx[0:5])
        conf, cls_conf = float(txx[5]), float(txx[6])
        cls_pred = txx[7]

        # self.final_result.append(f'{im_name} {x1} {y1} {x2} {y2} {conf} {cls_conf} {cls_pred}')
        # 262 490.5502014160156 399.2558288574219 920.959716796875 1059.2034912109375 0.8572085499763489 0.7573287487030029 person

        if idx in det_dict.keys():
            dets = det_dict[idx]
            dets.append([idx, x1,y1,x2,y2,conf,cls_conf, cls_pred])
            det_dict[idx] =dets
        else:
            det_dict[idx] = [[idx, x1,y1,x2,y2,conf,cls_conf, cls_pred]]

    return det_dict
Пример #2
0
def read_txt2(src_path, cam_nxt):
    f = open(src_path + '/' + cam_nxt + '.txt', 'r')

    gt = {}
    line_count, frame_count, child_count = 0, 0, 0
    while True:
        line = f.readline().split('\n')[0]
        if not line: break
        line_count += 1
        line = tools.int2round(line.split(' '))
        # line (cam, frame, object, _, x, y, w, h)
        fid, oid, x, y, w, h = line[1], line[3], line[4], line[5], line[6], line[7]
        bbox = (x, x + w, y, y + h)

        if w == 0 and h == 0:
            continue

        check_dup(gt, fid, oid)
        if fid in gt.keys():
            frame = gt[fid]
            frame[oid] = bbox
            child_count += 1
        else:
            frame_count += 1
            frame = {oid: bbox}
            gt[fid] = frame

    f.close()

    if var.DEBUG:
        print('Read text %d lines' % (line_count))
        print('unique frame count ', frame_count, ' child count ', child_count,' = ' , frame_count+child_count)

    return gt
Пример #3
0
def read_txt(src_path, cam_nxt):
    f = open(src_path + '/' + cam_nxt + '.txt', 'r')

    prvs_idx = -1
    gt = []

    while True:
        line = f.readline().split('\n')[0]
        if not line: break

        line = tools.int2round(line.split(' '))
        curr_idx = line[1]  # frame dix
        id, x, y, w, h = line[3], line[4], line[5], line[6], line[7]
        bbox = (x, x + w, y, y + h)

        if prvs_idx == curr_idx:
            frame = gt[-1]
            frame[id] = bbox
        else:
            frame = {id: bbox}
            gt.append(frame)
            prvs_idx = curr_idx

    f.close()
    return gt
Пример #4
0
def get_list_draw_every_ellipse(src, ellipse):
    """
    drawing ellipses for each image.

    :param src: image list
    :param ellipse: ellipse(center,size,orientation) list
    :return: image list
    """
    show_list = []

    idx = 0
    for i in range(len(src)):
        img = src[i].copy()
        if len(ellipse[i]) != 0:

            for j in range(
                    len(ellipse[i])
            ):  # draw all contours and line corresponding to contour.
                cv2.ellipse(img, ellipse[i][j], (0, 255, 0), 1)
                ellipse_center = tools.int2round(ellipse[i][j][0])
                cv2.putText(img, str(idx), ellipse_center,
                            cv2.FONT_HERSHEY_COMPLEX_SMALL, 1.0,
                            (255, 255, 255))
                idx += 1
            show_list.append(img)

    return show_list
def read_video_as_list_by_path(path, fname):
    """

    :param path: path to video file
    :param fname: video file name
    :return: image list
    """
    cap = cv2.VideoCapture()
    cap.open(path + '/' + fname)

    if not cap.isOpened():
        print 'tools, read video as list by path : file not exist'
        return None

    fps = cap.get(cv2.cv.CV_CAP_PROP_FPS)
    fourcc = cap.get(cv2.cv.CV_CAP_PROP_FOURCC)
    width = cap.get(cv2.cv.CV_CAP_PROP_FRAME_WIDTH)
    height = cap.get(cv2.cv.CV_CAP_PROP_FRAME_HEIGHT)

    f = []
    while 1:
        ret, frame = cap.read()

        if ret is False:
            break
        f.append(frame)

    if len(f) is 0:
        print 'tools, read video as list by path : no frames in video'
        return None

    cap.release()
    return f, tools.int2round(fps)
Пример #6
0
    def read_count_groundtruth(self):
        """
        reads text file which contains groundtruth.
        :return:
        """

        lines = files.read_text(self.res_path, 'count_gt')
        res = []
        for line in lines:
            tmp = line.split(',')
            tmp = tools.int2round(tmp)
            res.append(tmp)
        return res