小编Rog*_*ier的帖子

使用v4l2捕获相机图像非常慢

我一直在努力使用v4l2直接在OpenCV中抓取相机图像.这工作得非常好; 通过这种方式,我可以以YUYV格式和高分辨率获取图像(了解帧速率将下降).我无法通过OpenCV实现完成这项工作.功能上它的工作效果很好,但性能可能会好得多.由于这是我第一次直接使用v4l2,它对我来说仍然有点模糊.我已经对所有相关部分进行了计时,并发现v4l2选择方法需要花费一秒多的时间.当我降低时间间隔时,select方法花费的时间更少,但是出列的时间要长得多(也就是第二次).在其他功能中,相机被初始化,因此设置正确的格式等.我知道帧速率很低,没有压缩和高分辨率,但这是极低的.

下面是捕获图像功能.我跳过了缓冲区转换为Mat(YUYV - > RGB)的代码,因为我认为它现在不相关.

有谁知道如何使v4l2捕获图像更快?也许有些部分我不应该执行每个帧抓取?

谢谢!

Mat Camera::capture_image() {
Mat returnframe(10, 10, CV_8UC3);
struct v4l2_buffer buf = {0};
buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
buf.memory = V4L2_MEMORY_MMAP;
buf.index = 0;
if (-1 == xioctl(fd, VIDIOC_QBUF, &buf)) {
    perror("Query Buffer");
    return returnframe;
}

if (-1 == xioctl(fd, VIDIOC_STREAMON, &buf.type)) {
    perror("Start Capture");
    return returnframe;
}

fd_set fds;
FD_ZERO(&fds);
FD_SET(fd, &fds);
struct timeval tv = {0};
tv.tv_sec = 2;
int r = select(fd + 1, &fds, NULL, NULL, &tv);
if (-1 == r) …
Run Code Online (Sandbox Code Playgroud)

c++ camera opencv v4l2

5
推荐指数
1
解决办法
3405
查看次数

在向量中找到struct

我想在向量中找到一个结构,但是我遇到了一些麻烦.我读了几篇关于这个的帖子,但是这些都搜索了struct的一个元素:我希望能够在搜索时比较struct的多个元素.我的结构和向量定义为:

struct subscription {
    int tournamentid;
    int sessionid;
    int matchid;

    bool operator==(const subscription& m) const {
        return ((m.matchid == matchid)&&(m.sessionid==sessionid)&&(m.tournamentid==tournamentid));
    }
};

vector<subscription> subscriptions;
Run Code Online (Sandbox Code Playgroud)

然后我想在向量订阅中搜索结构,但由于sessionid和matchid的组合是唯一的,我需要搜索两者.仅搜索一个将导致多个结果.

    subscription match;
    match.tournamentid = 54253876;
    match.sessionid = 56066789;
    match.matchid = 1108;
    subscriptions.push_back(match);

    it = find(subscriptions.begin(), subscriptions.end(), match);
Run Code Online (Sandbox Code Playgroud)

find函数在编译期间给出以下错误:

main.cpp:245:68:错误:'it = std :: find [with _IIter = __gnu_cxx :: __ normal_iterator>,_Tp = echo_client_handler :: subscription]((echo_client_handler*)this)中的'operator ='不匹配 - > echo_client_handler :: subscriptions.std :: vector <_Tp,_Alloc> ::以_Tp = echo_client_handler :: subscription开头,_Alloc = std :: allocator,std :: vector <_Tp,_Alloc> …

c++ struct vector

3
推荐指数
1
解决办法
5622
查看次数

标签 统计

c++ ×2

camera ×1

opencv ×1

struct ×1

v4l2 ×1

vector ×1