Reputation: 15
I'm quite new to OpenCV and CV as a whole. I'm trying to create a state detector that allows me to extract information from the screen in a certain game. This feature pre-processing is almost complete, but up until now I have used colour as the main way of extracting useful information. I wish to capture as to whether this red shield shape is present in the screen:
()
The shield is always shaped like this, but is translucent and so the colour test cannot be applied.
I have not yet tried a solution, as after much searching and learning, for this one problem I'm not sure where to start.
I have an image processedImage
, and would like to extract a simple bool describing whether this shape is present or not.
Any help would be greatly appreciated.
Thanks.
Upvotes: 1
Views: 441
Reputation: 2337
Since you know that the shield is always red, convert the image into HSV and use the hue channel to threshold/hysteresis the image and get the red region
img = cv2.imread(img_path)
hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
m = cv2.split(hsv)
plt.imshow(m[1])
Plotting the Saturation channel here just for visualization purposes. Once you get this, perhaps you can use some sort template matching algorithm to get the location.
Upvotes: 0
Reputation: 5774
I think the best solution would be to detect the edges of the shield image. You can do this through some image processing techniques at:
Perhaps something like:
edges = cv2.Canny(img,100,200) #img is your image
Would work for you, but if using the color image doesn't work you can try converting to greyscale first with something like:
grey = cv2.cvtColor(screen, cv2.COLOR_RGB2GRAY) #screen is your image
And then do the edge detection algorithm. Obviously once you find the shape you would have to define it (likely through tweaking the Canny parameters, or doing some other technique like HoughLines), but to do this it would be helpful first to think about things like
Then craft your algorithm around these assumptions! I think you would want to define a function and have it return True
or return False
and then you can call this to "get a boolean of if the image is present"
Because you're not asking an explicit question I think this answer will be sufficient, but feel free to drop a comment if it needs elaboration! Otherwise, if this answered your question, then to accept it you can click the check mark next to the post :)
Upvotes: 0