找回密码
 注册
搜索
查看: 1458|回复: 8

[讨论] sensor图象出现光栅/网格

[复制链接]
发表于 2010-4-19 16:55:03 | 显示全部楼层 |阅读模式
大家好, 我现在用Qt做了一个MT9J001(美光的sensor)的上位机, 将抓到的数据显示在屏幕上,出现了一个问题, 当窗口的大小比sensor的resolution小的时候, 会出现红色的光栅/网格。 scale用的是QImage::scale, 也试过开源的CImg来做, 问题也是一样, 用OV的OV5620也是同样的问题,不显示,直接转换RGB后scale存bmp也是这个问题,原始大小则没有问题(或者是不明显看不出来), 所以我想问题可能出在sensor的配置, 或者是我Raw data转RGB的算法上, 大家帮忙看下。

<img src="attachments/dvbbs/2010-4/201041916543273499.jpg" border="0" onclick="zoom(this)" onload="if(this.width>document.body.clientWidth*0.5) {this.resized=true;this.width=document.body.clientWidth*0.5;this.style.cursor='pointer';} else {this.onclick=null}" alt="" />
 楼主| 发表于 2010-4-19 16:56:01 | 显示全部楼层
这是Raw 转RGB的算法

int Bayer_GRBG_To_RGB888(const uint8_t *src, uint8_t *dst, int width, int height)
{
        assert(src != NULL);
        assert(dst != NULL);

        const uint8_t *pSrcRow = src;
        uint8_t *pDstRow = dst;
        const uint8_t *pSrcRowNext = 0;
        const uint8_t *pSrcRowPrev = 0;
        long nSrcBytesPerRow = 1 * width;
        long nDstBytesPerRow  = 3 * width;
        long nSrcWidth = width;
        long nSrcHeight = height;

        for (long nRow=0; nRow < nSrcHeight; nRow++) {
                pSrcRowNext = pSrcRow + nSrcBytesPerRow;
                if (nRow == 0) pSrcRowPrev = pSrcRowNext;
                else pSrcRowPrev = pSrcRow - nSrcBytesPerRow;

                if (nRow == nSrcHeight-1) pSrcRowNext = pSrcRowPrev;

                for (long nCol = 0, k = 0; nCol < nSrcWidth; nCol++,k += 3) {
                        long nColNext = nCol + 1;
                        long nColPrev = nCol - 1;
                        if (nCol == 0) nColPrev = nColNext;
                        if (nCol == nSrcWidth-1) nColNext = nColPrev;

                        if ((nRow % 2) == 0) {        // even row
                                if ((nCol % 2) == 0) {  // even column, Raw Green
                                        pDstRow[k] = ((long)pSrcRow[nColNext] + pSrcRow[nColPrev]) / 2;        // Red
                                        pDstRow[k + 1] = pSrcRow[nCol];        // green
                                        pDstRow[k + 2] = ((long)pSrcRowNext[nCol] + pSrcRowPrev[nCol]) / 2;        // blue
                                } else {  // odd column, Raw Red
                                        pDstRow[k] = pSrcRow[nCol];        // Red
                                        pDstRow[k + 1] = ((long)pSrcRow[nColPrev] + pSrcRow[nColNext] + pSrcRowNext[nCol] + pSrcRowPrev[nCol]) / 4;        // Green
                                        pDstRow[k + 2] = ((long)pSrcRowNext[nColNext] + pSrcRowNext[nColPrev] + pSrcRowPrev[nColNext] + pSrcRowPrev[nColPrev]) / 4;        // blue
                                }
                        } else { // odd row
                                if ((nCol % 2) == 0) { // even column, Raw Blue
                                        pDstRow[k] = ((long)pSrcRowNext[nColNext] + pSrcRowNext[nColPrev] + pSrcRowPrev[nColNext] + pSrcRowPrev[nColPrev]) / 4;        // Red
                                        pDstRow[k + 1] = ((long)pSrcRow[nColPrev] + pSrcRow[nColNext] + pSrcRowNext[nCol] + pSrcRowPrev[nCol]) / 4;        // Green
                                        pDstRow[k + 2] = pSrcRow[nCol];        // blue
                                } else {  // odd column, Raw Green
                                        pDstRow[k] = ((long)pSrcRowNext[nCol] + pSrcRowPrev[nCol]) / 2;        // Red
                                        pDstRow[k + 1] = pSrcRow[nCol];        // Green
                                        pDstRow[k + 2] = ((long)pSrcRow[nColNext] + pSrcRow[nColPrev]) / 2;        // blue
                                }
                        }
                }

                pSrcRow += nSrcBytesPerRow;
                pDstRow += nDstBytesPerRow;
        }

        return 0;
}
点评回复

使用道具 举报

