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

📄 camera.h-orig

📁 linux和arm下usb摄像头图像的获取
💻 H-ORIG
字号:
#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 <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>

#define VIDEO_PALETTE_JPEG  21
#define methodRead 0
#define methodMmap 1
#define OUTFRMNUMB 4
#define debug 0

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 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;
		const char *name;
	};

	const static struct bridge_list Blist[]=
	{
		{BRIDGE_SPCA505,"SPCA505"},
		{BRIDGE_SPCA506,"SPCA506"},
		{BRIDGE_SPCA501,"SPCA501"},
		{BRIDGE_SPCA508,"SPCA508"},
		{BRIDGE_SPCA504,"SPCA504"},
		{BRIDGE_SPCA500,"SPCA500"},
		{BRIDGE_SPCA504B,"SPCA504B"},
		{BRIDGE_SPCA533,"SPCA533"},
		{BRIDGE_SPCA504C,"SPCA504C"},
		{BRIDGE_SPCA561,"SPCA561"},
		{BRIDGE_SPCA536,"SPCA536"},
		{BRIDGE_SONIX,"SN9C102"},
		{BRIDGE_ZR364XX,"ZR364XX"},
		{BRIDGE_ZC3XX,"ZC301-2"},
		{BRIDGE_CX11646,"CX11646"},
		{BRIDGE_TV8532,"TV8532"},
		{BRIDGE_ETOMS,"ET61XX51"},
		{BRIDGE_SN9CXXX,"SN9CXXX"},
		{BRIDGE_MR97311,"MR97311"},
		{BRIDGE_UNKNOW,"UNKNOW"},
		{-1,NULL}
	};
	
	int init_videoIn (struct vdIn *vd, char *device, int width, int height,  int format, int grabmethod);
	int GetDepth (int format);
	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);
	void grab (void);
	int v4lGrab (struct vdIn *vd );
	double ms_time (void);
	int convertframe(unsigned char *dst,unsigned char *src, int width,int height, int formatIn, int size);
	int get_jpegsize (unsigned char *buf, int insize);
	int close_v4l (struct vdIn *vd);
	void sigchld_handler();
	unsigned short bright;
 	unsigned short contrast;
	int format;
	int grabmethod;
	struct vdIn videoIn;
	char videodevice[50];
	int width;
	int height;
	pthread_t grabImgThrdId;
	struct sigaction sa;
}

#endif

⌨️ 快捷键说明

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