SXH232摄像头使用示范
来源:互联网 发布:淘宝到付怎么弄 编辑:程序博客网 时间:2024/06/08 09:49
It occurred to me suddenly that I wanted to program the our camera sensor for PC desktop, just like the one purchased from shop, which can make the video recording. Finally although the result seemed not to be as good as expected, it improved me.
Here I used the SXH232-V1 camera. Judging from literal meaning, it has RS232 port obviously.So first connect the camera to PC with 232 port correctly. Then create a winform VS project, and create a form like this:
Here's what I intend to do. when I click "start taking photo" button, the picture taken by camera is showed in the picturebox in no time.If the speed is fast enough, then we'll see a video made up of several frames of pictures. However to my pity, I haven't done it completely, which means it has a few seconds of delay.
OK, then let's see the main code:
private SXH sxh = new SXH();private Queue<Image> queue = new Queue<Image>();private Image img = null;Thread pic, pbx;public Form1(){InitializeComponent();this.comboBox1.Text = "COM1";this.comboBox2.Text = "115200";this.comboBox3.Text = "640x480";this.comboBox4.Text = "2";sxh.InitSXH(this.comboBox1.Text, Convert.ToInt32(this.comboBox2.Text),this.comboBox3.Text,Convert.ToInt32(this.comboBox4.Text));}
first create some private members and initiate the form and camera
private void button1_Click(object sender, EventArgs e){pic = new Thread(new ThreadStart(TakePic));pic.Start();pbx = new Thread(new ThreadStart(ShowPic));pbx.Start();this.comboBox1.Enabled = false;this.comboBox2.Enabled = false;this.comboBox3.Enabled = false;this.comboBox4.Enabled = false;this.button1.Enabled = false;}
when I start taking, the message handling function creates two threads. One is responsible for taking picture, another for showing it.
public void TakePic(){byte[] data = null;while (true){sxh.GetData(0x01, out data);//获得图片字节if (data != null){MemoryStream ms = new MemoryStream(data);img = System.Drawing.Image.FromStream(ms); }if (img != null){img.RotateFlip(RotateFlipType.Rotate180FlipX);//若摄像头安反了,就反转一下queue.Enqueue(img);}}}public void ShowPic(){while (true){if (queue.Count > 0){Image img = queue.Dequeue();this.pictureBox1.Size = img.Size;this.pictureBox1.Image = img;//Thread.Sleep(200);}}}the above are two threads. One puts the image into queue, anther gets image from the queue.
Of course, there is an important problem here. How do we get the data from camera? Well, we should write the camera driver according to camera document. As for the code, you can refer to the doc here, or you can contact me.
Finally build the execute the program. let's watch a snapshot from camera:
It has to be acknowledged that this program has imperfections. Sometimes after a little long time running, it will raise a kind of exception. Apparently there are errors in my code. Furthermore, I'm looking forward to seeing the real-time video instead of the delayed pictures, but actually I've no idea whether it can be achieved. I had thought that I could handle it with threads programming. Anyway something's wrong with my design.
- SXH232摄像头使用示范
- jquery validate 使用示范
- JFreeChart使用示范
- 实例示范脱壳常用工具使用
- 多渠道打包 mac使用示范
- Flink DataSet API 使用示范
- 摄像头使用
- 实例示范如何使用 Android Services
- SQL SERVER 2008 游标使用示范
- Ventuz基础系列之插件使用示范
- google guava使用例子/示范(一)
- jquery validate 使用示范
- google guava使用例子/示范(一)
- ios Pod安装使用 + Podfile 文件格式示范
- fortran F90动态数组的基本使用示范
- 创意示范:苹果如何使用无线充电技术
- 虚拟化平台 KVM API的ioctl使用示范(一)
- Linux下nginx的安装及点直播使用示范
- btn = (Button)sender
- Html标签 textarea 的属性及用法
- understanding linux usb ehci device driver
- js中按字节截取字符串
- 5个海盗,分100个金币
- SXH232摄像头使用示范
- OSI七层模型
- zoj3529 A Game Between Alice and Bob 博弈
- JS 字符串操作
- 什么是Visual C++以及C++新特性
- AudioRecord录音初始化异常
- hashmap详解(带hashmap源码分析)
- 为什么说数据库版本控制是必须的
- xcode自定义配色方案以及配色方案的移植