我使用keras 2和tf后端和opencv 3,
我希望从网络摄像头中识别图像而不是
test_image = cv2.imread('cat.jpg')"
此外,我还在实时饲料中堆叠打印标签。我只是不知道如何通过循环和识别来连续获取图像。我知道它可以通过opencv VideoCapture完成,只是不知道该怎么做。
我的其他信息是
num_classes = 4
labels[0:202] = 0
labels[202:404] = 1
labels[404:606] = 2
labels[606:] = 3
names = ['cats', 'dogs', 'horses', 'humans']
我希望你们帮助我。提前谢谢。
以下是我从路径
测试图片的示例代码# Testing a new image
test_image = cv2.imread('cat.jpg')
test_image = cv2.cvtColor(test_image, cv2.COLOR_BGR2GRAY)
test_image = cv2.resize(test_image, (128, 128))
test_image = np.array(test_image)
test_image = test_image.astype('float32')
test_image /= 255
print(test_image.shape)
if num_channel == 1:
if K.image_dim_ordering() == 'th':
test_image = np.expand_dims(test_image, axis=0)
test_image = np.expand_dims(test_image, axis=0)
print(test_image.shape)
else:
test_image = np.expand_dims(test_image, axis=3)
test_image = np.expand_dims(test_image, axis=0)
print(test_image.shape)
else:
if K.image_dim_ordering() == 'th':
test_image = np.rollaxis(test_image, 2, 0)
test_image = np.expand_dims(test_image, axis=0)
print(test_image.shape)
else:
test_image = np.expand_dims(test_image, axis=0)
print(test_image.shape)
# Predicting the test image
print(model.predict(test_image))
print(model.predict_classes(test_image))
答案 0 :(得分:0)
如您所言,您可以使用webpack
进行网络摄像头输入。流程就是这样
cv2.VideoCapture(0)