⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 camera.h

📁 linux和arm下usb摄像头图像的获取
💻 H
字号:
#ifndef CAMERA_H
#define CAMERA_H

#include <syslog.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <signal.h>
#include <errno.h>
#include <sys/time.h>
#include <math.h>
#include <stdarg.h>
#include <linux/types.h>
#include <linux/videodev.h>
#include <sys/mman.h>
#include <sys/ioctl.h>
#include <sys/file.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <pthread.h>

/* Our private ioctl */
#define SPCAGVIDIOPARAM _IOR('v',BASE_VIDIOCPRIVATE + 1,struct video_param)
#define SPCASVIDIOPARAM _IOW('v',BASE_VIDIOCPRIVATE + 2,struct video_param)
#define defaultDev "/dev/video0"
#define VIDEO_PALETTE_JPEG  21
#define methodRead 0
#define methodMmap 1
#define OUTFRMNUMB 4
#define debug 1

	struct video_param 
	{
		int chg_para;
		#define CHGABRIGHT 1
		#define CHGQUALITY 2
		#define CHGTINTER  4
		__u8 autobright;
		__u8 quality;
		__u16 time_interval;
	};

	
	struct vdIn 
	{
		int fd;
		char *videodevice ;
		struct video_mmap vmmap;
		struct video_capability videocap;
		int mmapsize;
		struct video_mbuf videombuf;
		struct video_picture videopict;
		struct video_window videowin;
		struct video_channel videochan;
		struct video_param videoparam;		
		int cameratype ;
		char *cameraname;
		char bridge[9];
		int sizenative; // available size in jpeg
		int sizeothers;	// others palette 
		int palette; // available palette
		int norme ; // set spca506 usb video grabber
		int channel ; // set spca506 usb video grabber
		int grabMethod ;
		unsigned char *pFramebuffer;
		unsigned char *ptframe[4];
		int framelock[4];
		pthread_mutex_t grabmutex;
		int framesizeIn ;
		volatile int frame_cour;
		int bppIn;
		int  hdrwidth;
		int  hdrheight;
		int  formatIn;
		int signalquit;	
	};


	struct frame_t
	{
		char header[5];
		int nbframe;
		double seqtimes;
		int deltatimes;
		int w;
		int h;
		int size;
		int format;
		unsigned short bright;
		unsigned short contrast;
		unsigned short colors;
		unsigned short exposure;
		unsigned char wakeup;
		int acknowledge;
	} __attribute__ ((packed));  

	
	enum 
	{
		JPEG = 0,
		YUVY,
		YYUV,
		YUYV,
		GREY,
		GBRG,
		SN9C,
		GBGR,
		UNOW,
	};
	
	/* specific for the spca5xx webcam */
	enum
	{
		BRIDGE_SPCA505 = 0,
		BRIDGE_SPCA506,
		BRIDGE_SPCA501,
		BRIDGE_SPCA508,
		BRIDGE_SPCA504,
		BRIDGE_SPCA500,
		BRIDGE_SPCA504B,
		BRIDGE_SPCA533,
		BRIDGE_SPCA504C,
		BRIDGE_SPCA561,
		BRIDGE_SPCA536,
		BRIDGE_SONIX,
		BRIDGE_ZR364XX,
		BRIDGE_ZC3XX,
		BRIDGE_CX11646,
		BRIDGE_TV8532,
		BRIDGE_ETOMS,
		BRIDGE_SN9CXXX,
		BRIDGE_MR97311,
		BRIDGE_UNKNOW,
		MAX_BRIDGE,
	};

	struct bridge_list
	{
		int num;
		char name[10];
	};

class Camera
{
public:
	Camera(char *deviceIn, int widthIn, int heightIn, int formatIn, int grabmethodIn);
	//Camera();
	~Camera();
	void openCamera();
	void closeCamera();
	int readFrame(char *buf);
	void  upbright();
	void downbright();
       void upcontrast();       
 	void downcontrast();
	
private:	

	struct bridge_list Blist[21];
	
	int init_videoIn (struct vdIn *vd, char *device, int width, int height,  int format, int grabmethod);
	int GetDepth (int format);
	void initBlist();
	int init_v4l (struct vdIn *vd);
	void exit_fatal(char *messages);
	int GetStreamId (const char *BridgeName);
	int isSpcaChip (const char *BridgeName);
	void spcaPrintParam (int fd, struct video_param *videoparam);
	int SetVideoPict (struct vdIn *vd);
	int GetVideoPict (struct vdIn *vd);
	static void* grab (void* arg);
	static int v4lGrab (struct vdIn *vd );
	static double ms_time (void);
	static int convertframe(unsigned char *dst,unsigned char *src, int width,int height, int formatIn, int size);
	static int get_jpegsize (unsigned char *buf, int insize);
	int close_v4l (struct vdIn *vd);
	void sigchld_handler();

	//static void * test(void *arg){};
	unsigned short bright;
 	unsigned short contrast;
	int format;
	int grabmethod;
	struct vdIn videoIn;
	char videodevice[50];
	int width;
	int height;
	int tmp;
	pthread_t grabImgThrdId;
	struct sigaction sa;
};

#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -