opencv 從本地讀取視頻和文件夾下圖片

讀取視頻

    VideoCapture m_cap;
    VideoWriter videoWriter;
    m_cap.open("...//1.mp4");
    int32_t m_totalFrames = static_cast<int32_t>(m_cap.get(CV_CAP_PROP_FRAME_COUNT)); //total num
    videoWriter.open("D://result.avi", CV_FOURCC('X', 'V', 'I', 'D'), 15, Size(1280, 720));

    for (int32_t idx = 0; idx < 100; idx ++)
    {
        int32_t curBgFrame = 12 * idx % m_totalFrames;
        m_cap.set(CAP_PROP_POS_FRAMES , curBgFrame);
        Mat img;
        m_cap >> img;
        imshow("src", img);
        waitkey(10);
    }

讀取文件夾下圖片

    
    int32_t imgNum = 100;//the max img idx is 100
    for (int32_t idx = 0; idx < imgNum; idx++)
    {
        stringstream ss;
        string num;
        ss << idx;
        ss>>num;
        string addr = "...//";
        string format = ".bmp";
        string wholeString = addr + num + format;
        Mat img = imread(wholeString, 1);
        imshow(num + format, img);
        waitkey(10);
    }

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章