天嵌 ARM开发社区

 找回密码
 注册
查看: 5491|回复: 20

关于QT2.2.0自带的照相机应用问题。

[复制链接]
无聊 发表于 2012-5-17 13:49:45 | 显示全部楼层 |阅读模式
我把QT2.2.0移植到了板子上了。
然后插上摄像头,也能显示图像,照相功能也能用了。。

但是它显示的图像存在一些问题。
第一:刷新貌似很慢。就是我移动了一下摄像头,他要过一会儿才能反映过来。实时性不好。
第二:他刷新图像的时候,经常出现一半一半的情况,就是显示的图像,在刷新的过程,色调什么的一直在变化。。。上半部分和下半部分的色调或者说亮度有点不同。。。

我自己看了下代码。能看懂一些。。。
但是如何修改到更好却无从下手啊。。。。

求指教,该修改哪些参数?还是什么?
亚瑟王 发表于 2012-5-17 17:57:44 | 显示全部楼层
要修改两个方面:
1、2440自带的摄像头控制器,
2、ov9650的初始化参数。
具体值要根据你要显示的分辨率等信息来确定。建议看一下芯片手册。
 楼主| 无聊 发表于 2012-5-18 09:00:35 | 显示全部楼层
亚瑟王 发表于 2012-5-17 17:57
要修改两个方面:
1、2440自带的摄像头控制器,
2、ov9650的初始化参数。

自带的摄像头控制器指的是什么啊??

另,我用的是中星微的摄像头,zc301的。
驱动是自己insmod进去的gspca的驱动。、、、、
亚瑟王 发表于 2012-5-18 11:59:28 | 显示全部楼层
无聊 发表于 2012-5-18 09:00
自带的摄像头控制器指的是什么啊??

另,我用的是中星微的摄像头,zc301的。

哦,你用的是usb摄像头吗?检查一下你的摄像头采集的分辨率之类的吧。
我以为你用的是OV9650呢。
 楼主| 无聊 发表于 2012-5-18 13:01:55 | 显示全部楼层
亚瑟王 发表于 2012-5-18 11:59
哦,你用的是usb摄像头吗?检查一下你的摄像头采集的分辨率之类的吧。
我以为你用的是OV9650呢。

就是修改video_capability结构体的东西吗?
 楼主| 无聊 发表于 2012-5-18 17:59:50 | 显示全部楼层
亚瑟王 发表于 2012-5-18 11:59
哦,你用的是usb摄像头吗?检查一下你的摄像头采集的分辨率之类的吧。
我以为你用的是OV9650呢。

我修改了其中的长宽,图像变得清楚一些了。。。

但是他刷新的还是很慢。。。

请问这个应该修改哪个地方啊?
亚瑟王 发表于 2012-5-18 18:54:59 | 显示全部楼层
无聊 发表于 2012-5-18 17:59
我修改了其中的长宽,图像变得清楚一些了。。。

但是他刷新的还是很慢。。。

分辨率呢?
 楼主| 无聊 发表于 2012-5-18 19:40:48 | 显示全部楼层
本帖最后由 无聊 于 2012-5-24 09:04 编辑
亚瑟王 发表于 2012-5-18 18:54
分辨率呢?

