I'm doing a test with opencv and python but the code below does not return anything ... Can someone help me by seeing if there is an error?

-1
import numpy as np
import cv2

cap = cv2.VideoCapture('peopleCounter.avi') #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

The error returned by the console is:

Traceback (most recent call last):
  File "/home/adryan/Documentos/Projects/SPtrans/OpenCV/People-Counter/Drawing_2.0.py", line 22, in <module>
    cv2.imshow('Frame 2',frame2)
error: /build/opencv-00QkEr/opencv-2.4.9.1+dfsg1/modules/highgui/src/window.cpp:261: error: (-215) size.width>0 && size.height>0 in function imshow
    
asked by anonymous 31.03.2018 / 03:25

1 answer

0
    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))

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

    cv2.imshow('Frame 2',frame)

This is the solution for those who have the same problem.

    
31.03.2018 / 18:20