corrected function for detecting external edges
This commit is contained in:
parent
bb5083d419
commit
5abc80aced
@ -81,7 +81,6 @@ def annotate_image(image, stats):
|
|||||||
|
|
||||||
def find_and_close_edges(img_bin_final):
|
def find_and_close_edges(img_bin_final):
|
||||||
contours, hierarchy = cv2.findContours(img_bin_final, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
|
contours, hierarchy = cv2.findContours(img_bin_final, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
|
||||||
# contoured_img = cv2.drawContours(img_bin_final,contours, -1,(255,255,255),2)
|
|
||||||
for cnt in contours:
|
for cnt in contours:
|
||||||
missing_external_edges = True
|
missing_external_edges = True
|
||||||
left = tuple(cnt[cnt[:, :, 0].argmin()][0])
|
left = tuple(cnt[cnt[:, :, 0].argmin()][0])
|
||||||
@ -89,15 +88,18 @@ def find_and_close_edges(img_bin_final):
|
|||||||
top = tuple(cnt[cnt[:, :, 1].argmin()][0])
|
top = tuple(cnt[cnt[:, :, 1].argmin()][0])
|
||||||
bottom = tuple(cnt[cnt[:, :, 1].argmax()][0])
|
bottom = tuple(cnt[cnt[:, :, 1].argmax()][0])
|
||||||
topleft = [left[0] + 1, top[1]]
|
topleft = [left[0] + 1, top[1]]
|
||||||
|
# print(cnt, left, top, topleft)
|
||||||
bottomright = [right[0] - 1, bottom[1]]
|
bottomright = [right[0] - 1, bottom[1]]
|
||||||
|
|
||||||
for arr in cnt:
|
for arr in cnt:
|
||||||
if np.array_equal(arr, np.array([bottomright])) or np.array_equal(arr, np.array([topleft])):
|
if np.array_equal(arr, np.array([bottomright])) or np.array_equal(arr, np.array([topleft])):
|
||||||
missing_external_edges = False
|
missing_external_edges = False
|
||||||
break
|
break
|
||||||
|
|
||||||
if missing_external_edges:
|
if missing_external_edges and (bottomright[0]-topleft[0])*(bottomright[1]-topleft[1])>= 50000:
|
||||||
|
topleft[0] -= 1
|
||||||
|
bottomright[0] += 1
|
||||||
cv2.rectangle(img_bin_final, tuple(topleft), tuple(bottomright), (255,255,255) , 2)
|
cv2.rectangle(img_bin_final, tuple(topleft), tuple(bottomright), (255,255,255) , 2)
|
||||||
|
print("missing cell detectet rectangle drawn")
|
||||||
|
|
||||||
return img_bin_final
|
return img_bin_final
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user