发表于 2010-4-20 13:41:07 | 显示全部楼层
我也 碰见过同样的问题, 后来我觉得是 图象被窗口压缩了,出现显示网格状,应该不是 转RGB 问题,存BMP照片没问题的啊,应该是显示出来才有。
点评回复

使用道具 举报

 楼主| 发表于 2010-4-20 13:52:20 | 显示全部楼层
以下是引用angel19840920在2010-4-20 13:41:07的发言:
我也 碰见过同样的问题, 后来我觉得是 图象被窗口压缩了,出现显示网格状,应该不是 转RGB 问题,存BMP照片没问题的啊,应该是显示出来才有。


我存成BMP也是同样的问题, 按原始大小存没问题, scale后再存也是一样的问题!
点评回复

使用道具 举报

 楼主| 发表于 2010-4-20 15:16:15 | 显示全部楼层
这里有一种方法可以。。开源的dc1394..

/* this is the method used inside AVT cameras. See AVT docs. */
dc1394error_t
dc1394_bayer_Simple(const uint8_t *restrict bayer, uint8_t *restrict rgb, int sx, int sy, int tile)
{
    const int bayerStep = sx;
    const int rgbStep = 3 * sx;
    int width = sx;
    int height = sy;
    int blue = tile == DC1394_COLOR_FILTER_BGGR
        || tile == DC1394_COLOR_FILTER_GBRG ? -1 : 1;
    int start_with_green = tile == DC1394_COLOR_FILTER_GBRG
        || tile == DC1394_COLOR_FILTER_GRBG;
    int i, imax, iinc;

    if ((tile>DC1394_COLOR_FILTER_MAX)||(tile<DC1394_COLOR_FILTER_MIN))
      return DC1394_INVALID_COLOR_FILTER;

    /* add black border */
    imax = sx * sy * 3;
    for (i = sx * (sy - 1) * 3; i < imax; i++) {
        rgb = 0;
    }
    iinc = (sx - 1) * 3;
    for (i = (sx - 1) * 3; i < imax; i += iinc) {
        rgb[i++] = 0;
        rgb[i++] = 0;
        rgb[i++] = 0;
    }

    rgb += 1;
    width -= 1;
    height -= 1;

    for (; height--; bayer += bayerStep, rgb += rgbStep) {
        const uint8_t *bayerEnd = bayer + width;

        if (start_with_green) {
            rgb[-blue] = bayer[1];
            rgb[0] = (bayer[0] + bayer[bayerStep + 1] + 1) >> 1;
            rgb[blue] = bayer[bayerStep];
            bayer++;
            rgb += 3;
        }

        if (blue > 0) {
            for (; bayer <= bayerEnd - 2; bayer += 2, rgb += 6) {
                rgb[-1] = bayer[0];
                rgb[0] = (bayer[1] + bayer[bayerStep] + 1) >> 1;
                rgb[1] = bayer[bayerStep + 1];

                rgb[2] = bayer[2];
                rgb[3] = (bayer[1] + bayer[bayerStep + 2] + 1) >> 1;
                rgb[4] = bayer[bayerStep + 1];
            }
        } else {
            for (; bayer <= bayerEnd - 2; bayer += 2, rgb += 6) {
                rgb[1] = bayer[0];
                rgb[0] = (bayer[1] + bayer[bayerStep] + 1) >> 1;
                rgb[-1] = bayer[bayerStep + 1];

                rgb[4] = bayer[2];
                rgb[3] = (bayer[1] + bayer[bayerStep + 2] + 1) >> 1;
                rgb[2] = bayer[bayerStep + 1];
            }
        }

        if (bayer < bayerEnd) {
            rgb[-blue] = bayer[0];
            rgb[0] = (bayer[1] + bayer[bayerStep] + 1) >> 1;
            rgb[blue] = bayer[bayerStep + 1];
            bayer++;
            rgb += 3;
        }

        bayer -= width;
        rgb -= width * 3;

        blue = -blue;
        start_with_green = !start_with_green;
    }

    return DC1394_SUCCESS;

}
点评回复

使用道具 举报

 楼主| 发表于 2010-4-20 15:16:45 | 显示全部楼层
其他标准的方法都不行。。不知道为什么。。
点评回复

使用道具 举报

发表于 2010-4-28 11:14:50 | 显示全部楼层
那这么说 就是BAYER 转RGB 算法 引起的?
点评回复

使用道具 举报

发表于 2010-4-30 11:41:49 | 显示全部楼层
不懂,帮顶一下
但还是学习了,正在做摄像头调试
点评回复

使用道具 举报

发表于 2010-8-20 15:32:23 | 显示全部楼层
学习了……
点评回复

使用道具 举报

高级模式
B Color Image Link Quote Code Smilies

本版积分规则

Archiver|手机版|小黑屋|52RD我爱研发网 ( 沪ICP备2022007804号-2 )

GMT+8, 2024-10-4 12:26 , Processed in 0.072278 second(s), 18 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

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