leduckhc
8/28/2019 - 4:15 PM

[VideoCapture] using Video Capture for mp4, rtsp streams #cv2

[VideoCapture] using Video Capture for mp4, rtsp streams #cv2

#include <iostream>
#include <opencv2/core.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/imgproc.hpp>

int main() {
    cv::VideoCapture capture("http://10.0.230.101/mjpg/video.mjpg ");
    cv::String winname = "demo";
    cv::Mat frame;
    char key; // bookkeeping of the key pressed

    while (capture.isOpened()) {
        capture >> frame;
        if (frame.empty())
            break;

        cv::imshow(winname, frame);
        key = (char) cv::waitKey(10);
        if (key == 27 || key == 'q' || key == 'Q')
            break;
    }

    std::cout << "Hello, World!" << std::endl;
    return 0;
}
import cv2

cap = cv2.VideoCapture(0)
while cap.isOpened():
  	ret, frame_bgr = cap.read()
  	if not ret:
    	break