使用python和opencv绘制折线时出错

时间:2016-11-10 08:52:56

标签: python-2.7 opencv

我收到此错误:

  

File" C:/Python27/drawingInTheVideo.py" ;,第22行,在       cv2.imshow('第2帧',第2帧)cv2.error:........ \ opencv \ modules \ highgui \ src \ window.cpp:261:错误:(-215)   size.width> 0&&函数cv :: imshow

中的size.height> 0

我正在使用此代码:

import numpy as np
import cv2

cap = cv2.VideoCapture('vid2.mp4')  # Open video file

while (cap.isOpened()):
    ret, frame = cap.read()  # read a frame
    try:
        cv2.imshow('Frame', frame)
        frame2 = frame
    except:
        # if there are no more frames to show...
        print('EOF')
        break

    line1 = np.array([[100, 100], [300, 100], [350, 200]], np.int32).reshape((-1, 1, 2))
    line2 = np.array([[400, 50], [450, 300]], np.int32).reshape((-1, 1, 2))

    frame2 = cv2.polylines(frame2, [line1], False, (255, 0, 0), thickness=2)
    frame2 = cv2.polylines(frame2, [line2], False, (0, 0, 255), thickness=1)

    cv2.imshow('Frame 2', frame2)

    # Abort and exit with 'Q' or ESC
    k = cv2.waitKey(30) & 0xff
    if k == 27:
        break

cap.release()  # release video file
cv2.destroyAllWindows()  # close all openCV windows

我做错了什么?请帮忙

0 个答案:

没有答案