@@ -55,20 +55,20 @@ def find_orange_ring_pipeline(frame):
5555 # Value: Anything above 30 is bright enough
5656 lower_bound = (15 , 50 , 30 )
5757 upper_bound = (25 , 255 , 255 )
58- inRange = cv .inRange (hsv , lower_bound , upper_bound )
58+ in_range = cv .inRange (hsv , lower_bound , upper_bound )
5959
6060 # Noise in the image often causes `cv.inRange()` to return false positives
6161 # and false negatives, meaning there are some incorrect pixels in the binary
6262 # image. These can be cleaned up with morphological operations, which
6363 # effectively grow and shrink regions in the binary image to remove tiny
6464 # blobs of noise
6565 kernel = cv .getStructuringElement (cv .MORPH_RECT , (3 , 3 ))
66- morphOpen = cv .morphologyEx (inRange , cv .MORPH_OPEN , kernel )
67- morphClose = cv .morphologyEx (morphOpen , cv .MORPH_CLOSE , kernel )
66+ morph_open = cv .morphologyEx (in_range , cv .MORPH_OPEN , kernel )
67+ morph_close = cv .morphologyEx (morph_open , cv .MORPH_CLOSE , kernel )
6868
6969 # Now we use `cv.findContours()` to find the contours in the binary image,
7070 # which are the boundaries of the regions in the binary image
71- contours , hierarchy = cv .findContours (morphClose , cv .RETR_EXTERNAL , cv .CHAIN_APPROX_SIMPLE )
71+ contours , hierarchy = cv .findContours (morph_close , cv .RETR_EXTERNAL , cv .CHAIN_APPROX_SIMPLE )
7272
7373 # It's possible that no contours were found, so first check if any were
7474 # found before proceeding
@@ -91,7 +91,7 @@ def find_orange_ring_pipeline(frame):
9191
9292 # If no contour was found, return invalid values to indicate that
9393 if best_contour is None :
94- return ( - 1 , - 1 )
94+ return - 1 , - 1
9595
9696 # Calculate the bounding rectangle of the contour, and use that to calculate
9797 # the center coordinates of the ring
@@ -141,7 +141,7 @@ def find_orange_ring_pipeline(frame):
141141
142142 # Now we can return the distance and position of the ring in cm, since
143143 # that's the only data we need from this pipeline
144- return ( distance_cm , position_x_cm )
144+ return distance_cm , position_x_cm
145145
146146# Move the servo out of the way of the camera
147147servo_one .set_angle (90 )
@@ -157,7 +157,7 @@ def find_orange_ring_pipeline(frame):
157157while True :
158158 # Read a frame from the camera
159159 success , frame = camera .read ()
160- if success == False :
160+ if not success :
161161 print ("Error reading frame from camera" )
162162 break
163163
0 commit comments