相关文章推荐
个性的拐杖  ·  swagger 多文件上传 - ...·  1 年前    · 
斯文的剪刀  ·  java - Apache Mina ...·  1 年前    · 
眉毛粗的水桶  ·  Pandas —— ...·  1 年前    · 
#include <opencv2/core/core.hpp>      
#include <opencv2/highgui/highgui.hpp>      
#include <opencv2/imgproc/imgproc.hpp>     
#include <opencv2/imgcodecs.hpp>  
#include <opencv2/videoio.hpp>   
#include <iostream>    
using namespace std;
using namespace cv;
int main()
#if 0
    //-------------【1】读取视频文件-------------
    VideoCapture capture;
    capture.open("xxxpath/input.h264");
    //方式二:VideoCapture capture("xxxpath/input.h264");
    //-------------【2】判断视频读取是否正确-------------
    if (!capture.isOpened())
        cout << "打开视频文件失败,请重新输入正确路径!" << endl;
        system("pause");
        return -1;
    //-------------【3】获取视频相关信息-------------
    //获取视频相关信息——帧数
    long nTotalFrame = capture.get(CV_CAP_PROP_FRAME_COUNT);
    cout << "帧数 = " << nTotalFrame << endl;
    //获取视频相关信息——帧像素宽/高
    int frameHeight = capture.get(CV_CAP_PROP_FRAME_HEIGHT);
    int frameWidth = capture.get(CV_CAP_PROP_FRAME_WIDTH);
    cout << "帧像素高 = " << frameHeight << endl;
    cout << "帧像素宽 = " << frameWidth << endl;
    //获取视频相关信息——帧率
    double FrameRate = capture.get(CV_CAP_PROP_FPS);
    cout << "帧率 = " << FrameRate << endl;
    //--------------【4】循环显示每一帧---------------
    long nCount = 1;    //计数,当前帧号
    bool flag = true;
    while (flag)
        //输出当前帧号
        cout << "当前帧号: " << nCount << endl;
        Mat frameImg;//定义一个Mat变量,用于存储每一帧的图像
        capture >> frameImg;
        //判断当前读取文件
        if (frameImg.empty())
            break;
        imshow("读取视频", frameImg);    //显示当前帧    
        //按下键盘上Q或q键退出
        if (char(waitKey(40)) == 'q' || char(waitKey(40)) == 'Q') //每帧画面存在40ms,即1秒25帧
            break;
        nCount++;
        flag = false;
    //视频释放
    capture.release();
#endif
    std::string path = "xxxpath";
    cv::VideoCapture * m_Cap = new cv::VideoCapture(path);
    if (m_Cap) {
        std::cout << "video: " << path << " is opened !" << std::endl;
    else {
        std::cout << "video: " << path << " opened failed !" << std::endl;
    if( !m_Cap->isOpened() )
        std::cout << "***Could not initialize capturing...***\n";
    cv::Mat frame;
    bool flag = true;
    while (m_Cap->read(frame) && flag) {
          //flag = false;
    m_Cap->release();
    return 0;

以上程序在ubuntu电脑上能够跑通,正常读取视频,但是在开发板上不能读取,isOpened()函数返回false

查看原因是由于电脑上的libopencv_videoio库编译时携带了ffmpeg,而板子上没有,具体查看下图

利用ffmpeg和opencv进行视频的解码播放
https://www.jianshu.com/p/6ef3c18d61b0

https://bbs.huaweicloud.com/forum/thread-99217-1-1.html