热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

linux摄像头编程问题

linux摄像头编程问题--Linux通用技术-Linux编程与内核信息,下面是详情阅读。
本人是个菜鸟,在网上找了一些资料,想写个摄像头的调用代码,遇到了一些问题,请高手指教,非常感谢,代码如下:
#include
using namespace std;

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define DEFAULT "/dev/video0"


struct video_capability video_cap;
struct video_picture picture;
struct video_window window;
struct video_mbuf mbuf;
struct video_mmap mmap1;
struct video_channel channel ;
int main(){
printf("hello");
int video_dev = open(DEFAULT,O_RDWR);
cout<<"get dev "< if(ioctl(video_dev,VIDIOCGCAP,&video_cap) == -1)
{
perror("Cann't get the information of the video device");
cout<<"erro";
close(video_dev);
exit(1);
}
int i ;
for (i =0;i channel.channel = i ;
if(ioctl(video_dev,VIDIOCGCHAN,&channel)==-1){
perror("can not get the ifmation of the channels");
cout<<"erro about channels ;";
close(video_dev);
exit(3);
}if(channel.type ==VIDEO_TYPE_TV){
printf("the %d is name :%s",i,channel.name);
}if(channel.type ==VIDEO_TYPE_CAMERA){
if(ioctl(video_dev,VIDIOCSCHAN,&channel)==-1){
perror("cant set the camera channel ");
close(video_dev);
exit(4);
}
}
}

picture.palette = VIDEO_PALETTE_RGB32;
//picture.colour = 0;
//picture.brightness = 65535 ;
if(ioctl(video_dev,VIDIOCSPICT,&picture)==-1){
perror("cant set picture");
close(video_dev);
exit(6);
}
if(ioctl(video_dev,VIDIOCMCAPTURE,&mbuf)==-1){
perror("capture failed");
close(video_dev);
exit(7);
}
unsigned char *frames = (unsigned char *)::mmap(0,mbuf.size,PROT_READ|PROT_WRITE,MAP_SHARED,video_dev,0);
if(!frames || frames == (unsigned char *)(long)(-1))
{
perror("The device cann't be memory mapped!");
close(video_dev);
exit(8);
}
if(ioctl(video_dev,VIDIOCMCAPTURE,&mmap) == -1)
{
perror("Capture failed!");
close(video_dev);
exit(9);
}

else
{
//display or save the picture file
printf("successful!");
}

}
输出结果为:cant set picture: Invalid argument
helloget dev 3

我原以为是picture.palette = VIDEO_PALETTE_RGB32;这的设置问题,可是我换了1到16都不行,于是我上网找到了个测试代码:/*
* v4l_tools A small set of tools for video4linux
* Copyright (C) 2002, 2003 Raphael Assenat
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warrenty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Raphael Assenat
* raph@raphnet.net
* http://www.raphnet.net
*
* */
#include
#include
#include
#include
#include
#include
#include
#include
#include

// vars
char *video_device="/dev/video0";
char *palette="";

// proto
int try_palette(int fd, unsigned short palette, struct video_picture *vpic);
int getPaletteId(char *palette);

int main(int argc, char **argv)
{
int res;
int fd=-1;

struct video_picture vpic;

if (argc<2) {
printf("Usage: ./v4l_set_palette palette [device]\n");
printf("VIDEO_PALETTE_GREY\n");
printf("VIDEO_PALETTE_HI240,\n");
printf("VIDEO_PALETTE_RGB565\n");
printf("VIDEO_PALETTE_RGB24\n");
printf("VIDEO_PALETTE_RGB32\n");
printf("VIDEO_PALETTE_RGB555\n");
printf("VIDEO_PALETTE_YUV422\n");
printf("VIDEO_PALETTE_YUYV\n");
printf("VIDEO_PALETTE_UYVY\n");
printf("VIDEO_PALETTE_YUV420\n");
printf("VIDEO_PALETTE_YUV411\n");
printf("VIDEO_PALETTE_RAW\n");
printf("VIDEO_PALETTE_YUV422P\n");
printf("VIDEO_PALETTE_YUV411P\n");
printf("VIDEO_PALETTE_YUV420P\n");
printf("VIDEO_PALETTE_YUV410P\n");
printf("VIDEO_PALETTE_PLANAR\n");
printf("VIDEO_PALETTE_COMPONENT\n\n");
return 0;
}

if (argc>2) {
video_device=argv[2];
}

palette = argv[1];

printf("Using device %s\n", video_device);
printf("Setting palette %s\n", palette);

fd = open(video_device, O_RDWR);
if (fd<0) {
perror("open");
return -1;
}

/* Read the initial settings */
res = ioctl(fd, VIDIOCGPICT, &vpic);
if (res<0) {
perror("VIDIOCGPICT");
goto shutdown;
}

vpic.palette = getPaletteId(palette);
if (vpic.palette==0) {
fprintf(stderr, "Unknown palette\n");
goto shutdown;
}

if (try_palette(fd, vpic.palette, &vpic)==0) {
fprintf(stderr, "Could not set palette\n");
}

shutdown:
if (fd!=-1) { close(fd); }

return 0;
}


