OpenCV中文网站

 找回密码
 立即注册
搜索
热搜: 安装 配置
查看: 5672|回复: 3

求一个运用c#和opencv写的把摄像头的图像实时显示在界面上

[复制链接]
发表于 2013-8-16 22:16:49 | 显示全部楼层 |阅读模式
usingusing System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Emgu.Util;
using Emgu.CV.Structure;
using Emgu.CV;
using System.Runtime.InteropServices;
using System.Drawing.Imaging;


namespace 摄像头
{
    public partial class Form1 : Form
    {
        Bitmap[] bitmap;
        string file;
        IntPtr vedio;
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            vedio = CvInvoke.cvCreateCameraCapture(0);
            if (timer1.Enabled == false)
            {
                this.button1.Text = "停止";
                this.timer1.Enabled = true;
            }
            else
            {
                this.button1.Text = "开始";
                this.timer1.Enabled = false;
            }
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            IntPtr frame = CvInvoke.cvQueryFrame(vedio);
            if (  frame!=IntPtr.Zero)
            {
                MIplImage iplImage = (MIplImage)Marshal.PtrToStructure(frame, typeof(MIplImage));
                Emgu.CV.Image<Bgr, byte> image = new Image<Bgr, byte>(iplImage.width, iplImage.height, iplImage.widthStep, iplImage.imageData);
                this.pictureBox1.Image = image.Bitmap;
            }
            else
            {
                this.button1.Text = &quot;开始&quot;;
                this.timer1.Enabled = false;
                pictureBox1.Image = bitmap[0];
            }
        }
    }
}
回复

使用道具 举报

发表于 2013-9-4 19:25:55 | 显示全部楼层
int _tmain(int argc, _TCHAR* argv[])
{cvNamedWindow("show-image",1);
CvCapture* ds=cvCreateCameraCapture(0);
        IplImage* frame;
        while(1){
        frame = cvQueryFrame(ds);
        if(!frame)break;
        cvShowImage("show-image",frame);
        char c=cvWaitKey(33);
        if(c==27)break;
        }
        cvReleaseCapture(&ds);
        cvDestroyWindow("show-image");
        return 0;
回复 支持 反对

使用道具 举报

发表于 2013-10-9 21:35:42 | 显示全部楼层
能不能请问一下VS2005,使用C#,怎么安装C#下的OpenCV啊,这个和C++的又有什么区别呢
回复 支持 反对

使用道具 举报

发表于 2013-11-22 03:45:00 | 显示全部楼层
这个不是更简单?

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using Emgu.CV;
using Emgu.CV.Structure;
using Emgu.Util;



namespace test
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }


        private Capture capture;

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                capture = new Capture();
            }
            catch (NullReferenceException excpt)
            {
                MessageBox.Show(excpt.Message);
            }

            Application.Idle += new EventHandler(processfram);
        }

        private void processfram(object sender, EventArgs arg)
        {
            Image<Bgr, Byte> frame = capture.QueryFrame();
            pictureBox1.Image =  frame.ToBitmap();

        }
    }
}
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|OpenCV中文网站

GMT+8, 2024-5-14 01:32 , Processed in 0.008980 second(s), 17 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表