SXH232摄像头使用示范

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.

时间: 2024-09-29 10:17:12

SXH232摄像头使用示范的相关文章

阵列式摄像头

转载自:http://www.igao7.com/news/201406/pelican.html 相信各位都看过诺基亚要与 Pelican 合作,联手研发 16 颗阵列式镜头的超强拍照手机的新闻了吧. 小编也对这个镜头很感兴趣,现在就由小编来介绍一下这颗摄像头的强大之处. Pelican Imaging 这间公司成立于 2008 年,总部设在加利福尼亚州的山景城,是移动设备上阵列式摄像头的发明者.目前投资者包括高通和诺基亚等. 这个镜头是由 4*4 个子镜头组成阵列式镜头,每个镜头会单独捕捉捕

飞凤平台示范项目

飞凤平台示范项目 能耗系统:管理整个楼层整体能耗的系统,比如用电量.用水量等等,并对此相关的数据进行显示和分析: 安防系统:智能楼宇体系里面的一个重点,包含入侵检测,火情检测,报警通知等等.用到的技术手段比较多,比如入侵检测,可以是红外检测,也可以是摄像头检测.通信方式也是有线,无线各种形式混合: 智能楼宇:其实安防,能耗也是智能楼宇的一部分,但是这两种方案相对独立,所以就剥离了出去.本方案基本也就是除了这二者之外的智能楼宇的方案的一些汇总: 智慧农业:物联网.移动互联网.云计算等信息技术与传统

如何暂停网络摄像头

如果谁会 GPUImage实现摄像头暂停 软件  请联系 我  18945818128  必有重谢

Halcon学习之二:摄像头获取图像和相关参数

1.close_all_framegrabbers ( : : : ) 关闭所有图像采集设备. 2.close_framegrabber ( : : AcqHandle : ) 关闭Handle为AcqHandle的图像采集设备. 3.open_framegrabber ( : : Name, HorizontalResolution, VerticalResolution, ImageWidth, ImageHeight, StartRow, StartColumn, Field, BitsP

你家的摄像头是如何被攻击的?

最近大量家用摄像头遭入侵,那么当摄像头已经不再安全的时候,我们该怎么办?你还敢用摄像头吗?今天小编带大家了解下你的摄像头是如何被黑掉的. 怎么找到那些摄像头的? 如果你是一个IT技术男,你一定知道Shodan,一个最可怕的搜索引擎,与谷歌不同的是,它不是在网上搜索网址,而是直接进入互联网的背后通道. Shodan可以说是一款"黑暗"谷歌,一刻不停的在寻找着所有和互联网关联的服务器.摄像头.打印机.路由器等.每个月Shodan都会在大约5亿个服务器上日夜不停地搜集信息,能找到几乎所有和互

最简单的基于FFmpeg的AVDevice例子(读取摄像头)【转】

转自:http://blog.csdn.net/leixiaohua1020/article/details/39702113 版权声明:本文为博主原创文章,未经博主允许不得转载. 目录(?)[-] libavdevice使用 注意事项 代码 结果 下载 =====================================================最简单的基于FFmpeg的AVDevice例子文章列表: 最简单的基于FFmpeg的AVDevice例子(读取摄像头) 最简单的基于FFm

新版FPC摄像头测评 OV7725 OV7670 OV9650 OV9655 OV5640 OV5642 OV2640 OV3640 MT9D112

最新制样新版FPC摄像头板卡,先看看结构尺寸 再瞧瞧接口(支持市面最通用的接口:2.54mm间距排针,支持5v或3.3v供电) 支持的柴草旗下将近十余款fpc标准摄像头(如OV7725 OV7670 OV9650 OV9655 OV5640 OV5642 OV2640 OV3640 MT9D112 ),涵盖30w至500w像素 支持raw.yuv.rgb格式输出. 再看看板卡资源实物(丰富的电源系统:3.3v.2.8v.1.8v.电源完整性设计和布线,高速传输下使得摄像头图像噪声降低到了极限)

Android自定义照相机 预览拍照 切换前后置摄像头

Android提供了Camera来控制拍照,步骤如下:(1)调用Camera的open()方法打开相机.(2)调用Camera的getParameters()获取拍照参数,该方法返回一个Cmera.Parameters对象.(3)调用Camera.Parameters对象对照相的参数进行设置.(4)调用Camera的setParameters(),并将Camera.Parameters对象作为参数传入,这样就可以对拍照进行参数控制,Android2.3.3以后不用设置.(5)调用Camerade

android环境下摄像头数据采集及显示

以前项目涉及些摄像头预览及数据处理操作,当时的需求是除了做摄像头预览外,还要显示文字.个性图像等,当初在查找资料实现相关模块时,发现很多资料讲的比较繁琐,不够简洁,这里将自己的实现方式分享出来,希望能够为正在做相关工作的同学提供些思路.不过这里先顺便提一下,如果单纯的做摄像头预览,不在预览数据时做添加文字.图像等额外操作,可以用surfaceview方式,性能上会更好些. 这里将摄像头采集及视频图像绘制放在一个模块中,比较便于管理及维护,同时在使用时,因为该类继承自view类,所以可以向操作很多