使用opencv和c ++动态地从多个网络摄像头直播视频 [英] Live video feed from multiple webcam dynamically using opencv and c++

查看:294
本文介绍了使用opencv和c ++动态地从多个网络摄像头直播视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经实现了显示四个opencv窗口的代码,以便从4个网络摄像头获取实时视频。但代码不是动态的。我想让它变得动态,它只显示与连接到System的摄像机数量相等的窗口。我得到了连接到机器的相机数量。唯一的任务仍然是实现动态场景的代码。

这是代码。



I have implemented the code that displays four windows of opencv to get live video feed from 4 webcams. But the code is not dynamic. I want to make it dynamic where it will display only windows equal to the number of cameras attached to System. I am getting the number of camera attached to the machine. The only task remains is to implement the code for dynamic scenario.
Here's the code.

#include<opencv\cv.h>
#include<opencv\highgui.h>
#include<d:\my>

using namespace cv;

int main(){

	//Create matrix to store image
	Mat image;
	Mat image1;
	Mat image2;
	Mat image3;

	//Mat image1;
	//initailize capture
	videoInput VI;
	int numDevices = VI.listDevices();	
 	VideoCapture cap;
	VideoCapture cap1;
	VideoCapture cap2;
	VideoCapture cap3;

	bool x = false;
	//VideoCapture cap1;
	cap.open(0);
	cap1.open(1);
	cap2.open(2);
	cap3.open(3);
	
	namedWindow("Camera 1",1);
	namedWindow("Camera 2",1);
	namedWindow("Camera 3",1);
	namedWindow("Camera 4",1);

	while(1){
		//copy webcam stream to image
		cap >> image;
		cap1 >> image1;
		cap2 >> image2;
		cap3 >> image3;
		cap4 >> image4;
		//cap1 >> image1;
		imshow("Camera 1",image);
		imshow("Camera 2",image1);
		imshow("Camera 3",image2);
		imshow("Camera 4",image3);

		//imshow("Camera 2",image1);
		//delay 33ms
		waitKey(33);
	}
}



请指出制作动态代码的正确方向。后来我想在mfc中实现代码。


Please point me to right direction for the making the dynamic code. Later i want to implement the code in mfc.

推荐答案

可能有相机API提供的相机列表 - 这是第一个看的地方,相机厂商通常提供示例代码。并且可能链接到结构列表,其中每个结构包含关于一个相机的信息。我会寻找这些。

当使用相机(在火线总线上)时,我需要能够检测到新添加的相机,并推断有人在那里添加(或移除相机),因此可以按下按钮'刷新相机列表'相当于要求某个低级别检测发出的事件。虽然可能是你的API再次提供了这样的事件,但请查看。

稍后您可能会发现编写C ++类来处理此类添加和删除很有用。我已经添加了我写的这个类的标题及其描述,以显示它的外观。



There's likely to be a list of cameras provided, perhaps by the camera API - that's the first place to look, camera manufacturers usually provided example code. And perhaps linking to a list of structures, where each structure contains information about one camera. I'd look for these.
When using cameras (on a firewire bus) I needed be able to detect newly a added camera and reasoned that a person is there to add (or remove that camera) and so can press a button 'refresh camera list' rather demand an event fired by some low-level detection. Though it may be your API provides such an event so again, have a look for that.
You might later find it useful to write a C++ class to handle such additions and removals. I've added the header from such a class I wrote, and its description, to show how this might look.

#include "CameraList.h" // The list of [camera] nodes on the bus that are managed.

/* The number of cameras on the firewire bus can change, that is a camera could be manually connected or disconnected or a connected camera could fail therefore we need to have our list of cameras updated, both on an event driven basis and at our request. A Bus Manager has been introduced to take care of this. Event driven changes are not really a problem, but at times the firewire bus has been initialised and generated events before the list of information on the ameras is actually required. So being able to ask the Bus Manager to regenerate the list upon demand, simply by calling the event handler OnNodeListChanged is extremely useful.
CBusManager also wraps the code for adding and removing nodes from the list of Cameras, making use of the bus simpler and cleaner. */

class CBusManager
{
public:
    CBusManager(CCameraList* pCameraList);
    void OnNodelistChanged();
    void EnableNode(UINT32 Ix,BOOL Enable);
    void RemoveNode(UINT32 Ix);
    void AddNode(FGNODEINFO *pInfo);

    CCameraList* m_pCameraList;
};


这篇关于使用opencv和c ++动态地从多个网络摄像头直播视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