0% found this document useful (0 votes)
43 views1 page

Detecting Objects with MinEnclosingCircle

The document contains a Python script that uses OpenCV to capture video from a camera and detect a specific color range defined by navLower and navUpper. It processes the video frames to identify contours, calculate their centers and radii, and provides directional feedback based on the position and size of the detected object. The script runs in a loop until the user presses 'q' to quit.

Uploaded by

dspssmp
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views1 page

Detecting Objects with MinEnclosingCircle

The document contains a Python script that uses OpenCV to capture video from a camera and detect a specific color range defined by navLower and navUpper. It processes the video frames to identify contours, calculate their centers and radii, and provides directional feedback based on the position and size of the detected object. The script runs in a loop until the user presses 'q' to quit.

Uploaded by

dspssmp
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

import imutils

import cv2
navLower = (80, 64, 67)
navUpper = (175, 255, 255)
camera=[Link](0)

while True:

_,frame = [Link]()
frame=[Link](frame,width=600)
blurred = [Link](frame, (11, 11), 0)
hsv = [Link](blurred, cv2.COLOR_BGR2HSV)

mask = [Link](hsv, navLower, navUpper)


mask = [Link](mask, None, iterations=2)
mask = [Link](mask, None, iterations=2)

cnts = [Link]([Link](), cv2.RETR_EXTERNAL,


cv2.CHAIN_APPROX_SIMPLE)[-2]
center = None
if len(cnts) > 0:
c = max(cnts, key=[Link])
((x, y), radius) = [Link](c)
M = [Link](c)
center = (int(M["m10"] / M["m00"]), int(M["m01"] / M["m00"]))
if radius > 10:
[Link](frame, (int(x), int(y)), int(radius),
(0, 255, 255), 2)
[Link](frame, center, 5, (0, 0, 255), -1)
print(center,radius)
if radius > 250:
print("stop")
else:
if(center[0]<150):
print("Left")
elif(center[0]>450):
print("Right")
elif(radius<250):
print("Front")
else:
print("Stop")
[Link]("Frame", frame)
key = [Link](1) & 0xFF
if key == ord("q"):
break

[Link]()
[Link]()

You might also like