How to do it

You need to complete the following steps:

  1. Import the necessary modules, open an input image, and copy it:
import cv2import numpy as npimg = cv2.imread('../data/circlesgrid.png', cv2.IMREAD_COLOR)show_img = np.copy(img)
  1. Define two functions to implement the process of points selection :
selected_pts = []def mouse_callback(event, x, y, flags, param):    global selected_pts, show_img    if event == cv2.EVENT_LBUTTONUP:        selected_pts.append([x, y])        cv2.circle(show_img, (x, y), 10, (0, 255, 0), 3)def select_points(image, points_num):    global selected_pts    selected_pts = []        cv2.namedWindow('image')    cv2.setMouseCallback('image', mouse_callback)    while True:        cv2.imshow('image', image)        k = cv2.waitKey(1) if k == 27 or len(selected_pts) == ...

Get OpenCV 3 Computer Vision with Python Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.