I would like to check if a certain color is on a photo and as a result no image output but information to:
Color found: Yes/No
In which area of the photo: Pixelarea or similar.
Background: It is about being able to automatically assign test strips with 6 different values (color codes are displayed to me).
Is this possible with OpenCV?
Are there any examples (Python or C++)?
Thanks,
Peter
I have used this samplecode, but it only shows the result as a image.
# -*- coding: utf-8 -*-
import numpy as np
import cv2
#https://learnopencv.com/install-opencv-on-windows/
#img_path = "d:\_phyton\opencv_color.jpg"
img_path = "d:\_phyton\Teststreifenklein.jpg"
ranges = {
#"red": ([0, 0, 128], [60, 60, 255]), # Blau GrĂĽn Rot
# "yellow": ([0, 190, 210], [128, 255, 255]), # B G R
# many more
# ph Wert
#"F1": ([92, 217, 238], [92, 217, 238]), # B G R
"F1": ([17, 145, 180], [36, 165, 190]), # B G R
# "F2": ([90, 197, 235], [90, 197, 235]), # B G R
# "F3": ([76, 156, 227], [76, 156, 227]), # B G R
# "F4": ([64, 88, 202], [64, 88, 202]), # B G R
# "F5": ([66, 76, 207], [66, 76, 207]), # B G R
# "F6": ([72, 74, 206], [72, 74, 206]), # B G R
}
image = cv2.imread(img_path)
# Alternative
#cam = cv2.VideoCapture(0)
#check, image = cam.read()
x = 0
for key in ranges.keys():
lowerRange = np.array(ranges[key][0], dtype="uint8")
upperRange = np.array(ranges[key][1], dtype="uint8")
mask = cv2.inRange(image, lowerRange, upperRange)
output = cv2.bitwise_and(image, image, mask=mask)
#if x == 0:
# print('output')
# print(mask)
# show the images
cv2.imshow(key, output)
cv2.waitKey(0)
cv2.destroyAllWindows()