【问题标题】:How would I send live video using OpenCV to Tensorflow?如何使用 OpenCV 将实时视频发送到 Tensorflow?
【发布时间】:2019-11-25 03:03:15
【问题描述】:

基本上,我使用了 Teachable Machine,这是 Google 的一个网站,可让您训练自己的机器学习模型。它还具有可以导出代码的功能。我从未使用过 Tensorflow 或 OpenCV/cv2,所以这对我来说是一个相当艰巨的过程。

这是我的代码:

from PIL import Image
import numpy as np
import cv2
import numpy as np
import matplotlib.pyplot as plt 
# Disable scientific notation for clarity
np.set_printoptions(suppress=True)

cap = cv2.VideoCapture(0)
# Load the model
model = tensorflow.keras.models.load_model('keras_model.h5', compile=False)

# Create the array of the right shape to feed into the keras model
# The 'length' or number of images you can put into the array is
# determined by the first position in the shape tuple, in this case 1.
data = np.ndarray(shape=(1, 224, 224, 3), dtype=np.float32)

# Replace this with the path to your image
image = Image.open('Path to your image')

# Make sure to resize all images to 224, 224 otherwise they won't fit in the array
image = image.resize((224, 224))
image_array = np.asarray(image)

# Normalize the image
normalized_image_array = (image_array.astype(np.float32) / 127.0) - 1

# Load the image into the array
data[0] = normalized_image_array

# run the inference
prediction = model.predict(data)
print(prediction)

它是直接来自可教机器。目前,该程序只允许我上传程序将分类的单个图像。

是否可以使用我的程序(最好使用 openCV)将实时视频流式传输到该程序。

另外,如果您有时间,能否告诉我如何在程序已识别的类周围放置彩色框。

如果要求太多,我很抱歉!

【问题讨论】:

    标签: python-3.x opencv tensorflow


    【解决方案1】:

    在这个 github 问题中有一个如何做你所问的例子:https://github.com/googlecreativelab/teachablemachine-community/issues/55#issuecomment-560447633

    希望有效

    【讨论】:

      猜你喜欢
      • 2016-09-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-01
      • 1970-01-01
      • 2015-09-08
      • 2021-05-07
      • 2013-09-16
      相关资源
      最近更新 更多