Processing videos

To be able to use any of the algorithms that we've learned so far on videos, we need to be able to read video frames and store them in Mat objects. We have already learned about how to deal with video files, cameras, and RTSP feeds in the initial chapters of this book. So, extending that, using what we learned in the previous chapters, we can use a code similar to the following, in order to apply colormaps to the video feed from the default camera on a computer:

VideoCapture cam(0); // check if camera was opened correctly if(!cam.isOpened()) return -1; // infinite loop while(true) { Mat frame; cam >> frame; if(frame.empty()) break; applyColorMap(frame, frame, COLORMAP_JET); // display the frame imshow("Camera", frame); // ...

Get Hands-On Algorithms for Computer Vision now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.