#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 "<
{
perror("Cann't get the information of the video device");
cout<<"erro";
close(video_dev);
exit(1);
}
int i ;
for (i =0;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照相机,是可以调用摄像头的啊?
求高手解决啊,真的困扰我很久了 。。。。
blue_rain 于 2011-11-01 12:17:05发表:
求高手解答啊
erfcend 于 2011-11-01 08:45:24发表:
路过
blue_rain 于 2011-10-31 23:33:34发表:
还有些测试信息:[chenchao@localhost v4l_dump]$ ./v4l_dump
Using device /dev/video0
struct video_capability
{
name='USB 2.0 Camera'
channels=1
audios=0
maxwidth=640
maxheight=480
minwidth=48
minheight=32
}
VIDIOCGCHAN: Invalid argument
struct video_picture
{
brightness=0
hue=0
colour=0
contrast=0
whiteness=0
depth=16
palette=8
}
以及
[chenchao@localhost v4l_probe_palettes]$ ./v4l_probe_palettes
Using device /dev/video0
Supported palettes:
VIDEO_PALETTE_GREY: NO
VIDEO_PALETTE_HI240: NO
VIDEO_PALETTE_RGB565: NO
VIDEO_PALETTE_RGB24: NO
VIDEO_PALETTE_RGB32: NO
VIDEO_PALETTE_RGB555: NO
VIDEO_PALETTE_YUV422: MISMATCH. NO
VIDEO_PALETTE_YUV411: NO
VIDEO_PALETTE_RAW: NO
VIDEO_PALETTE_YUV422P: NO
VIDEO_PALETTE_YUV411P: NO
VIDEO_PALETTE_YUV420P: NO
VIDEO_PALETTE_YUV410P: NO