Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Do the loop in the main function (untested code, but easy to understand):

laserHPos=0;
laserVPos=100;
while(cap.isOpened()):
    ret, frame = cap.read()

    if frame is None:
        exit()

    cv2.line(frame, (laserHPos, laserVPos), (laserHPos + 40, laserVPos), (0,0,255), 5)

    laserHPos += 10; # update the horizontal position of the laser
    if laserHPos > vCol:
        laserHPos=0; #shoot a new laser...
        laserVPos=numpy.random.randint(vRow); # on a random line

    cv2.imshow('frame', frame)

    if cv2.waitKey(33) >= 0:
        break

    last_frame = frame

The idea is to keep the laser position in a variable, update and reinitialize it when needed.