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.
SXH232摄像头使用示范的更多相关文章
- Android开发之控制摄像头拍照
如今的手机一般都会提供相机功能,有些相机的镜头甚至支持1300万以上像素,有些甚至支持独立对焦.光学变焦这些仅仅有单反才有的功能,甚至有些手机直接宣传能够拍到星星.能够说手机已经变成了专业数码相机.为 ...
- 在DevExpress中使用CameraControl控件进行摄像头图像采集
在我们以前的项目了,做摄像头的图片采集,我们一般还是需要做一个封装处理的,在较新版本的DevExpress控件里面,增加了一个CameraControl控件,可以直接调用摄像头显示的,因此也可以做头像 ...
- ubuntu-Linux系统读取USB摄像头数据(gspca)
将摄像头图像保存为jpg格式.摄像头需要是gspca免驱的.uvc若用uvc格式的需要在图像中插入Huffman表.否则无法正常显示. 程序代码: #include <stdio.h> # ...
- ubuntu-Linux系统读取USB摄像头数据(uvc)
这几天在做小车的过程中,需要用到图像采集.我想现在用的摄像头是UVC免驱的.根据国嵌的教程中有一个gspca摄像头的程序.我发现把gspca的采集程序用到uvc上时,在显示图像的时候提示没有huffm ...
- C# 使用AForge调用笔记本摄像头拍照
vs2012 winform 连接摄像头设备,这里需要引入 代码: using AForge; using AForge.Controls; using AForge.Imaging; using ...
- Opencv摄像头实时人脸识别
Introduction 网上存在很多人脸识别的文章,这篇文章是我的一个作业,重在通过摄像头实时采集人脸信息,进行人脸检测和人脸识别,并将识别结果显示在左上角. 利用 OpenCV 实现一个实时的人脸 ...
- Opencv VideoCapture实时捕捉摄像头信息
#include "opencv2/highgui/highgui.hpp" #include <iostream> using namespace cv; using ...
- Unity打开摄像头占满全屏
Unity打开摄像头占满全屏 AR项目需求,Unity打开摄像头作为背景渲染占满全屏~ Unity对设备硬件操作的API并不是太友好~打开一个摄像头,渲染到屏幕上也都得自己写,虽然步骤少,提取摄像头t ...
- Vuforia unity开发摄像头问题
Vuforia unity开发摄像头问题 项目一直在赶进度,写博的时间越来越少了~从事Unity开发也快两个月了,AR方向~ 使用的是高通家的SDK Vuforia...从工程融合一直到对unity和 ...
随机推荐
- Ionic Js七:手势事件
1.on-hold 长按的时间是500毫秒. HTML 代码 <button on-hold="onHold()" class="button">长 ...
- HDU - 2199 Can you solve this equation? 二分 简单题
Can you solve this equation? Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ( ...
- Android与GPL、BSD和Apache之间的关系
参考资料 Android ,在争议中逃离 Linux 内核的 GPL 约束 | 爱范儿 简介 众所周知,Linux内核基于GPL v2发行.GPL规定,基于GPL的软件产品的衍生产品,也必须使用GPL ...
- 不可不说的Java“锁”事
前言 Java提供了种类丰富的锁,每种锁因其特性的不同,在适当的场景下能够展现出非常高的效率.本文旨在对锁相关源码(本文中的源码来自JDK 8).使用场景进行举例,为读者介绍主流锁的知识点,以及不同的 ...
- 机器学习之路: python 实践 word2vec 词向量技术
git: https://github.com/linyi0604/MachineLearning 词向量技术 Word2Vec 每个连续词汇片段都会对后面有一定制约 称为上下文context 找到句 ...
- C# String.Format 格式化字符串 数字/时间
首先献给只想知道结果的人 格式化 DateTime 对象 标准 数字 格式化 Int Decimal Float Double 关于这一块一直不是很清楚,MSDN 上也不够清晰. 就花了点时间敲了一下 ...
- BZOJ 1951SDOI2010 古代猪文
真是到很强的数学题 先利用欧拉定理A^B %p=A^(B%φ(p)+φ(p) ) %p 然后利用卢卡斯定理求出在modφ(p)的几个约数下的解 再利用中国剩余定理合并 计算答案即可 By:大奕哥 #i ...
- CF1060E Sergey and Subway 思维
分两种情况讨论 一种为奇数长为$L$的路径,在经过变化后,我们需要走$\frac{L}{2} + 1$步 一种为偶数长为$L$的路径,在变化后,我们需要走$\frac{L}{2}$步 那么,我们只需要 ...
- BlocksKit(1)-基本类型的分类
BlocksKit(1)-基本类型的分类 BlocksKit是一个用block的方式来解决我们日常用对集合对象遍历.对象快速生成使用.block作为委托对象的一种综合便利封装库.这个库主要分三个大块C ...
- [HDU6155]Subsequence Count
题目大意: 给定一个01序列,支持以下两种操作: 1.区间反转: 2.区间求不同的子序列数量. 思路: 首先我们考虑区间反转,这是一个经典的线段树操作. 接下来考虑求不同的子序列数量,在已知当前区间的 ...