I am writing a program that draws a line on a video where the first pixels of the railing are encountered, my problem is that the video playback is sluggish.
Screenshot for reference of what the video looks like. During the video the camera is moved closer but because of the slow speed, I have to wait a few minutes to see the change, but when filming took place, it was moved every few seconds.
I assume the issue is the fact that the for loops are operating on every single frame of the video but I am not sure.
What solution could I implement to speed up my program?
import cv2
cap = cv2.VideoCapture('video.mp4')
while(cap.isOpened()):
ret, frame = cap.read()
canny = cv2.Canny(frame, 85, 255)
height, width = canny.shape
first_black_array = []
for x in range(width):
first_black_pixel_found = 0
for y in range(height):
if first_black_pixel_found == 0:
if canny[y,x] == 255:
first_black_array.append(height - y)
first_black_pixel_found = 1
cv2.line(frame,(x,y),(x,y),(0,255,0),1)
cv2.imshow('frame',frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
Thanks!