0

I want to check some Numbers for a color recognition. I'm new to python so please do not judge me.

thresholdR = 50
thresholdG = 50
thresholdB = 50
middleValue = [225,165, 25]
    
lowerBound = [middleValue - thresholdR/2,middleValue - thresholdG/2,middleValue - thresholdB/2]
upperBound = [middleValue +  thresholdR/2,middleValue + thresholdG/2,greenMiddle + thresholdB/2]

When I try to run this I get the error:

TypeError: unsupported operand type(s) for -: 'list' and 'float'

I don't know how to fix this I would be so pleased if you could help me!

5
  • 3
    middleValue is a list. You can't subtract a value from it. Do you want to calculate those lower/upper bounds for every element of middleValue? Commented Apr 28, 2021 at 14:00
  • 2
    Did you mean: middleValue[0] - thresholdR/2 to mean red value - threshold/2? Commented Apr 28, 2021 at 14:01
  • @kuro yes thats right so I would have to use middleValue[0], middleValue[1] and middleValue[2] ? Commented Apr 28, 2021 at 14:01
  • @MrSpoony, yes. Does that solve your problem? Commented Apr 28, 2021 at 14:02
  • @kuro Yes It solves it! Thank you Commented Apr 28, 2021 at 14:05

2 Answers 2

1

You can not just substract a integer from a list. Maybe u mean this

lowerBound = [middleValue[1] - thresholdR/2,middleValue[2] - thresholdG/2,middleValue[3] - thresholdB/2]
upperBound = [middleValue[1] +  thresholdR/2,middleValue[2] + thresholdG/2,middleValue[3] + thresholdB/2]
Sign up to request clarification or add additional context in comments.

Comments

0

You need to add array indexers to your middleValue references.

lowerBound = [middleValue[0] - thresholdR/2,middleValue[1] - thresholdG/2,middleValue[2] - thresholdB/2]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.