int getPaletteId(char *palette)
{

if (strcasecmp(palette, "VIDEO_PALETTE_GREY")==0) { return VIDEO_PALETTE_GREY; }
if (strcasecmp(palette, "VIDEO_PALETTE_HI240")==0) { return VIDEO_PALETTE_HI240; }
if (strcasecmp(palette, "VIDEO_PALETTE_RGB565")==0) { return VIDEO_PALETTE_RGB565; }
if (strcasecmp(palette, "VIDEO_PALETTE_RGB24")==0) { return VIDEO_PALETTE_RGB24; }
if (strcasecmp(palette, "VIDEO_PALETTE_RGB32")==0) { return VIDEO_PALETTE_RGB32; }
if (strcasecmp(palette, "VIDEO_PALETTE_RGB555")==0) { return VIDEO_PALETTE_RGB555; }
if (strcasecmp(palette, "VIDEO_PALETTE_YUV422")==0) { return VIDEO_PALETTE_YUV422; }
if (strcasecmp(palette, "VIDEO_PALETTE_YUYV")==0) { return VIDEO_PALETTE_YUYV; }
if (strcasecmp(palette, "VIDEO_PALETTE_UYVY")==0) { return VIDEO_PALETTE_UYVY; }
if (strcasecmp(palette, "VIDEO_PALETTE_YUV420")==0) { return VIDEO_PALETTE_YUV420; }
if (strcasecmp(palette, "VIDEO_PALETTE_YUV411")==0) { return VIDEO_PALETTE_YUV411; }
if (strcasecmp(palette, "VIDEO_PALETTE_RAW")==0) { return VIDEO_PALETTE_RAW; }
if (strcasecmp(palette, "VIDEO_PALETTE_YUV422P")==0) { return VIDEO_PALETTE_YUV422P; }
if (strcasecmp(palette, "VIDEO_PALETTE_YUV411P")==0) { return VIDEO_PALETTE_YUV411P; }
if (strcasecmp(palette, "VIDEO_PALETTE_YUV420P")==0) { return VIDEO_PALETTE_YUV420P; }
if (strcasecmp(palette, "VIDEO_PALETTE_YUV410P")==0) { return VIDEO_PALETTE_YUV410P; }

return 0;
}


/* set the video picture using the given palette. Returns 1 if it seems
* to work, otherwise 0 */
int try_palette(int fd, unsigned short palette, struct video_picture *vpic)
{
struct video_picture gpic;

vpic->palette = palette;

if (ioctl(fd, VIDIOCSPICT, vpic)<0) { return 0; }

ioctl(fd, VIDIOCGPICT, &gpic);
if (gpic.palette!=vpic->palette) { printf("MISMATCH. "); return 0; }


return 1;
}
编译运行之后确输出:Using device /dev/video0
Setting palette /dev/video0
Unknown palette
为什么啊,我用的是fedora,我用系统自带的一个cheese照相机,是可以调用摄像头的啊?

