【问题标题】:Read video frame with OpenCV to specified pointer (C++)使用 OpenCV 将视频帧读取到指定的指针(C++)
【发布时间】:2018-05-08 22:35:46
【问题描述】:

有没有办法通过 videocapture 读取视频帧并指定它应该在内存中的位置?假设我有一个指针 char *p 并且已经为帧预分配了正确的内存量,我可以在帧中读取 p 的地址吗?

【问题讨论】:

    标签: c++ opencv pointers memory-management video-capture


    【解决方案1】:

    cv::Mat 旨在自动处理图像的内存管理,但它也可以与外部分配的缓冲区一起使用。为此,请将指向外部缓冲区的指针传递给Mat constructor

    确保缓冲区大小、Mat 大小和类型(通道、深度等)与 VideoCapture 的输出相匹配。

    例子:

    unsigned char *data; // Points to buffer of appropriate size.
    cv::VideoCapture cap; // A valid capture
    
    // This only allocates the Mat header with a reference to "data"
    cv::Mat frame {
        rows,
        cols,
        CV_8UC3, // image type, here 3-channel, 8 bits per channel, unsigned
        data
    };
    cap >> frame;  // Image data stored into buffer at "data"
    

    【讨论】:

    • 更改:{} => ()
    猜你喜欢
    • 1970-01-01
    • 2013-11-08
    • 1970-01-01
    • 1970-01-01
    • 2018-01-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多