#includeusing namespace cv; int main() { VideoCapture cap(0); // 0 represents the default camera if (!cap.isOpened()) return -1; Mat frame; while (true) { cap.read(frame); if (frame.empty()) break; imshow("Camera", frame); if (waitKey(30) == 27) break; // escape key to quit } return 0; }
#includeThis example reads video data from a file named "testvideo.mp4" and displays it in a window named "Video". The while loop continues until the user presses the escape key. Package Library: OpenCVusing namespace cv; int main() { VideoCapture cap("testvideo.mp4"); if (!cap.isOpened()) return -1; Mat frame; while (true) { cap.read(frame); if (frame.empty()) break; imshow("Video", frame); if (waitKey(30) == 27) break; // escape key to quit } return 0; }