Ask Your Question
1

Detecting colour under different lighting conditions

asked 2016-05-25 18:07:20 -0500

Agrajag gravatar image

G'day, I'm trying to use simplecv to read a gauge needle, which I have seen some others do, and am having success with the following:

img = Image('gauge.jpg')
img = img.colorDistance(color=(172,89,115)).stretch(0,50).binarize()
blobs = img.findBlobs()
print "Found angle: %d" % blobs[0].angle()

Example image: gauge

I have taped a large piece of coloured paper to the needle as the original is just black and very fine, so I could easily use a different colour/shape/whatever. The problem I'm having is that this gauge is in a place where I can't control the lighting very well. So the RGB colour that I'm using here that works may not work well under slightly different lighting conditions.

Does anyone have any suggestions on how I can improve the detection? Is there something I can do besides using the specific RGB color in colorDistance() ?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2016-06-25 10:20:12 -0500

foska gravatar image

I'm also struggling with a similar problem.So far i figured out to put a piece of colored paper in front of the camera, get the color of the pixel and use it as a reference for brightness/color calibration.This is my code:

from SimpleCV import *
cam = Camera()
bright = 1
while True:
    img = cam.getImage() #grab a frame
    img = img*bright                # multiply the image by the brightness variable

    pixel=img[0,0]                  # reference color
    r,g,b=pixel
    if r < 128 :                    # change the brightness var until its 128
        bright=bright + 0.1         # 0.1 - the speed of change/cycle
    elif r > 128 :
        bright=bright - 0.1         
    img.show()

In your case i guess that img.binarize could also work. Hope this helps.I'm new to simplecv and python so sorry if this isn't an elegant solution.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2016-05-25 18:07:20 -0500

Seen: 793 times

Last updated: Jun 25 '16