2017-01-16 8 views
1
img = cv2.imread('/home/user/Documents/workspace/ImageProcessing/img.JPG'); 
image = cv2.cvtColor(img, cv2.COLOR_BGR2HSV) 

#red, blue, yellow, and gray 
boundaries = [ 
([17, 15, 100], [50, 56, 200]), 
([86, 31, 4], [220, 88, 50]), 
([25, 146, 190], [62, 174, 250]), 
([103, 86, 65], [145, 133, 128])] 


for i, (lower, upper) in enumerate(boundaries): 

    lower = np.array(lower, dtype="uint8") 
    upper = np.array(upper, dtype="uint8") 

    mask = cv2.inRange(image, lower, upper) 
    output = cv2.bitwise_and(image, image, mask=mask) 

    cv2.imwrite(str(i) + 'image.jpg', output) 

イメージから赤、青、黄色、グレーの色を分離しようとしています(別途)。 これまでのところ、「感度」が低いです。 アルゴリズムの一部に小さな色の斑点がありません。 これをキャリブレーションする方法はありますか? ありがとう!Python OpenCV - cv.inRange() "sensitivity"?

編集: 入力画像 input

出力
output1 output2 output3 output4

+0

入力/出力画像を追加することができれば、問題をよりよく理解するのに役立ちます。 – ilke444

答えて

3

inRange機能が内蔵された感度を持ちません。値を比較するだけです。 inRange(x,10,20)はあなたに{10,11、...、20}を与えるだけです。

これを克服する1つの方法は、独自の感度測定値を導入することです。

s = 5 # for example sensitivity=5/256 color values in range [0,255] 

for i, (lower, upper) in enumerate(boundaries): 

    lower = np.array([color-s if color-s>-1 else 0 for color in lower], dtype="uint8") 
    upper = np.array([color+s if color+s<256 else 255 for color in upper], dtype="uint8") 

    mask = cv2.inRange(image, lower, upper) 
    output = cv2.bitwise_and(image, image, mask=mask) 

    cv2.imwrite(str(i) + 'image.jpg', output) 

または、あらかじめ画像を滑らかにして、そのようなノイズの多いピクセルを取り除くことができます。これにより、ピクセル値がお互いに近づくため、境界から外れたものが範囲に近い値を取得する可能性があります。

+0

お返事ありがとうございます! – cmplx96

+0

しかし、私は感度0.01から200までのすべてを試しましたが、それ以上は得られません – cmplx96

+0

感度= 20後はすべて黒です – cmplx96