0

I used the "In-Range" function in the following code to separate RED colored lines from the image. But it doesn't give the correct output. I'm new to openCV and can anyone suggest me a way to separate the red colored lines. After detecting the red color lines I want to get its coordinates.

import cv2
import numpy as np

img = cv2.imread('masked.jpg')

ORANGE_MIN = np.array([0, 0, 255],np.uint8)
ORANGE_MAX = np.array([0, 0, 255],np.uint8)

hsv_img = cv2.cvtColor(img,cv2.COLOR_RGB2HSV)

frame_threshed = cv2.inRange(hsv_img, ORANGE_MIN, ORANGE_MAX)
cv2.imwrite('inRange.jpg', frame_threshed)

Input Image,

enter image description here

Result generated,

enter image description here

I developed the above code with the aid of the following solution. Here the above solution detects the orange color lid. But when I apply the same code it doesn't give any valued output. Why?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Nine3KiD
  • 473
  • 2
  • 4
  • 20
  • 1
    looks like your images have compression artifacts or fading lines. Instead of only using hue channel, use some min/max thtesholds for saturation and value, top. – Micka Jun 13 '16 at 05:55
  • @Micka Sir,How can I do it?Can you explain further more.I'm completely lost with this code. – Nine3KiD Jun 13 '16 at 06:06
  • ah maybe that's not even necessary... your code looks broken, because MIN and MAX are equal and you are choosing a range in the value channel. Try `ORANGE_MIN = np.array([0, 10, 10],np.uint8)` and `ORANGE_MAX = np.array([15, 255, 200],np.uint8)`. In addition you need a second range at the "end" of the color space, because HUE channel is a circle (that's why red and only red color has 2 ranges). – Micka Jun 13 '16 at 06:22

0 Answers0