资源简介
自己写的USB摄像头采集程序,编译需要用到jpeg库,验证运行OK,和大家分享。
代码片段和文件信息
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define CAMERA_DEVICE “/dev/video2“
/*#define CAPTURE_FILE “usbpic.jpg“ */
#define CAPTURE_FILE0 “usbpic0.jpg“
#define CAPTURE_FILE1 “usbpic1.jpg“
#define CAPTURE_FILE2 “usbpic2.jpg“
#define CAPTURE_FILE3 “usbpic3.jpg“
#define VIDEO_WIDTH 320
#define VIDEO_HEIGHT 240
#define VIDEO_FORMAT V4L2_PIX_FMT_YUYV
#define BUFFER_COUNT 4
#define jpegQuality 80
typedef struct VideoBuffer {
void *start;
size_t length;
} VideoBuffer;
static void YUV422toRGB888(int width int height unsigned char *src unsigned char *dst)
{
int line column;
unsigned char *py *pu *pv;
unsigned char *tmp = dst;
/* In this format each four bytes is two pixels. Each four bytes is two Y‘s a Cb and a Cr.
Each Y goes to one of the pixels and the Cb and Cr belong to both pixels. */
py = src;
pu = src + 1;
pv = src + 3;
printf(“4\n“);
#define CLIP(x) ( (x)>=0xFF ? 0xFF : ( (x) <= 0x00 ? 0x00 : (x) ) )
printf(“5\n“);
for (line = 0; line < height; ++line) {
for (column = 0; column < width; ++column) {
*tmp++ = CLIP((double)*py + 1.402*((double)*pv-128.0));
*tmp++ = CLIP((double)*py - 0.344*((double)*pu-128.0) - 0.714*((double)*pv-128.0));
*tmp++ = CLIP((double)*py + 1.772*((double)*pu-128.0));
// increase py every time
py += 2;
// increase pupv every second time
if ((column & 1)==1) {
pu += 4;
pv += 4;
}
}
}
printf(“6\n“);
}
static void jpegWrite(unsigned char* img FILE *fp)
{
struct jpeg_compress_struct cinfo;
struct jpeg_error_mgr jerr;
JSAMPROW row_pointer[1];
if ((NULL==img) || (NULL==fp))
{
printf(“jpegWrite: para error.\n“);
return;
}
// create jpeg data
cinfo.err = jpeg_std_error( &jerr );
jpeg_create_compress(&cinfo);
jpeg_stdio_dest(&cinfo fp);
// set image parameters
cinfo.image_width = VIDEO_WIDTH;
cinfo.image_height = VIDEO_HEIGHT;
cinfo.input_components = 3;
cinfo.in_color_space = JCS_RGB;
// set jpeg compression parameters to default
jpeg_set_defaults(&cinfo);
// and then adjust quality setting
jpeg_set_quality(&cinfo jpegQuality TRUE);
// start compress
jpeg_start_compress(&cinfo TRUE);
// feed data
while (cinfo.next_scanline < cinfo.image_height)
{
row_pointer[0] = &img[cinfo.next_scanline * cinfo.image_width * cinfo.input_components];
jpeg_write_scanlines(&cinfo row_pointer 1);
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2012-08-16 16:50 cameraGrap\
文件 9996 2012-08-16 10:38 cameraGrap\UsbCamPic.c
- 上一篇:数据库转换,礼光,欧凯,新德利
- 下一篇:VHDL N位 除法器
相关资源
- linux下基于V4L2/Qt的usb摄像头采集显示
- v4l2采集MJPG保存到本地
- linux qt4.7 v4l2 YUV(YUYV) mmap 显示视频
- V4L2 通过JRTPLIB 实现RTP实时视频传输并
- singleCamD
- MAX9286的V4L2测试代码
- webcam_v4l2_x264
- 嵌入式平台ARm9使用V4L2格式摄像头抓帧
- linux下基于QT和v4l2驱动的USB摄像头视频
- 智能家居的项目用的 V4L2
- v4l2采集视频并保存和lcd显示
- v4l2 QT MJPEG格式 视频采集+屏幕显示+图
- 使用Linux的V4L2读取摄像头数据+Opencv图
- v4l2 qt实时显示摄像头数据未使用ope
- V4L2视频采集与h264编码
- linux下v4l2实现图片采集
- 基于QT的V4L2摄像头视频采集并显示
- tiny4412 + qtopia + v4l2 + usb camera
- Linux Media Subsystem Documentation
- 冒死上传公司车载设备源码 支持gp
- V4L2+FFMPEG+live555实现流媒体服务端
- LINUX下采集视频数据并编码为H264项目
- Linux 下V4l2摄像头采集图片,实现yuy
- linux v4l2视频采集教程
- TI OMAP3 ISP驱动整体框架、流程整理分
- 基于V4l2的uvc摄像头视频录像代码avi
- linux下v4l2视频采集源代码
- Linux 下 v4l2 和 Qt 连接usb摄像头
- UVC驱动抓图测试程序--基于V4L2
评论
共有 条评论