Yefei.Blog

个人日记 WIKI

用户工具

站点工具


python:opencv

RGB → BGR 算法好像有问题,不过能使用

def rgb2bgr(im):
    out = StringIO()
    for h in xrange(0, im.height):
        for w in xrange(0, im.width):
            r, g, b = im.getpixel((w, h))
            out.write(chr(r & 0xFF))
            out.write(chr((g >> 8) & 0xFF))
            out.write(chr((b >> 16) & 0xFF))
    return out.getvalue()

numpy 版本,速度是他几百倍

def numpy_rgb2bgr(im):
    return str(numpy.array(im)[:, :, ::-1].copy().data)
python/opencv.txt · 最后更改: 2016/09/14 20:17 由 yefei