コード例 #1
0
def read_video_as_list_by_path(path, fname):
    print 'reading video for ', path, fname
    #cap = cv2.VideoCapture(path + '\\' + fname)
    cap = cv2.VideoCapture()
    cap.open(path + '\\' + fname)
    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)

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

    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()
    size = int2round((width, height))
    fps = int2round(fps)
    fourcc = int2round(fourcc)
    return f, (fourcc, fps, size)
コード例 #2
0
def get_number_interation_ransac(n_model, p_inliers, precision):
    """
    x = 1 - ( 1 - pow(a,m) ) ^ n
    x = log(1-p) / log(1 - pow(a,m)

    :param n_model:
    :param rate_inliers:
    :param precision:
    :return:
    """
    lower =  math.log(1 - math.pow(p_inliers, n_model), 10)

    if lower == 0:
        print 'my_ransac, get_iteration : lower is 0'
        return 0
    else:
        x = math.log(1-precision, 10) / lower
        return int2round(x)
コード例 #3
0
def get_list_draw_every_ellipse(src, ellipse, vvpoints):
    show_list = []
    vvpoint = (int(vvpoints[0]), int(vvpoints[1]))

    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 = (int(ellipse[i][j][0][0]), int(ellipse[i][j][0][1]))
                ellipse_center = int2round(ellipse[i][j][0])
                cv2.line(img, vvpoint, ellipse_center, (0, 255, 0), 1, 8)  # draw orientation line.

                # a, b = get_end_points(ellipse[i][j], width, height)
                # cv2.line(img, int2round(a), int2round(b), (255, 0, 0), 1) # draw line of ellipse

            show_list.append(img)

    return show_list
コード例 #4
0
def preprocess_training_data(img, gt):
    col = img.shape[0]
    x = gt[0]
    y = gt[1]
    w = gt[2]
    h = gt[3]
    o = gt[4]
    center = (x + (w / 2), y + (h / 2))
    distance = get_distance_two_points(center, (x, y))
    distance = int2round(distance)

    if center[1] - distance < 0:
        return None
    if center[1] + distance > col:
        return None
    if len(img) == 2:
        roi = img[center[1] - distance: center[1] + distance, x: x + w]
    else:
        roi = img[center[1] - distance: center[1] + distance, x: x + w, :]
    rotate_matrix = cv2.getRotationMatrix2D((w / 2, distance), o, 1)  # TODO check angle system.

    return cv2.warpAffine(roi, rotate_matrix, (w, 2 * distance))  # , flags=cv2.INTER_LINEAR)
コード例 #5
0
    def prepare_size_ransac(self, ellipse_list):
        # ellipse_table = [[[[], []] for x in range(shape[1])] for x in range(shape[0])]  # repeat [[row] for col]

        size_dic = {}
        for i in range(len(ellipse_list)):  # assgning ellipse at correponding point
            e = ellipse_list[i]
            center = int2round(e[0])
            size = e[1]
            dist = self.get_distance_two_points(self.vvpoint, center)

            if dist not in size_dic:
                size_dic[dist] = [[], []]
            size_dic[dist][0].append(size[0])  # shor axis = width
            size_dic[dist][1].append(size[1])  # long axis = height

        result = {}
        for key in size_dic.keys():
            height = np.array(size_dic[key][1])
            width = np.array(size_dic[key][0])
            result[key] = (width.mean(), height.mean())

        # return height_list,width_list
        return result
コード例 #6
0
    def test_size(self, ellipse_list):
        base_list = []
        height_list = []
        width_list = []
        size_dic = {}
        given_vvpoint = (584, 144)
        for i in range(len(ellipse_list)):  # assgning ellipse at correponding point
            e = ellipse_list[i]
            center = int2round(e[0])
            size = e[1]
            # dist = self.get_distance_two_points(self.vvpoint, center)
            dist = self.get_distance_two_points(given_vvpoint, center)
            base_list.append(dist)
            width_list.append(size[0])
            height_list.append(size[1])

            if dist not in size_dic:
                size_dic[dist] = [[], []]
            size_dic[dist][0].append(size[0])  # shor axis = width
            size_dic[dist][1].append(size[1])  # long axis = height

        plot2d([base_list, width_list, height_list], ["distance", "raw_width", "raw_height"], False, True)
        print len(base_list), len(width_list), len(height_list)
        height_mean_list = []
        width_mean_list = []

        for key in size_dic.keys():
            height = np.array(size_dic[key][1])
            width = np.array(size_dic[key][0])
            height_mean_list.append((height.mean()))
            width_mean_list.append(width.mean())
        print len(size_dic.keys()), len(height_mean_list)

        plot2d(
            [size_dic.keys(), width_mean_list, height_mean_list], ["distance", "mean width", "mean height"], False, True
        )