基于ARM的图像采集和数据传输系统

今天完成了前两个模块的整合调试,基本实现了功能!

把代码贴出来!

下一步考虑压缩为jpeg视频数据流,不保存文件直接传输。

视频采集头文件:

#ifndef _CAPTURE_H_
#define _CAPTURE_H_


#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

#include <linux/videodev.h>
#include <sys/ioctl.h>

#include <fcntl.h>
#include <linux/fb.h>
#include <sys/mman.h>

#include <linux/types.h>
#include <jpeglib.h>
#include <setjmp.h>


#define bool int
#define true 1
#define false 0
//#include <sys/times.h>
int errno;
extern pthread_t hthread_capture ;//capture thread!

bool open_video() ;//open video
char *NextFrame() ;//capture one frame data
void close_video() ;//close video and free resource
bool capture_Run(pthread_mutex_t *capture_lock) ;//create capture thread
void *thread_capture(pthread_mutex_t *capture_lock) ;//capture thread function
bool encode_jpeg(char *lpbuf,int width ,int height,pthread_mutex_t *capture_lock) ;//jpeg encode
#endif
视频采集源文件:capture.c

#include "capture.h"
//struct video_capture v_capture ;

//定义视频扑捉相应的结构体
struct video_mbuf v_bufferproperty ;//此结构体利用mmap进行映射帧信息
//实际上是输入到摄像头存储器缓冲区的帧信息
struct video_mmap *v_memorymap ;//用于内存映射
struct video_picture v_imageproperty ;//采集图像的各种属性
struct video_capability v_capability ;//摄像头的基本信息
char *memorymap ;
int bufferIndex=0 ;
//struct v4l vd ;//vidoe4linux


//define the variable
char* deviceName = "/dev/v4l/video0";  
char *fname="temp.jpg" ;
int deviceHandle = 0;
int width = 320;  
int height = 240;  
int depth=16;  
int palette=VIDEO_PALETTE_RGB24;  
 
 
//conrresponding to thread
pthread_t hthread_capture ;//capture thread!

bool open_video()
{
 int ret =-1 ;
 //open device
 deviceHandle=open(deviceName,O_RDWR) ;//read and write mode
 if(deviceHandle==-1)
 {
  printf("Capture:Open failed!/n") ;
  printf("Mesg:%s/n",sys_errlist[errno]) ;
  return false ;
 }
 
 //get the property of capture
 ret=ioctl(deviceHandle,VIDIOCGCAP,&v_capability) ;
 if(ret == -1)
 {
  printf("Capture:obtain capability failed!/n") ;
  printf("Mesg:%s/n",sys_errlist[errno]) ;
  close(deviceHandle) ;//关闭设备文件
  return false ;
 }
 if((v_capability.type&VID_TYPE_CAPTURE)==0)
 {
  printf("Capture:this device can't capture video to memory!/n") ;
  close(deviceHandle) ;//关闭设备文件
  return false ;
 }
 //print the information of capture
  printf(v_capability.name);
  printf(", Type:%d/n",v_capability.type);
  printf("Maxwidth:%d,Maxheight:%d/n",v_capability.maxwidth ,v_capability.maxheight);
  printf("Minwidth:%d,Minheight:%d/n",v_capability.minwidth,v_capab

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值