У меня там внизу есть этот код. Эта функция требует 2 отдельных щелчков мыши, чтобы запустить ее фактическую функцию. Я хочу заменить этот обратный вызов мыши для двух щелчков мыши по изображению на первые значения x, y ограничивающего прямоугольника, который у меня есть в файле txt (ширину и высоту можно игнорировать). Текстовый файл выглядит следующим образом:
#Textfile:
string ABCDEF(left_x: 268 top_y: 368 width: 12 height: 83)
string ABC (left_x: 399 top_y: 47 width: 33 height: 91)
string ABCDEFGHI (left_x: 501 top_y: 91 width: 40 height: 163)
string AB (left_x: 196 top_y: 332 width: 35 height: 128)
Вы также можете найти код в «manual_path_finder» по адресу https://github.com/m4nh/ariadne
#Code:
def clickCallback(data):
global output_image, clicked_points, active, end_reached
## pyautogui.click(x=100, y=200) # move to 100, 200, then click the left mouse button.
#######################################
# Debug click to check Node Label
#######################################
if len(clicked_points) == 2:
n = ariadne.graph.nearestNode(data[1])
print("CLICKED NODE:", n)
return
#######################################
# Click over tips
#######################################
clicked_points.append(data[1])
print("CLICKED POINTS", clicked_points)
if len(clicked_points) == 1:
return
print("CLICKED POINTS", clicked_points)
#######################################
# Get Current Clicked Node
#######################################
n = ariadne.graph.nearestNode(clicked_points[0])
#######################################
# Starts Multi-Path Finder search
#######################################
multi_path_finder.startSearchInNeighbourhood(
n, depth=overall_predictor.start_depth)
reaches_map = [0] * multi_path_finder.size()
#######################################
# Search main loop
#######################################
active = True
while True:
#######################################
# Debug Draw
#######################################
if args['debug']:
output_image = ariadne.graph.generateBoundaryImage(image, color=boundary_color)
cv2.circle(output_image, tuple(
clicked_points[0]), int(config.get(config_name, 'end_region_radius')), (0, 0, 1), 2)
cv2.circle(output_image, tuple(
clicked_points[1]), int(config.get(config_name, 'end_region_radius')), (0, 0, 1), 2)
if active:
print("ROUND", multi_path_finder.getIterations() + 1, "=" * 50)
#######################################
# Mult-Path Finder Next step
#######################################
multi_path_finder.nextStep()
#######################################
# Fetch scores for each Path
#######################################
scores_raw = multi_path_finder.getScores(single_components=True)
scores = multi_path_finder.getScores(single_components=False)
reaches_counter = 0
for i, f in enumerate(scores):
path_finder = multi_path_finder.path_finders[i]
print("Path ", i, scores_raw[i], scores[i],
"REACHED" if reaches_map[i] > 0 else "")
#######################################
# Debug Draw of current Path
#######################################
if args['debug']:
color = colors[i % len(colors)]
if path_finder.isOpen():
path_finder.path.draw(
output_image, draw_numbers=False, color=color)
last_point = path_finder.path.as2DPoints()[-1]
cv2.putText(output_image, "{}".format(i), tuple(
last_point + np.array([5, 0])), cv2.FONT_HERSHEY_PLAIN, 1.5, (0, 0, 0), 2)
#######################################
# Close condition for current Path
#######################################
if scores[i] < float(config.get(config_name, 'min_score')):
path_finder.close()
# print("PAth", i, "Has Reached MIN SCORE!")
if path_finder.path.endsInRegion(clicked_points[1], int(config.get(config_name, 'end_region_radius'))):
# print("PAth", i, "Has Reached Destiantion!")
n2 = ariadne.graph.nearestNode(clicked_points[1])
path_finder.path.addNode(n2)
path_finder.close()
reaches_map[i] = 1
reaches_counter += 1
if multi_path_finder.getIterations() > int(config.get(config_name, 'max_length')):
multi_path_finder.close()
c = 0
step_time = 0
if args['debug']:
print("STOP")
if not end_reached:
c = window.showImg(output_image, step_time)
if multi_path_finder.isFinished():
end_reached = True
print("END REACHED!")
# output_image = ariadne.graph.generateBoundaryImage(image)
# cv2.circle(output_image, tuple(
# clicked_points[0]), config.get(config_name, 'end_region_radius'), (0, 0, 1), 2)
# cv2.circle(output_image, tuple(
# clicked_points[1]), config.get(config_name, 'end_region_radius'), (0, 0, 1), 2)
# for i, f in enumerate(multi_path_finder.path_finders):
# f.path.draw(output_image, color=(0, 0, 1), draw_numbers=False)
# last_point = f.path.as2DPoints()[-1]
# cv2.putText(output_image, "{}".format(i), tuple(
# last_point + np.array([5, 0])), cv2.FONT_HERSHEY_PLAIN, 1.5, (0, 0, 0), 2)
output_image = image.copy() # ariadne.graph.generateBoundaryImage(image)
best = multi_path_finder.getBestPathFinder()
best.path.draw(output_image, color=(0, 255, 0), draw_numbers=False)
window.showImg(output_image, 0)
window = InteractiveWindow("stereo_matching", autoexit=True)
window.registerCallback(clickCallback, event=InteractiveWindow.EVENT_MOUSEDOWN)
output_image = ariadne.graph.generateBoundaryImage(image, color=boundary_color)
window.showImg(image, time=0, disable_keys=False)