使用Tensorflow和python进行对象识别的屏幕抓取

使用Tensorflow和python进行对象识别的屏幕抓取,python,tensorflow,machine-learning,computer-vision,Python,Tensorflow,Machine Learning,Computer Vision,伙计们,我想知道如何使用屏幕抓取的图像,然后使用Tensorflow对数据进行分类,并在对象周围绘制方框,我希望屏幕抓取和分类能够足够快地完成,以连续并模拟视频。在使用cascase-haras方法之前,我已经这样做了。我有一个工作的tensorflow模型和一个自定义的推理图,所有这些都与网络摄像头和视频一起工作。我想知道如何更改以下代码以从图像而不是视频读取相关数据: def from_img(img): ret, frame = video.read() <-- i want t

伙计们,我想知道如何使用屏幕抓取的图像,然后使用Tensorflow对数据进行分类,并在对象周围绘制方框,我希望屏幕抓取和分类能够足够快地完成,以连续并模拟视频。在使用cascase-haras方法之前,我已经这样做了。我有一个工作的tensorflow模型和一个自定义的推理图,所有这些都与网络摄像头和视频一起工作。我想知道如何更改以下代码以从图像而不是视频读取相关数据:

def from_img(img):
ret, frame = video.read()   <-- i want to change this line to read this data from the image
frame_expanded = np.expand_dims(frame, axis=0)

# Perform the actual detection by running the model with the image as input
(boxes, scores, classes, num) = sess.run(
    [detection_boxes, detection_scores, detection_classes, num_detections],
    feed_dict={image_tensor: frame_expanded})

# Draw the results of the detection (aka 'visulaize the results')
vis_util.visualize_boxes_and_labels_on_image_array(
    frame,
    np.squeeze(boxes),
    np.squeeze(classes).astype(np.int32),
    np.squeeze(scores),
    category_index,
    use_normalized_coordinates=True,
    line_thickness=8,
    min_score_thresh=0.85)

# All the results have been drawn on the frame, so it's time to display it.
cv2.imshow('Object detector', frame)
来自img(img)的def

ret,frame=video.read()ret,frame=video.read()为真如果帧读取正确,则这是ret位,frame只是从视频中提取的一帧,即图像。看来你已经在对视频中的图像进行分类了

如果要对图像进行分类,例如与脚本保存在同一目录中的.jpg文件

img = cv2.imread('img.jpg')
然后以这种方式输入图像

img = cv2.imread('img.jpg')