def get_contours(orig_image):
"""
Get edge points (hopefully corners) from the given opencv image (called
contours in opencv)
Parameters:
:param: `orig_image` - the thresholded image from which to find contours
"""
new_image = numpy.copy(orig_image)
# cv2.imshow("Vision", new_image)
# cv2.waitKey(1000)
new_image, contours, hierarchy = cv2.findContours(new_image,
cv2.RETR_EXTERNAL,
cv2.CHAIN_APPROX_SIMPLE)
# print(len(contours))
# print(len(contours[0]))
# print(len(contours[0][0]))
# print(len(contours[0][0][0]))
largest_contour = 0
most_matching = 0
min_score = 0
max_area = 0
if len(contours) > 1:
print("Length of contours:", len(contours))
max_area = cv2.contourArea(contours[0])
min_score = average_goal_matching(contours[0])
for i in range(1, len(contours)):
# print(contours[i])
current_score = average_goal_matching(contours[i])
current_area = cv2.contourArea(contours[i])
if current_area > max_area:
max_area = current_area
largest_contour = i
if current_score < min_score and current_score != 0 and current_area > 300 and current_area < 1500:
min_score = current_score
most_matching = i
elif len(contours) == 0:
raise GoalNotFoundException("Goal not found!")
if min_score >= 9999999999999999:
raise GoalNotFoundException("Goal not found!")
print("largest_contour:", largest_contour)
print("Area:", max_area)
# print("largest_contour:", largest_contour)
print("Most matching:", most_matching)
print("Score:", min_score)
print("Area of most matching:", cv2.contourArea(contours[most_matching]))
rect = cv2.minAreaRect(contours[most_matching])
box = cv2.boxPoints(rect)
box = numpy.int0(box)
# print(box)
return numpy.array(contours[most_matching]), box
vision_processing.py 文件源码
python
阅读 23
收藏 0
点赞 0
评论 0
评论列表
文章目录