Search code examples
image-processingcolor-detection

Is it possible to circle around the color spot on an image?


I'm doing an Image Processing Project. I'd like to circle around the yellow spot as follow.

My Image

How to know that position? I tried to find the value from image data (list), but I still don't know how to know that position and how to circle it.

Please help me.

Here is my sample code:

import cv2
import numpy as np

cap = cv2.imread("img.jpg")
cap = cv2.resize(cap, (500, 500))

hsv_frame = cv2.cvtColor(cap, cv2.COLOR_BGR2HSV)

# Yellow color
low_yellow = np.array([21, 39, 64])
high_yellow = np.array([40, 255, 255])
yellow_mask = cv2.inRange(hsv_frame, low_yellow, high_yellow)

yellow = cv2.bitwise_and(cap, cap, mask=yellow_mask)

cv2.imshow("Frame", cap)
test = cv2.imshow("Yellow", yellow)
cv2.imwrite("yellowSpot.jpg", yellow)

key = cv2.waitKey(0)

Solution

  • Here is my solution using GRIP and its auto-generated code (it's a great GUI for building image processing functions in a graphical, easy-to-experiment way):

    My image processing "pipeline": Pipeline

    Image processing functions:

    1. Blur (to remove all the little noise spots from the image, and preserve the yellow spot) Blurred_Img

    2. HSV threshold (to only show the YELLOW spot) HSV

    3. Find Blobs (to find the yellow spots and put a CIRCLE around it) Blob

    Here is the link to download the GRIP software

    Here is a link to all my files (including the auto-generated Python image processing pipeline)