因为不能同时打开两个摄像头,所以想轮流打开采集,但是编程功底不够,主要程序部分如下,单独都能实现。
MyHelloForm::MyHelloForm( QWidget* parent, const char* name, WFlags fl)
:HelloBaseForm(parent, name, fl)
{
connect (this, SIGNAL(close_signal()), this, SLOT(camara_quit()));
connect (this, SIGNAL(quit_signal()), qApp, SLOT(quit()));
connect (CloseButton, SIGNAL(clicked()), this, SLOT(camara_quit()));
connect (SnapButton, SIGNAL(clicked()), this, SLOT(camara_snap()));
//这里是初始化第一个摄像头
if (v4l2_init("/dev/video2"))
{
printf("video2 init is error!\n");
emit(close_signal());
}
timer = new QTimer(this);
connect (timer, SIGNAL(timeout()), this, SLOT(showMe1()));
timer->start(FRAME_IDLE);
//如果注释掉下面内容就可以显示一边了,但我还想显示另一个摄像头。
//这一段是清除映射关系等
munmap(buffers[0].start, FRAME_COUNT*buffers[0].length);
::close(fd);
timer->stop();
//这一段是打开第二个摄像头
if (v4l2_init2("/dev/video3"))
{
printf("video3 init is error!\n");
emit(close_signal());
}
timer = new QTimer(this);
connect (timer, SIGNAL(timeout()), this, SLOT(showMe2()));
timer->start(FRAME_IDLE);
//程序到这里结束可以显示第二个摄像头,但是不能显示第一个
//我大概设计了一个UI左右两边可以实时显示采集的图像就是showMe1和showMe2。
//怎么让他们轮流采集呢,一直不成功,求各位大大帮忙。
}