求高手解决啊,真的困扰我很久了 。。。。
推荐阅读
  • PHP玩家基地系统毕业设计(附源码、运行环境)的用户登录界面、游戏管理和玩家作品管理
    本文介绍了一个PHP玩家基地系统的毕业设计,包括用户登录界面、游戏管理和玩家作品管理等功能。附带源码和运行环境,并提供免费赠送本源代码和数据库的方式,请私信获取详细信息。摘要共计约XXX字。 ... [详细]
  • Monkey《大话移动——Android与iOS应用测试指南》的预购信息发布啦!
    Monkey《大话移动——Android与iOS应用测试指南》的预购信息已经发布,可以在京东和当当网进行预购。感谢几位大牛给出的书评,并呼吁大家的支持。明天京东的链接也将发布。 ... [详细]
  • 本文介绍了在开发Android新闻App时,搭建本地服务器的步骤。通过使用XAMPP软件,可以一键式搭建起开发环境,包括Apache、MySQL、PHP、PERL。在本地服务器上新建数据库和表,并设置相应的属性。最后,给出了创建new表的SQL语句。这个教程适合初学者参考。 ... [详细]
  • 基于layUI的图片上传前预览功能的2种实现方式
    本文介绍了基于layUI的图片上传前预览功能的两种实现方式:一种是使用blob+FileReader,另一种是使用layUI自带的参数。通过选择文件后点击文件名,在页面中间弹窗内预览图片。其中,layUI自带的参数实现了图片预览功能。该功能依赖于layUI的上传模块,并使用了blob和FileReader来读取本地文件并获取图像的base64编码。点击文件名时会执行See()函数。摘要长度为169字。 ... [详细]
  • 搭建Windows Server 2012 R2 IIS8.5+PHP(FastCGI)+MySQL环境的详细步骤
    本文详细介绍了搭建Windows Server 2012 R2 IIS8.5+PHP(FastCGI)+MySQL环境的步骤,包括环境说明、相关软件下载的地址以及所需的插件下载地址。 ... [详细]
  • PHP图片截取方法及应用实例
    本文介绍了使用PHP动态切割JPEG图片的方法,并提供了应用实例,包括截取视频图、提取文章内容中的图片地址、裁切图片等问题。详细介绍了相关的PHP函数和参数的使用,以及图片切割的具体步骤。同时,还提供了一些注意事项和优化建议。通过本文的学习,读者可以掌握PHP图片截取的技巧,实现自己的需求。 ... [详细]
  • 关羽败走麦城时路过马超封地 马超为何没有出手救人
    对当年关羽败走麦城,恰好路过马超的封地,为啥马超不救他?很感兴趣的小伙伴们,趣历史小编带来详细的文章供大家参考。说到英雄好汉,便要提到一本名著了,没错,那就是《三国演义》。书中虽 ... [详细]
  • 本文分享了一个关于在C#中使用异步代码的问题,作者在控制台中运行时代码正常工作,但在Windows窗体中却无法正常工作。作者尝试搜索局域网上的主机,但在窗体中计数器没有减少。文章提供了相关的代码和解决思路。 ... [详细]
  • 本文介绍了使用Java实现大数乘法的分治算法,包括输入数据的处理、普通大数乘法的结果和Karatsuba大数乘法的结果。通过改变long类型可以适应不同范围的大数乘法计算。 ... [详细]
  • PHP设置MySQL字符集的方法及使用mysqli_set_charset函数
    本文介绍了PHP设置MySQL字符集的方法,详细介绍了使用mysqli_set_charset函数来规定与数据库服务器进行数据传送时要使用的字符集。通过示例代码演示了如何设置默认客户端字符集。 ... [详细]
  • Java序列化对象传给PHP的方法及原理解析
    本文介绍了Java序列化对象传给PHP的方法及原理,包括Java对象传递的方式、序列化的方式、PHP中的序列化用法介绍、Java是否能反序列化PHP的数据、Java序列化的原理以及解决Java序列化中的问题。同时还解释了序列化的概念和作用,以及代码执行序列化所需要的权限。最后指出,序列化会将对象实例的所有字段都进行序列化,使得数据能够被表示为实例的序列化数据,但只有能够解释该格式的代码才能够确定数据的内容。 ... [详细]
  • 橱窗设计的表现手法及其应用
    本文介绍了橱窗设计的表现手法,包括直接展示、寓意与联想、夸张与幽默等。通过对商品的折、拉、叠、挂、堆等陈列技巧,橱窗设计能够充分展现商品的形态、质地、色彩、样式等特性。同时,寓意与联想可以通过象形形式或抽象几何道具来唤起消费者的联想与共鸣,创造出强烈的时代气息和视觉空间。合理的夸张和贴切的幽默能够明显夸大商品的美的因素,给人以新颖奇特的心理感受,引起人们的笑声和思考。通过这些表现手法,橱窗设计能够有效地传达商品的个性内涵,吸引消费者的注意力。 ... [详细]
  • HDU 2372 El Dorado(DP)的最长上升子序列长度求解方法
    本文介绍了解决HDU 2372 El Dorado问题的一种动态规划方法,通过循环k的方式求解最长上升子序列的长度。具体实现过程包括初始化dp数组、读取数列、计算最长上升子序列长度等步骤。 ... [详细]
  • faceu激萌变老特效的使用方法详解
    本文介绍了faceu激萌变老特效的使用方法,包括打开faceu激萌app、点击贴纸、选择热门贴纸中的变老特效,然后对准人脸进行拍摄,即可给照片添加变老特效。操作简单,适合新用户使用。 ... [详细]
  • Android中高级面试必知必会,积累总结
    本文介绍了Android中高级面试的必知必会内容,并总结了相关经验。文章指出,如今的Android市场对开发人员的要求更高,需要更专业的人才。同时,文章还给出了针对Android岗位的职责和要求,并提供了简历突出的建议。 ... [详细]
author-avatar
爱到最后还是分离_851
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有