0

画像のカラー値 RGB を出力する関数を書きたいと思います。写真は、すべて黄色、または白のいずれかに着色されています。

私が持っているものは次のとおりです。

def findColor():
    pic=takePicture()
    red = 0   
    green = 0
    blue = 0 
    size = getWidth(pic)*getHeight(pic)
    for pix in getPixels(pic):
        r = getRed(pix)
        g = getGreen(pix)
        b = getBlue(pix)
        red = red + r
        green = green + g
        blue = blue + b 
    print(red//size,green//size,blue//size)

または、上記と同様の値を与えるコード:

def findColor():
    pic=takePicture()
    for pix in getPixels(pic):
        r = getRed(pix)
        g = getGreen(pix)
        b = getBlue(pix)
    print(r,g,b)   

これらのコードは、RGB 値を取得する正しい方法ですか? 写真に異なる色が含まれている場合、2番目のコードは正確ではないと思います。

4

2 に答える 2

1

個々のピクセルごとに RGB 値を出力するだけの場合は、インデントを修正すると、2 番目のコード ブロックが機能します。

def findColor():
    pic=takePicture()
    for pix in getPixels(pic):
        r = getRed(pix)
        g = getGreen(pix)
        b = getBlue(pix)
        print(r,g,b) 
于 2014-10-24T19:15:53.993 に答える