@@ -77,8 +77,7 @@ def getOrientation(frame, config):
7777 th_val = 1
7878
7979 ret , binary_img = cv2 .threshold (frame , th_val , 255 , cv2 .THRESH_BINARY )
80-
81- contours , hierarchy = cv2 .findContours (binary_img , cv2 .RETR_EXTERNAL , cv2 .CHAIN_APPROX_NONE )[- 2 :]
80+ contours , hierarchy = cv2 .findContours (binary_img , cv2 .RETR_EXTERNAL , cv2 .CHAIN_APPROX_NONE )[- 2 :]
8281
8382
8483 # Sort contours by area
@@ -133,9 +132,9 @@ def _get_range(l):
133132 # Find rotation angle again, this time only using the head half
134133
135134
136- contours , hierarchy = cv2 .findContours (head_half .copy (), cv2 .RETR_EXTERNAL , cv2 .CHAIN_APPROX_NONE )[- 2 :]
137- contours .sort (key = lambda ar : ar .size )
138- largest_contour = contours [- 1 ]
135+ contours , hierarchy = cv2 .findContours (head_half .copy (), cv2 .RETR_EXTERNAL , cv2 .CHAIN_APPROX_NONE )[- 2 :]
136+ contours .sort (key = lambda ar : ar .size )
137+ largest_contour = contours [- 1 ]
139138
140139
141140 [vx , vy , x , y ] = cv2 .fitLine (largest_contour , cv2 .DIST_L2 , 0 , 0.01 , 0.01 )
@@ -177,9 +176,9 @@ def getHeadMask(frame):
177176 head_mask = np .zeros ((img_thresh .shape [0 ], img_thresh .shape [1 ]), np .uint8 )
178177
179178
180- contours , hierarchy = cv2 .findContours (img_thresh , cv2 .RETR_EXTERNAL , cv2 .CHAIN_APPROX_NONE )[- 2 :]
181- contours .sort (key = lambda ar : ar .size )
182- head_contour = contours [- 1 ]
179+ contours , hierarchy = cv2 .findContours (img_thresh , cv2 .RETR_EXTERNAL , cv2 .CHAIN_APPROX_NONE )[- 2 :]
180+ contours .sort (key = lambda ar : ar .size )
181+ head_contour = contours [- 1 ]
183182
184183
185184 cv2 .drawContours (head_mask , [head_contour ], 0 , 255 , cv2 .FILLED )
@@ -192,11 +191,11 @@ def getHeadPoint(rotated_img, angle):
192191 theta = math .radians (- angle )
193192
194193
195- img_binary = np .zeros (rotated_img .shape , np .uint8 )
196- contours , hierarchy = cv2 .findContours (rotated_img .copy (), cv2 .RETR_EXTERNAL , cv2 .CHAIN_APPROX_NONE )[- 2 :]
197- contours .sort (key = lambda ar : ar .size )
198- largest_contour = contours [- 1 ]
199- cv2 .drawContours (img_binary , [largest_contour ], 0 , 255 , cv2 .FILLED )
194+ img_binary = np .zeros (rotated_img .shape , np .uint8 )
195+ contours , hierarchy = cv2 .findContours (rotated_img .copy (), cv2 .RETR_EXTERNAL , cv2 .CHAIN_APPROX_NONE )[- 2 :]
196+ contours .sort (key = lambda ar : ar .size )
197+ largest_contour = contours [- 1 ]
198+ cv2 .drawContours (img_binary , [largest_contour ], 0 , 255 , cv2 .FILLED )
200199
201200
202201 valid_pixels = np .nonzero (img_binary )
@@ -225,8 +224,8 @@ def getTailStartPoint(head_mask, head_point, config):
225224 # Calculate the angle from the head point to the contour center
226225 # Then, 'walk' down the line from the head point to the contour center point a set length
227226
228- contours , hierarchy = cv2 .findContours (head_mask .copy (), cv2 .RETR_EXTERNAL , cv2 .CHAIN_APPROX_NONE )[- 2 :]
229- contour = contours [- 1 ]
227+ contours , hierarchy = cv2 .findContours (head_mask .copy (), cv2 .RETR_EXTERNAL , cv2 .CHAIN_APPROX_NONE )[- 2 :]
228+ contour = contours [- 1 ]
230229
231230
232231 # Get contour center
@@ -504,7 +503,7 @@ def getZebrafishMask(frame, config):
504503
505504 worm_mask = cleaned_mask .copy ()
506505
507- contours , hierarchy = cv2 .findContours (cleaned_mask .copy (), cv2 .RETR_EXTERNAL , cv2 .CHAIN_APPROX_NONE )[- 2 :]
506+ contours , hierarchy = cv2 .findContours (cleaned_mask .copy (), cv2 .RETR_EXTERNAL , cv2 .CHAIN_APPROX_NONE )[- 2 :]
508507
509508
510509
0 commit comments