I am working on a project related to object detection using Mask RCNN on google colab. I have a video uploaded to my colab. I want to display it as a video while processing it at the runtime using openCV. I want to do what cv2.VideoCapture('FILE_NAME')
does on the local machine. Is there any way to do it?
Advertisement
Answer
Found I way to do it. But it is very slow.
JavaScript
x
19
19
1
from IPython.display import clear_output, Image
2
import base64
3
4
def arrayShow (imageArray):
5
ret, png = cv2.imencode('.png', imageArray)
6
encoded = base64.b64encode(png)
7
return Image(data=encoded.decode('ascii'))
8
9
video_capture = cv2.VideoCapture(VIDEO_SOURCE)
10
while video_capture.isOpened():
11
success, frame = video_capture.read()
12
13
clear_output(wait=True)
14
img = arrayShow(frame)
15
display(img)
16
17
if cv2.waitKey(1) & 0xFF == ord('q'):
18
break
19
The code does not play video exactly. It just displays the new frame and removes the old frame from output.