main.cpp

来自「linux和arm下usb摄像头图像的获取」· C++ 代码 · 共 44 行

CPP
44
字号
#include "camera.h"
#include <stdio.h>
#include <fcntl.h>
int main(void)
{
	char *imageBuf;
	int readBytes;	
	int fd;
	char fileName[20];
	FILE *fp;
	imageBuf = NULL;
	readBytes = 0;
	Camera cam(0, 320, 240, VIDEO_PALETTE_JPEG, methodRead);
	for(; imageBuf == NULL;)
	{
		printf("allocate memory for image buffer\n");
		imageBuf = (char *)malloc(25 * 1024);
	}
	
	cam.openCamera();
	for(;;)
	{
		memset(fileName, 0, sizeof (fileName));
		printf("Please input a file name to save the image:");
		scanf("%s", fileName);
		readBytes = cam.readFrame(imageBuf);
		printf("readBytes = %d\n", readBytes);

		/*fd = open(fileName, O_WRONLY);		
		//write(fd, imageBuf, readBytes);
		printf("filename=%s, fd=%d, size=%d\n", fileName, fd, write(fd, imageBuf, readBytes));
		close(fd);*/

		fp = fopen(fileName, "wb+");
		fwrite(imageBuf, readBytes, 1, fp);
		fclose(fp);
	}
	
	cam.closeCamera();
	
	return 0;
}

⌨️ 快捷键说明

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