搜索
bottom↓
回复: 4

征集路人一起围观 mini2440 的CMOS摄像头测试代码

[复制链接]

出0入0汤圆

发表于 2010-3-30 00:54:05 | 显示全部楼层 |阅读模式
征集路人一起围观 mini2440 的CMOS摄像头测试代码。

传说这段代码效率不高,速度不高。

有研究过的发表点意见啊

本文件源于mini2440的光盘ourdev_542332.rar(文件大小:2K) (原文件名:camtest.rar)

不明白里面为什么是这些东西,其他的都是c的,偏偏这个是cpp的,还有很多不认识的符号


%:include <iostream>
%:include <fcntl.h>
%:include <sys/ioctl.h>
%:include <sys/types.h>
%:include <sys/stat.h>
%:include <sys/mman.h>
%:include <unistd.h>
%:include <string.h>
%:include <stdlib.h>
%:include <string.h>
%:include <linux/types.h>
%:include <linux/fb.h>


class TError <%
public:
        TError(const char *msg) <%
                this->msg = msg;
        %>
        TError(const TError bitand e) <%
                msg = e.msg;
        %>
        void Output() <%
                std::cerr << msg << std::endl;
        %>
        virtual ~TError() <%%>
protected:
        TError bitand operator=(const TError bitand);
private:
        const char *msg;
%>;

// Linear memory based image
class TRect <%
public:
        TRect():  Addr(0), Size(0), Width(0), Height(0), LineLen(0), BPP(16) <%
        %>
        virtual ~TRect() <%
        %>
        bool DrawRect(const TRect bitand SrcRect, int x, int y) const <%
                if (BPP not_eq 16 or SrcRect.BPP not_eq 16) <%
                        // don't support that yet
                        throw TError("does not support other than 16 BPP yet");
                %>

                // clip
                int x0, y0, x1, y1;
                x0 = x;
                y0 = y;
                x1 = x0 + SrcRect.Width - 1;
                y1 = y0 + SrcRect.Height - 1;
                if (x0 < 0) <%
                        x0 = 0;
                %>
                if (x0 > Width - 1) <%
                        return true;
                %>
                if( x1 < 0) <%
                        return true;
                %>
                if (x1 > Width - 1) <%
                        x1 = Width - 1;
                %>
                if (y0 < 0) <%
                        y0 = 0;
                %>
                if (y0 > Height - 1) <%
                        return true;
                %>
                if (y1 < 0) <%
                        return true;
                %>
                if (y1 > Height - 1) <%
                        y1 = Height -1;
                %>

                //copy
                int copyLineLen = (x1 + 1 - x0) * BPP / 8;
                unsigned char *DstPtr = Addr + LineLen * y0 + x0 * BPP / 8;
                const unsigned char *SrcPtr = SrcRect.Addr + SrcRect.LineLen *(y0 - y) + (x0 - x) * SrcRect.BPP / 8;

                for (int i = y0; i <= y1; i++) <%
                        memcpy(DstPtr, SrcPtr, copyLineLen);
                        DstPtr += LineLen;
                        SrcPtr += SrcRect.LineLen;
                %>
               
               
                return true;
        %>

        bool DrawRect(const TRect bitand rect) const <% // default is Center
                return DrawRect(rect, (Width - rect.Width) / 2, (Height - rect.Height) / 2);
        %>

        bool Clear() const <%
                int i;
                unsigned char *ptr;
                for (i = 0, ptr = Addr; i < Height; i++, ptr += LineLen) <%
                        memset(ptr, 0, Width * BPP / 8);
                %>
                return true;
        %>

protected:
        TRect(const TRect bitand);
        TRect bitand operator=( const TRect bitand);

protected:
        unsigned char *Addr;
        int Size;
        int Width, Height, LineLen;
        unsigned BPP;
%>;



