[问题] 两支CCD摄影机 同时显示不同画面

楼主: Timid (吞豚)   2016-09-06 15:02:58
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
Graphics objGraphic = e.Graphics;
Pen pen = new Pen(Color.Blue);
objGraphic.DrawLine(pen, (pictureBox1.Width) / 2, 0,
(pictureBox1.Width) / 2, pictureBox1.Height);
objGraphic.DrawLine(pen, 0, (pictureBox1.Height) / 2,
pictureBox1.Width, (pictureBox1.Height) / 2);
}
private void pictureBox2_Paint(object sender, PaintEventArgs e)//20160523新增
{
Graphics objGraphic = e.Graphics;
Pen pen = new Pen(Color.Red);
objGraphic.DrawLine(pen, (pictureBox2.Width) / 2, 0,
(pictureBox2.Width) / 2, pictureBox2.Height);
objGraphic.DrawLine(pen, 0, (pictureBox2.Height) / 2,
pictureBox2.Width, (pictureBox2.Height) / 2);
}
private void UpdateDeviceList()
{
//清除设备列表
DeviceListView.Items.Clear();
//要求设备enumerator的设备列表
List<DeviceEnumerator.Device> list =
DeviceEnumerator.EnumerateDevices();
//每个设备添加在列表中
foreach (DeviceEnumerator.Device device in list)
{
ListViewItem item = new ListViewItem(device.Name);
item.Tag = device; //连结该设备的数据
DeviceListView.Items.Add(item);
}
}
private void CaptureCamera()//启动相机的执行续
{
_cameraThread =new Thread(new ThreadStart(CaptureCameraCallback));
_cameraThread.Start();
}
private void CaptureCameraCallback()
{
ListViewItem item = DeviceListView.Items[0];
//获取连结设备的数据
DeviceEnumerator.Device device =(DeviceEnumerator.Device)item.Tag;
CvCapture cap0 = CvCapture.FromCamera((int)(device.Index));//PO0
IplImage tpl = Cv.LoadImage("CaptureL.bmp", LoadMode.Color);//读样
版图档案
Thread.Sleep(1000);
item = DeviceListView.Items[0];
//获取连结设备的数据
device = (DeviceEnumerator.Device)item.Tag;
CvCapture cap1 = CvCapture.FromCamera((int)(device.Index));//PO1
IplImage tpr = Cv.LoadImage("CaptureR.bmp", LoadMode.Color);//读样
版图档案
Thread.Sleep(1000);
CvPoint minloc, maxloc;
double minval, maxval;
myUI("", minloc_X);//minloc_X写为空白
while (true)
{
IplImage img0 = cap1.QueryFrame();
IplImage res0 = Cv.CreateImage(Cv.Size(img0.Width-tpr.Width+1,
img0.Height-tpr.Height+1),BitDepth.F32,1);
Cv.MatchTemplate(img0, tpr, res0,MatchTemplateMethod.SqDiffNormed);
Cv.MinMaxLoc(res0, out minval, out maxval, out minloc, out maxloc, null);
Bitmap bm0 = BitmapConverter.ToBitmap(img0);//将img转成BMP档
bm0.SetResolution(pictureBox2.Width,pictureBox2.Height);//设定BMP档的分辨率
pictureBox2.Image = bm0;
IplImage img1 = cap0.QueryFrame();
IplImage res1 = Cv.CreateImage(Cv.Size(img1.Width - tpl.Width + 1,
img1.Height - tpl.Height + 1), BitDepth.F32, 1);
Cv.MatchTemplate(img1, tpl, res1, MatchTemplateMethod.SqDiffNormed);
Cv.MinMaxLoc(res1, out minval, out maxval, out minloc, out maxloc, null);
Bitmap bm1 = BitmapConverter.ToBitmap(img1);//将img转成BMP档
bm1.SetResolution(pictureBox1.Width, pictureBox1.Height);
pictureBox1.Image = bm1;
}
}
private void video_start_Click(object sender, EventArgs e)
{
//CaptureCamera2();
CaptureCamera();
flog = 1;
}
不管怎么改都是两个picture box显示同一支摄影机的画面
已尝试过许多方法 也用测试程式试过两支摄影机都正常
但是使用opencv capture都只截取到同一只的画面
不知道是哪里出了问题 想请教板上高手能否帮忙开释一下
作者: starlion (不是0就是1)   2016-09-06 20:13:00
第二个device应该从Item[1]取得
楼主: Timid (吞豚)   2016-09-08 14:21:00
感谢 已修正,不过还是无法
作者: KLoVeRs (ちぐさ あすは)   2016-09-08 15:49:00
需要吴德清主任的帮助吗?
作者: dsin (dior)   2016-09-15 08:25:00
你该不会只是把Item[0]改成Item[1]这样做吧?

Links booklink

Contact Us: admin [ a t ] ucptt.com