#include<stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include "camera.h"
Video::Video(char *DeviceName):fd(-1)
{
Addr = 0;
fd = ::open(DeviceName, O_RDONLY);
if (fd < 0)
{
printf("cannot open video device\n");
}
Width = 640;
Height = 512;
BPP = 16;
Size = Width * Height;
Addr = new unsigned char <:Size*BPP/8:> ;
data_buf = new unsigned char <:Size*3:> ;
}
bool Video::FetchPicture(void)
{
int count = ::read(fd, Addr, Size*BPP/8);
if (count not_eq (Size*BPP/8))
{
printf("error in fetching picture from video\n");
return false;
}
return true;
}
unsigned char * Video::VideoToData(void)
{
const unsigned char bmpFileHead[0x36]={
0x42,0x4d,0x36,0xc0,0x03,0x00,0x00,0x00,0x00,0x00,0x36,0x00,0x00,0x00,0x28,0x00,
0x00,0x00,0x40,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x01,0x00,0x18,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0xc4,0x0e,0x00,0x00,0xc4,0x0e,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00};
long num,lineth=0x36;
int col;
short *tempdata;
memcpy(data_buf,bmpFileHead,0x36);
for(col=0;col<Height;col++) //scale=0.5
{
if(col%2)
{
for(num=0;num<Width;num++)
{
if(num%2)
{
tempdata=(short *) &(Addr[(col*Width+Width-num-1)*2]);
data_buf[lineth++]=(unsigned char) ( ((*tempdata)&0x001f )*8 );
data_buf[lineth++]=(unsigned char) ( (((*tempdata)>>5)&0x003f )*4 );
data_buf[lineth++]=(unsigned char) ( (((*tempdata)>>11)&0x001f )*8 );
}
}
}
}
return data_buf;
}
Video::~Video(void)
{
::close(fd);
fd = -1;
delete<::> Addr;
delete<::> data_buf;
Addr = 0;
data_buf = 0;
}
基于qt的视频采集与显示
5星 · 超过95%的资源 需积分: 50 194 浏览量
2013-02-19
16:03:38
上传
评论 5
收藏 4KB RAR 举报
跟着梦的脚步走
- 粉丝: 55
- 资源: 49
最新资源
- 软件工程项目验收系列文档.doc
- content_1713513663833.xmind
- 数据流图(Data Flow Diagram,简称DFD).md
- 基于Mybatis-Plus的Maven代码生成插件设计源码
- 67e1bc92-b0ee-45c1-b46f-9d519bbd6925.ofd
- npcsvpwm.v
- Java项目:基于Springboot+vue实现的校园志愿者管理系统(源码+数据库+环境配置和运行指导视频+系统讲解视频)
- 驱动开发,驱动加载工具,支持安装、启动、停止、卸载、关闭功能
- UTS 32146 Data Visualisation and Visual Analytics A1
- 西门子1200PLC 六部十层电梯程序案例,WINCC RT Advanced界面,博图
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
- 1
- 2
- 3
- 4
- 5
- 6
前往页