相机同步 OpenCV

发布于 2024-11-02 17:01:57 字数 182 浏览 2 评论 0原文

我有立体摄像系统。 在我的程序中,我通过两个线程捕获每个摄像机的图像。 (每个相机一个线程)。 当我收到来自每个相机的图像后,我想用 OpenCV 处理它们。我如何对我的程序说,两个相机线程都获得了图像,我可以去处理它们?

我还有一个问题。从相机接收到的每个帧都有一个由相机指定的时间戳。如何匹配时间戳,以便从两个摄像机同时拍摄图像?

I have stereo cameras systems.
In my program I catch the images from each camera in two threads. (one thread per camera).
After I receive the images from each camera, I want to process them with OpenCV. How I can say to my program, that the both camera threads got images and I can go to process them?

I have another question. Every received frame from the camera has a timestamp, which is specified by camera. How I can match the timestamp, so that I get images from two cameras, which were caught at the same time?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

貪欢 2024-11-09 17:01:57

您是否曾经使用 OpenCV 编写过应用程序来显示相机捕获的帧?从那里开始。下面的应用程序执行此操作,并将每个帧转换为其灰度版本:

CvCapture *capture = NULL;
capture = cvCaptureFromCAM(-1); //-1 or 0 depending on your platform
if (!capture)
{
    printf("!!! ERROR: cvCaptureFromCAM\n");
    return -1;
}

cvNamedWindow("video", CV_WINDOW_AUTOSIZE);

while (exit_key_press != 'q')
{
    /* Capture a frame */
    color_frame = cvQueryFrame(capture);
    if (color_frame == NULL)
    {
        printf("!!! ERROR: cvQueryFrame\n");
        break;
    }
    else
    {
        // WOW! We got a frame! 
        // This is the time to process it since we are not buffering 
        // the frames to use them later. It's now or never.

        IplImage* gray_frame = cvCreateImage(cvSize(color_frame->width, color_frame->height), color_frame->depth, 1);  
        if (gray_frame == NULL)
        {
            printf("!!! ERROR: cvCreateImage\n");
            continue;
        }

        cvCvtColor(color_frame, gray_frame, CV_BGR2GRAY);
        cvShowImage("Grayscale video", gray_frame);
        cvReleaseImage(&gray_frame);
    }
        exit_key_press = cvWaitKey(1);
}

请记住,这些帧是在循环内检索的,如果退出循环,您将停止从相机接收数据。这是有道理的,对吧?这给您留下了 2 个选择:

  • 以正确的方式处理帧。但如果此处理速度很慢,您可能会错过相机中的一些帧,直到下一个 cvQueryFrame() 操作。

  • 使用某种缓冲区机制存储帧,以便您可以在另一个线程上进行处理。如果您的处理技术对 CPU 要求很高并且您不想丢失任何帧,那么这是一个很好的方法。

关于你的第二个问题,我不清楚你的意思。请进一步详细说明。

Have you ever wrote an application using OpenCV to display the frames captured by the camera? Start from there. The application below does that and convert each frame to it's grayscale version:

CvCapture *capture = NULL;
capture = cvCaptureFromCAM(-1); //-1 or 0 depending on your platform
if (!capture)
{
    printf("!!! ERROR: cvCaptureFromCAM\n");
    return -1;
}

cvNamedWindow("video", CV_WINDOW_AUTOSIZE);

while (exit_key_press != 'q')
{
    /* Capture a frame */
    color_frame = cvQueryFrame(capture);
    if (color_frame == NULL)
    {
        printf("!!! ERROR: cvQueryFrame\n");
        break;
    }
    else
    {
        // WOW! We got a frame! 
        // This is the time to process it since we are not buffering 
        // the frames to use them later. It's now or never.

        IplImage* gray_frame = cvCreateImage(cvSize(color_frame->width, color_frame->height), color_frame->depth, 1);  
        if (gray_frame == NULL)
        {
            printf("!!! ERROR: cvCreateImage\n");
            continue;
        }

        cvCvtColor(color_frame, gray_frame, CV_BGR2GRAY);
        cvShowImage("Grayscale video", gray_frame);
        cvReleaseImage(&gray_frame);
    }
        exit_key_press = cvWaitKey(1);
}

Keep in mind that the frames are being retrieved inside a loop, and if you quit the loop you'll stop receiving data from the camera. It makes sense, right? This leaves you with 2 options:

  • Process the frame right way. But if this processing is slow, you'll probably miss a few frames from the camera until the next cvQueryFrame() operation.

  • Store the frame using some buffer mechanism so you can do the processing on another thread. This is a good approach if your processing technique is demanding on the CPU and if you don't want to loose any frames.

About your second question, its not clear to me what you mean. Please elaborate further.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文