QQ登录

只需一步,快速开始

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 5011|回复: 13

如何显示视频图像(请各位大虾帮忙)

[复制链接]
发表于 2006-4-13 14:59:26 | 显示全部楼层 |阅读模式
鄙人做毕设 需要用gtk编写摄像头界面 并且显示视频图像出来

现在界面大体没有问题,关键想请教各位大虾 如何编写回调函数 显示视频图像
摄像头捕捉的动态图像  如何才能显示出来



万分感谢 麻烦帮我解决这个问题
 楼主| 发表于 2006-4-14 14:49:45 | 显示全部楼层
急啊 ...各位

懂得密一下啦....
回复

使用道具 举报

发表于 2006-4-14 23:53:18 | 显示全部楼层
记得以前写过一个例子,周一给你贴上来。
回复

使用道具 举报

 楼主| 发表于 2006-4-17 09:15:56 | 显示全部楼层
mozilla,  万分感谢斑竹
回复

使用道具 举报

发表于 2006-4-17 13:09:41 | 显示全部楼层
[code:1]
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <linux/videodev.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <X11/Xlib.h>
#include <X11/extensions/Xvlib.h>


#define YUV420P_SIZE 115200
#define RGB_SIZE 230400
Display* display;
Window win;
GC gc;

int create_win(int x,int y,int width,int height)
{

        display = XOpenDisplay(NULL);
        if (display == NULL) {
            printf("cannot open display\n");
            return -1;
        }

        win = XCreateSimpleWindow(display, RootWindow(display, 0),
                        x, y, width, height, 2,
                        WhitePixel(display, 0),
                        BlackPixel(display, 0));

        gc=XCreateGC(display, win, 0, NULL);
        XSelectInput(display,win,KeyPressMask|StructureNotifyMask);
        XMapWindow(display, win);
        XMoveWindow(display,win,x,y);
        XSync(display, False);
}

XvImage *create_XvImage(Display *dsp,Window window,void *imgdata,XvPortID *xvport)
{
    int i,num;
    XvImage *image;
    unsigned int nadap=0;
    XvAdaptorInfo *adaps;
    XvImageFormatValues *format;
    XvQueryAdaptors(dsp,window,&nadap,&adaps);

   
    for(i=0;i<nadap;i++)
    {
        if((adaps[i].type & XvInputMask) && (adaps[i].type & XvImageMask))
        {
            *xvport=adaps[i].base_id;
            break;
        }
    }
    if(*xvport < 0)
    {
        printf("Xv Port failed\n");
        return NULL;
    }

    format=XvListImageFormats(dsp,*xvport,&num);
    if(!format)
    {
        printf("XvListImageFormats failed\n");
        return NULL;
    }
    image=XvCreateImage(dsp,*xvport,format[1].id,imgdata,320,240);
    return image;
}

Bool predicate(Display *dsp,XEvent *event,XPointer arg)
{
    return True;
}
main()
{
    void *imgdata=NULL;
    XvImage *image;
    XvPortID xvport;
    int fd;

    int imgsize,i;
    XEvent xevent;
    fd = open("/dev/video0",O_RDWR);
    if(!fd)
        return;
    create_win(50,50,320,240);
    imgsize=YUV420P_SIZE;
    imgdata=malloc(imgsize);
    image=create_XvImage(display,win,imgdata,&xvport);
    if(!image)
            return;
    while(1)
    {
        XCheckIfEvent(display,&xevent,predicate,NULL);
        if(xevent.type==KeyPress)
        {
            xevent.type=0;
            break;
        }
        read(fd,imgdata,imgsize);
        XvPutImage(display,xvport,win,gc,image,0,0,320,240,0,0,320,240);
    }
failed:
    XCloseDisplay(display);
    close(fd);
}

[/code:1]
回复

使用道具 举报

 楼主| 发表于 2006-4-17 15:51:55 | 显示全部楼层
哈 万分感谢


可能还有些问题需要请教斑竹您  等我详细阅读完这段代码后

再发信告诉您

希望您不吝赐教
回复

使用道具 举报

发表于 2006-4-18 16:11:16 | 显示全部楼层
这个  怎么编译?
回复

使用道具 举报

发表于 2006-4-18 17:53:48 | 显示全部楼层
gcc test.c -o test -I/usr/X11R6/include/ -L/usr/X11R6/lib -lX11 -lXext
缺什么库就加上
回复

使用道具 举报

发表于 2006-4-18 18:59:45 | 显示全部楼层
回复

使用道具 举报

发表于 2009-4-24 09:22:29 | 显示全部楼层
请教mozilla,为什么我播放出来的图像是绿色的?
还有XV怎么跟GTK联系起来?
回复

使用道具 举报

发表于 2009-4-28 16:56:42 | 显示全部楼层
真可怜啊,没有人救我啊~~~~~~
回复

使用道具 举报

发表于 2009-4-28 18:18:06 | 显示全部楼层
你顶老贴,当然没人帮你。
回复

使用道具 举报

发表于 2009-4-29 09:42:41 | 显示全部楼层
帖子老,但问题多啊~~~~
回复

使用道具 举报

发表于 2009-6-12 20:10:55 | 显示全部楼层
千年老帖都被顶上来了。
好长时间没来这里了,呵呵。

gdk有接口可以拿到窗口句柄,具体看看gdkx.h这个头文件吧,已经很长时间没摸这玩意了。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

GMT+8, 2024-4-25 06:40 , Processed in 0.114307 second(s), 15 queries .

© 2021 Powered by Discuz! X3.5.

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