Exemple #1
0
    # for fname in images:
    #     frame = cv2.imread(fname)
    # for m in data:

    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    ret, corners = cv2.findChessboardCorners(
        gray, (3, 3),
        None,
        flags=cv2.CALIB_CB_ADAPTIVE_THRESH + cv2.CALIB_CB_NORMALIZE_IMAGE +
        cv2.CALIB_CB_FAST_CHECK)
    destx = s0x
    desty = s0y
    # if True:
    if ret == True:
        m = cv2.mean(corners)
        xhistory.extend(np.array([m[0]]))
        yhistory.extend(np.array([m[1]]))
        count += 1
        if count < 12:
            continue

        dx = xhistory.get()
        dispx = np.mean(dx[-3:]) - np.mean(dx[-6:-3])
        last_dispx = np.mean(dx[-9:-6]) - np.mean(dx[-6:-3])
        changed_directionx = np.sign(dispx) != np.sign(last_dispx)
        if changed_directionx:
            tmp = dx[-2:]
            xhistory = RingBuffer(ringlen)
            xhistory.extend(np.array(tmp))
            dx = xhistory.get()
            dispx = dx[-1] - dx[-2]