class TFrameBuffer: public TRect <%
public:
        TFrameBuffer(const char *DeviceName = "/dev/fb0"): TRect(), fd(-1) <%
                Addr = (unsigned char *)MAP_FAILED;

                fd = open(DeviceName, O_RDWR);
                if (fd < 0) <%
                        throw TError("cannot open frame buffer");
                %>

                struct fb_fix_screeninfo Fix;
                struct fb_var_screeninfo Var;
                if (ioctl(fd, FBIOGET_FSCREENINFO, bitand Fix) < 0 or ioctl(fd, FBIOGET_VSCREENINFO, bitand Var) < 0) <%
                        throw TError("cannot get frame buffer information");
                %>

                BPP = Var.bits_per_pixel;
                if (BPP not_eq 16) <%
                        throw TError("support 16BPP frame buffer only");
                %>

                Width  = Var.xres;
                Height = Var.yres;
                LineLen = Fix.line_length;
                      Size = LineLen * Height;

                int PageSize = getpagesize();
                Size = (Size + PageSize - 1) / PageSize * PageSize ;
                Addr = (unsigned char *)mmap(NULL, Size, PROT_READ|PROT_WRITE,MAP_SHARED, fd, 0);
                if (Addr == (unsigned char *)MAP_FAILED) <%
                        throw TError("map frame buffer failed");
                        return;
                %>
                ::close(fd);
                fd = -1;

                Clear();
        %>

        virtual ~TFrameBuffer() <%
                ::munmap(Addr, Size);
                Addr = (unsigned char *)MAP_FAILED;

                ::close(fd);
                fd = -1;
        %>

protected:
        TFrameBuffer(const TFrameBuffer bitand);
        TFrameBuffer bitand operator=( const TFrameBuffer bitand);
private:
        int fd;
%>;

class TVideo : public TRect <%
public:
        TVideo(const char *DeviceName = "/dev/camera"): TRect(), fd(-1) <%
                Addr = 0;
                fd = ::open(DeviceName, O_RDONLY);
                if (fd < 0) <%
                        throw TError("cannot open video device");
                %>
                Width = 640;
                Height = 512;
                BPP = 16;
                LineLen = Width * BPP / 8;
                Size = LineLen * Height;
                Addr = new unsigned char<:Size:>;

                Clear();
        %>

        bool FetchPicture() const <%
                int count = ::read(fd, Addr, Size);
                if (count not_eq Size) <%
                        throw TError("error in fetching picture from video");
                %>
                return true;
        %>

        virtual ~TVideo() <%
                ::close(fd);
                fd = -1;
                delete<::> Addr;
                Addr = 0;
        %>

protected:
        TVideo(const TVideo bitand);
        TVideo bitand operator=(const TVideo bitand);

private:
        int fd;
%>;

int main(int argc, char **argv)
<%
        try <%
                TFrameBuffer FrameBuffer;
                TVideo Video;
                for (;;) <%
                        Video.FetchPicture();
                        FrameBuffer.DrawRect(Video);
                %>
        %> catch (TError bitand e) <%
                e.Output();
                return 1;
        %>

        return 0;
%>

阿莫论坛20周年了!感谢大家的支持与爱护!!

曾经有一段真挚的爱情摆在我的面前,我没有珍惜,现在想起来,还好我没有珍惜……

出0入0汤圆

发表于 2010-3-30 08:39:46 | 显示全部楼层
呃......楼主要有东西,路人才能围观啊 - -b

出0入0汤圆

发表于 2010-3-30 08:47:34 | 显示全部楼层
是呀。有东西才能围观

出0入0汤圆

发表于 2010-3-30 12:32:17 | 显示全部楼层
wo 我也来围观

出0入0汤圆

发表于 2014-4-29 21:18:31 | 显示全部楼层
不知楼主  测试成功没有   我测试的时候  报错error in fetching picture from video
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片。注意:要连续压缩2次才能满足要求!!】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-8-25 21:19

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

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