void VideoCapture::setupCamera( QSize size )
{
    // Clear important variables.
    frames = 0;
    currentFrame = 0;
    width = 640;
    height = 480;
    caps.minwidth = width;
    caps.minheight = height;
    caps.maxwidth = width;
    caps.maxheight = height;

    // Open the video device.
    fd = open( VIDEO_DEVICE, O_RDWR );
    if ( fd == -1 ) {
        qDebug( "%s: %s", VIDEO_DEVICE, strerror( errno ) );
        return;
    }

    // Get the device's current capabilities.
    memset( &caps, 0, sizeof( caps ) );
    if ( ioctl( fd, VIDIOCGCAP, &caps ) < 0 ) {
        qDebug( "%s: could not retrieve the video capabilities",
                VIDEO_DEVICE );
        close( fd );
        fd = -1;
        return;
    }

    // Change the channel to the first-connected camera, skipping TV inputs.
    // If there are multiple cameras, this may need to be modified.
    int chan;
    struct video_channel chanInfo;
    qDebug( "available video capture inputs:" );
    for ( chan = 0; chan < caps.channels; ++chan ) {
        chanInfo.channel = chan;
        if ( ioctl( fd, VIDIOCGCHAN, &chanInfo ) >= 0 ) {
            if ( chanInfo.type == VIDEO_TYPE_CAMERA )
                qDebug( "    %s (camera)", chanInfo.name );
            else if ( chanInfo.type == VIDEO_TYPE_TV )
                qDebug( "    %s (tv)", chanInfo.name );
            else
                qDebug( "    %s (unknown)", chanInfo.name );
        }
    }
    for ( chan = 0; chan < caps.channels; ++chan ) {
        chanInfo.channel = chan;
        if ( ioctl( fd, VIDIOCGCHAN, &chanInfo ) >= 0 ) {
            if ( chanInfo.type == VIDEO_TYPE_CAMERA ) {
                qDebug( "selecting camera on input %s", chanInfo.name );
                if ( ioctl( fd, VIDIOCSCHAN, &chan ) < 0 ) {
                    qDebug( "%s: could not set the channel", VIDEO_DEVICE );
                }
                break;
            }
        }
    }

    // Set the desired picture mode to RGB32.
    struct video_picture pict;
    memset( &pict, 0, sizeof( pict ) );
    ioctl( fd, VIDIOCGPICT, &pict );
    pict.palette = VIDEO_PALETTE_RGB32;
    if ( ioctl( fd, VIDIOCSPICT, &pict ) < 0 ) {
        qDebug( "%s: could not set the picture mode", VIDEO_DEVICE );
        close( fd );
        fd = -1;
        return;
    }

    // Determine the capture size to use.  Zero indicates "preview mode".
    if ( size.width() == 0 ) {
        size = QSize( caps.minwidth, caps.minheight );
    }

    // Get the current capture window.
    struct video_window wind;
    memset( &wind, 0, sizeof( wind ) );
    ioctl( fd, VIDIOCGWIN, &wind );

    // Adjust the capture size to match the camera's aspect ratio.
    if ( caps.maxwidth > 0 && caps.maxheight > 0 ) {
        if ( size.width() > size.height() ) {
            size = QSize( size.height() * caps.maxwidth / caps.maxheight,
                          size.height() );
        } else {
            size = QSize( size.width(),
                          size.width() * caps.maxheight / caps.maxwidth );
        }
    }

    // Set the new capture window.
    wind.x = 0;
    wind.y = 0;
    wind.width = size.width();
    wind.height = size.height();
    if ( ioctl( fd, VIDIOCSWIN, &wind ) < 0 ) {
        qDebug( "%s: could not set the capture window", VIDEO_DEVICE );
    }

    // Re-read the capture window, to see what it was adjusted to.
    ioctl( fd, VIDIOCGWIN, &wind );
    width = wind.width;
    height = wind.height;

    // Enable mmap-based access to the camera.
    memset( &mbuf, 0, sizeof( mbuf ) );
    if ( ioctl( fd, VIDIOCGMBUF, &mbuf ) < 0 ) {
        qDebug( "%s: mmap-based camera access is not available", VIDEO_DEVICE );
        close( fd );
        fd = -1;
        return;
    }

    // Mmap the designated memory region.
    frames = (unsigned char *)mmap( 0, mbuf.size, PROT_READ | PROT_WRITE,
                                    MAP_SHARED, fd, 0 );
    if ( !frames || frames == (unsigned char *)(long)(-1) ) {
        qDebug( "%s: could not mmap the device", VIDEO_DEVICE );
        close( fd );
        fd = -1;
        return;
    }

    // Start capturing of the first frame.
    struct video_mmap capture;
    currentFrame = 0;
    capture.frame = currentFrame;
    capture.width = width;
    capture.height = height;
    capture.format = VIDEO_PALETTE_RGB32;
    ioctl( fd, VIDIOCMCAPTURE, &capture );
}
应该是这段源码的缘故吧?

 楼主| 无聊 发表于 2012-5-18 19:41:24 | 显示全部楼层
:'(表示鸭梨大。。。。
没名字了~~~ 发表于 2012-5-23 08:52:32 | 显示全部楼层
亚瑟王 发表于 2012-5-18 18:54
分辨率呢?

借个地方问下亚瑟,ov9650的初始成像是240*320的,如何设置成480*272,要修改哪几个文件,我改了camera_test.c貌似没有用。
亚瑟王 发表于 2012-5-23 19:09:51 | 显示全部楼层
无聊 发表于 2012-5-18 19:40
void VideoCapture::setupCamera( QSize size )
{
    // Clear important variables.

你了解一下V4L协议,然后你再来看这个程序,你就会了。
亚瑟王 发表于 2012-5-23 19:10:26 | 显示全部楼层
没名字了~~~ 发表于 2012-5-23 08:52
借个地方问下亚瑟,ov9650的初始成像是240*320的,如何设置成480*272,要修改哪几个文件,我改了camera_t ...

需要修改驱动。
 楼主| 无聊 发表于 2012-5-24 09:06:00 | 显示全部楼层
亚瑟王 发表于 2012-5-23 19:09
你了解一下V4L协议,然后你再来看这个程序,你就会了。

是不是应该去修改video_picture这个结构体里面的一些信息啊?

我修改了前面的帧周期,以及把他的大小改为320x240还是解决不了,一半一半刷的情况啊。。。
 楼主| 无聊 发表于 2012-5-24 10:37:57 | 显示全部楼层
亚瑟王 发表于 2012-5-23 19:09
你了解一下V4L协议,然后你再来看这个程序,你就会了。

我自己写过一个不用QT的一个图像显示的。

是成功了的。不会出现上述那种,一半一半刷,而且实时性很不好的情况啊。

但是我对照着我写的那个程序来改写了这个自带的照相机应用的程序,他还是会出现图像刷新缓慢的情况啊。就是我动了一下摄像头,他要反应一会儿才显示新的东西,而且在显示的过程,不断的在刷新,就是看上去亮度和色度一直在刷新啊。。。
 楼主| 无聊 发表于 2012-5-24 10:38:53 | 显示全部楼层
求帮助。。求解惑啊。。。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

i.MX8系列ARM cortex A53 M4 工控板上一条 /1 下一条

Archiver|手机版|小黑屋|天嵌 嵌入式开发社区 ( 粤ICP备11094220号 )

GMT+8, 2024-5-5 20:15 , Processed in 1.031257 second(s), 18 queries .

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表