基于OpenMV平台进行开发
灰度图像的RGB分量值都是一样的
程序原理:
将RGB的每一个分量都变为灰度分量的1/3
程序运行结果:
程序代码:
import sensor, image
def rgb2gray(rgbFrame):
grayFrame = rgbFrame
for x in range(0,rgbFrame.width()):
for y in range(0,rgbFrame.height()):
rgb = rgbFrame.get_pixel(x, y)
gray_data = int(image.rgb_to_grayscale(rgb)/3)
gray = (gray_data,gray_data,gray_data)
grayFrame.set_pixel(x,y,gray)
return grayFrame;
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.skip_frames()
while(True):
img = sensor.snapshot()
img = rgb2gray(img);推荐牛人链接:http://www.lowfet.com/