Ask Your Question
0

Detecting Blue Color in this image

asked 2016-03-13 09:08:30 -0600

arp1561 gravatar image

This image was taken from a Quad-Copter. I need to detect the blue color that the guy in this picture is wearing.

It would be very helpful if you guys would try to guide me. I am also attaching the code that i used. The hsv range never seems to be correct.

import cv2
import numpy as np
from matplotlib import pyplot as plt

frame = cv2.imread("a.jpeg")
img = frame
hsv = cv2.cvtColor(img,cv2.COLOR_BGR2HSV)
lower_blue= np.array([78,158,124])
upper_blue = np.array([138,255,255])

mask = cv2.inRange(img,lower_blue,upper_blue)

img,cnts,hie = cv2.findContours(mask,cv2.RETR_TREE,cv2.CHAIN_APPROX_NONE)
cv2.drawContours(frame,cnts,-1,(0,255,0),3)

cv2.imshow("Frame",frame)
cv2.waitKey(0)

The image

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
0

answered 2016-03-13 10:37:40 -0600

gseif gravatar image

Have you tried using the RGB colour space? If you have the image in RGB then only look at channel 3 of the image. Then you would say, if the blue component is greater than a certain threshold then we have detected a blue colour. Anything less than the threshold and its probably a mix of colours.

mask = cv2.inRange(img, lower_magnitude_threshold, 255);

Hope this helps!

edit flag offensive delete link more

Comments

OpenCV uses BGR not RGB

sturkmen gravatar imagesturkmen ( 2016-03-13 11:20:41 -0600 )edit
0

answered 2017-04-25 12:45:51 -0600

electron gravatar image

I know it's too late, but this range works well for me:

lower_blue = np.array([100,150,0])
upper_blue = np.array([140,255,255])
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2016-03-13 09:08:30 -0600

Seen: 23,505 times

Last updated: Apr 25 '17