Detection of rust with OpenCV (Python) Part 2
This is a follow up to the previous post: Detection of rust with OpenCV (Python)
Original Image: Rust Image
After reading through the comments on the previous post, we tried working in HSV instead of BGR. However, there wasn't too much of a difference.
This is our current code with reference from here: Colour Detection HSV
import cv2
import numpy as np
img = cv2.imread('/home/brendanloe/img.jpeg', 1)
hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
boundaries1 = [ ([169, 100 , 100], [189, 255, 255]) ]
boundaries2 = [ ([3, 100, 100], [17, 255, 255]) ]
boundaries3 = [ ([2, 100, 100], [22, 255, 255]) ]
boundaries4 = [ ([6, 100, 100], [26, 255, 255]) ]
for (lower1, upper1) in boundaries1:
lower1 = np.array(lower1, dtype = "uint8")
upper1 = np.array(upper1, dtype = "uint8")
mask = cv2.inRange(hsv, lower1, upper1)
output1 = cv2.bitwise_and(img, img, mask = mask)
for (lower2, upper2) in boundaries2:
lower2 = np.array(lower2, dtype = "uint8")
upper2 = np.array(upper2, dtype = "uint8")
mask = cv2.inRange(hsv, lower2, upper2)
output2 = cv2.bitwise_and(img, img, mask = mask)
for (lower3, upper3) in boundaries3:
lower3 = np.array(lower3, dtype = "uint8")
upper3 = np.array(upper3, dtype = "uint8")
mask = cv2.inRange(hsv, lower3, upper3)
output3 = cv2.bitwise_and(img, img, mask = mask)
for (lower4, upper4) in boundaries4:
lower4 = np.array(lower4, dtype = "uint8")
upper4 = np.array(upper4, dtype = "uint8")
mask = cv2.inRange(hsv, lower4, upper4)
output4 = cv2.bitwise_and(img, img, mask = mask)
final = cv2.bitwise_or(output1, output2, output3)
final1 = cv2.bitwise_or(output4, final)
cv2.imshow("final", final1)
while(1):
k = cv2.waitKey(0)
if(k == 27):
break
cv2.destroyAllWindows()
How can we remove the yellow colour "parking" sign which is still showing in our output? Is it because we are using a jpeg image?
please add the original, bgr image so folks here can try your (and alternative) ideas
Hi, I have added the original image if that is what you were asking for.
it is, thank you ;)
It seems that the rust is a dark red, and the parking sign is yellow-green. Can you use that difference in their properties as a way to exclude the sign?