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摄像头使用示范的更多相关文章

  1. Android开发之控制摄像头拍照

    如今的手机一般都会提供相机功能,有些相机的镜头甚至支持1300万以上像素,有些甚至支持独立对焦.光学变焦这些仅仅有单反才有的功能,甚至有些手机直接宣传能够拍到星星.能够说手机已经变成了专业数码相机.为 ...

  2. 在DevExpress中使用CameraControl控件进行摄像头图像采集

    在我们以前的项目了,做摄像头的图片采集,我们一般还是需要做一个封装处理的,在较新版本的DevExpress控件里面,增加了一个CameraControl控件,可以直接调用摄像头显示的,因此也可以做头像 ...

  3. ubuntu-Linux系统读取USB摄像头数据(gspca)

    将摄像头图像保存为jpg格式.摄像头需要是gspca免驱的.uvc若用uvc格式的需要在图像中插入Huffman表.否则无法正常显示. 程序代码: #include <stdio.h> # ...

  4. ubuntu-Linux系统读取USB摄像头数据(uvc)

    这几天在做小车的过程中,需要用到图像采集.我想现在用的摄像头是UVC免驱的.根据国嵌的教程中有一个gspca摄像头的程序.我发现把gspca的采集程序用到uvc上时,在显示图像的时候提示没有huffm ...

  5. C# 使用AForge调用笔记本摄像头拍照

    vs2012  winform 连接摄像头设备,这里需要引入 代码: using AForge; using AForge.Controls; using AForge.Imaging; using ...

  6. Opencv摄像头实时人脸识别

    Introduction 网上存在很多人脸识别的文章,这篇文章是我的一个作业,重在通过摄像头实时采集人脸信息,进行人脸检测和人脸识别,并将识别结果显示在左上角. 利用 OpenCV 实现一个实时的人脸 ...

  7. Opencv VideoCapture实时捕捉摄像头信息

    #include "opencv2/highgui/highgui.hpp" #include <iostream> using namespace cv; using ...

  8. Unity打开摄像头占满全屏

    Unity打开摄像头占满全屏 AR项目需求,Unity打开摄像头作为背景渲染占满全屏~ Unity对设备硬件操作的API并不是太友好~打开一个摄像头,渲染到屏幕上也都得自己写,虽然步骤少,提取摄像头t ...

  9. Vuforia unity开发摄像头问题

    Vuforia unity开发摄像头问题 项目一直在赶进度,写博的时间越来越少了~从事Unity开发也快两个月了,AR方向~ 使用的是高通家的SDK Vuforia...从工程融合一直到对unity和 ...

随机推荐

  1. 8-10 Coping Books uva714

    题意:把一个包含m个正整数的序列划分为k个   1<=k<=m<=500的非空连续子序列  使得每个正整数恰好属于一个序列  设第i个序列的各个数之和为 Si   你的任务是让所有的 ...

  2. Ubuntu18.04 n卡配置

    一.背景 最近安装了ubutnu18.04后,安装系统后重启卡住,强制关机重启后,又在开机界面紫屏卡住,上网搜索后发现是n卡的驱动问题,使用以下方法安装驱动后成功解决该问题. 二.解决方法 1.进入恢 ...

  3. 洛谷P3265 [JLOI2015]装备购买 [线性基]

    题目传送门 装备购买 格式难调,题面就不放了. 分析: 一句话,有$n$件物品,每件物品有$m$个属性和一个花费值,如果一个装备的属性值可以由其他装备的属性值改变系数后组合得到那就不买,求购买最多装备 ...

  4. 个人博客www.0x002.com

    cnblogs只是相当于一个备份,感兴趣的读者赏脸关注下.

  5. python3.6 利用requests和正则表达式爬取猫眼电影TOP100

    import requests from requests.exceptions import RequestException from multiprocessing import Pool im ...

  6. 图形文件元数据管理工具exiv2

    图形文件元数据管理工具exiv2   图形文件通常都包含多种元数据,如Exif.IPTC.XMP.这些信息往往是渗透人员收集的目标.为了便于管理这些信息,Kali Linux内置了专用工具exiv2. ...

  7. iOS 9应用开发教程之编辑界面与编写代码

    iOS 9应用开发教程之编辑界面与编写代码 编辑界面 在1.2.2小节中提到过编辑界面(Interface builder),编辑界面是用来设计用户界面的,单击打开Main.storyboard文件就 ...

  8. Qt Quick快速入门之线程基础

    首先必须明确的是,Qt中的线程使用是相对复杂的,并不像C#中那么随意,特别是结合串口.网络编程等,使用时稍有不慎就会出问题,然后Qt里面经常出了问题就直接崩溃(这个真是谁用谁知道),所以如果在功能上用 ...

  9. [BZOJ1815&BZOJ1488]有色图/图的同构(Polya定理)

    由于有很多本质相同的重复置换,我们先枚举各种长度的点循环分别有多少个,这个暴搜的复杂度不大,n=53时也只有3e5左右.对于每种搜索方案可以轻易求出它所代表的置换具体有多少个. 但我们搜索的是点置换组 ...

  10. 【20181030T2】字胡串【分治+双指针】

    题面 [正解] 一眼分治 哎\(O(N^2)\)有50分,先敲了 等下,由于最大的数或进去了,所以有\(g(T) \geq f(T)\) 也就是说,我们用\(n \times (n-1) /2\)算出 ...