Search code examples
pythonopencvnumpycameragaussianblur

Drawing circles around a certain area with opencv


I am working on a code which accesses my camera, turns the output into grayscale, applies a gaussian blur finds the brightest area/pixel and circles it. Everything but the drawing-a-circle-part works fine. The command I am trying to use does nothing for me. Does anybody have an idea? I am working with opencv, python 2.7 and a Windows Computer!

This is the code:

import cv2
import numpy as np

cv2.namedWindow("spot")
cam = cv2.VideoCapture(0)

if cam.isOpened(): 
    rval, frame = cam.read()
else:
    rval = False

while rval:

    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    gray = cv2.GaussianBlur(gray,(21,21), 0)
    (minVal, maxVal, minLoc, maxLoc) = cv2.minMaxLoc(gray)

    cv2.imshow("spot", gray)
    rval, frame = cam.read()
    key = cv2.waitKey(20)

    if key == 27: 
        break
    cv2.destroyWindow("spot")

And this is the line I have been trying to add so far:

cv2.circle(gray, maxLoc, 21, (255, 0, 0), 2)

Solution

  • You are trying to draw a colour circle on gray image , instead you can make the circle on the original colour frame

    cv2.circle(frame, maxLoc, 10, (255, 0, 0) )
    cv2.imshow("spot",frame)