# Open video
cap = cv2.VideoCapture(input_video)
frame_width = 640
frame_height = 480
cap.set(cv2.CAP_PROP_FRAME_WIDTH, frame_width)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, frame_height)
frame_width = int(round(cap.get(cv2.CAP_PROP_FRAME_WIDTH)))
frame_height = int(round(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)))
print("camera", input_video, " (", frame_width, ",", frame_height, ")")

# Open dobble model
model = load_model('dobble_model.h5')

# Load reference images
train1_dir = dir + '/dobble_deck01_cards_57'
train1_cards = db.capture_card_filenames(train1_dir)
train1_X, train1_y = db.read_and_process_image(train1_cards, 72, 72)

# Load mapping/symbol databases
symbols = db.load_symbol_labels(dir + '/dobble_symbols.txt')
mapping = db.load_card_symbol_mapping(dir + '/dobble_card_symbol_mapping.txt')

print("================================")
print("Dobble Classification Demo:")
print("\tPress ESC to quit ...")
print("\tPress 'p' to pause video ...")
print("\tPress 'c' to continue ...")
print("\tPress 's' to step one frame at a time ...")
print("\tPress 'w' to take a photo ...")
print("================================")
    'dobble_deck09_cards_55', 'dobble_deck10_cards_55'
]
nb_card_decks = len(card_decks)
print("")
print("PARAMETERS:")
print("Normalized shape of images :", ncols, " x ", nrows)
print("Card Decks : ", nb_card_decks, card_decks)

#
# Capture images/labels from data set for training and testing
#

train_cards = []
for d in range(0, nb_card_decks):
    train_dir = dir + '/' + card_decks[d]
    train_cards.append(db.capture_card_filenames(train_dir))

#
# Read images and pre-process to fixed size
#

train_X = []
train_y = []
for d in range(0, nb_card_decks):
    X, y = db.read_and_process_image(train_cards[d], nrows, ncols)
    train_X.append(np.array(X))
    train_y.append(np.array(y))

print("")
print("TRAINING DATA SET:")
for d in range(0, nb_card_decks):
    # lookup the zValue depending on the confidence
    zvalue = _zValues.get(confidence)
    # get the standard deviation
    stdev = math.sqrt((mean * (1 - mean)) / sampleSize)
    # multiply the standard deviation by the zvalue
    interval = zvalue * stdev
    lower = mean - interval
    upper = mean + interval
    return (lower, upper)


#test_dir = './dobble_dataset/dobble_test01_cards'
test_dir = './dobble_dataset/dobble_test02_cards'

test_cards = db.capture_card_filenames(test_dir)
test_set_size = len(test_cards)
np.random.shuffle(test_cards)

test_X, test_y = db.read_and_process_image(test_cards, nrows, ncols)
del test_cards

ntest = len(test_y)

test_X = np.array(test_X)
test_y = np.array(test_y)

# normalize images
test_X = test_X * (1. / 255)

# convert labels in range 0-57 to one-hot encoding