小编lah*_*oda的帖子

在谷歌 Colab 中使用 cv2.imshow()

我正在尝试通过输入视频来对视频进行对象检测

cap = cv2.VideoCapture("video3.mp4")

在处理部分之后,我想使用实时对象检测显示视频

while True:
ret, image_np = cap.read()

# Expand dimensions since the model expects images to have shape: [1, None, None, 3]
image_np_expanded = np.expand_dims(image_np, axis=0)
# Actual detection.
output_dict = run_inference_for_single_image(image_np_expanded, detection_graph)
# Visualization of the results of a detection.
vis_util.visualize_boxes_and_labels_on_image_array(
    image_np,
    output_dict['detection_boxes'],
    output_dict['detection_classes'],
    output_dict['detection_scores'],
    category_index,
    instance_masks=output_dict.get('detection_masks'),
    use_normalized_coordinates=True,
    line_thickness=8)

cv2.imshow('object detection', cv2.resize(image_np, (800, 600)))
if cv2.waitKey(25) & 0XFF == ord('q'):
    cv2.destroyAllWindows()
    break
Run Code Online (Sandbox Code Playgroud)

但是 colab 说 cv2.imshow() 被禁用并使用 cv2_imshow()。但它只渲染图像。[一帧一帧]。我想像使用 cv2.imshow() 那样将视频输出。请帮我解决这个问题。提前致谢。

附上我的完整代码

import numpy as np …
Run Code Online (Sandbox Code Playgroud)

python cv2 google-colaboratory

5
推荐指数
2
解决办法
2万
查看次数

标签 统计

cv2 ×1

google-colaboratory ×1

python ×1