<jupyter_start><jupyter_text>Point Selection Importing Python libraries:<jupyter_code>import cv2
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import ipywidgets as widgets<jupyter_output><empty_output><jupyter_text>Reading image:<jupyter_code># fig = plt.figure(figsize=(50,70))
image = cv2.imread('balloonfiesta.jpeg')
resized_image = cv2.resize(image, (800,500))

from PointSelection import pickpoints
points = pickpoints(resized_image, n=5)<jupyter_output>311, 227
432, 141
533, 197
452, 273
354, 198<jupyter_text>Function for detecting clicks on image and putting them in circle matrix:<jupyter_code>def detectPoints(event,x,y,flags,params):
    global counter
    if event == cv2.EVENT_LBUTTONDOWN:
        circles[counter] = x,y
        counter = counter + 1
        print(circles)
        
# cid = fig.canvas.mpl_connect('button_press_event', detectPoints)

# imgplot = plt.imshow(image)
# plt.show()<jupyter_output><empty_output><jupyter_text>Perform Template Matching once 4 points has been detected:<jupyter_code># while True:
#     if counter == 4:
#         width, height = 250,350
#         pts1 = np.float32([circles[0],circles[1],circles[2],circles[3]])
#         pts2 = np.float32([[0,0], [width,0], [0,height], [width,height]])
#         matrix = cv2.getPerspectiveTransform(pts1,pts2)
#         imgOutput = cv2.warpPerspective(resized_image,matrix,(width,height))
#         cv2.imshow("Output Image", imgOutput)
        
#     for x in range(0,4):
#         cv2.circle(resized_image,(circles[x][0], circles[x][1]),3,(0,255,0),cv2.FILLED)
        
#     cv2.imshow("Original", resized_image)
#     cv2.setMouseCallback("Original", detectPoints)
#     cv2.waitKey(1)
# cv2.imshow("Original", resized_image)
# cv2.setMouseCallback("Original", detectPoints)
# cv2.waitKey(1)
# cv2.waitKey(1)

# imgOutput = resized_image[circles[0]-10:circles[0]+10, circles[1]-10:circles[1]+10]
# cv2.imshow("Output Image", imgOutput)
circles
half_window = 100
counter = 0
while True:
    if counter == 1:
        template = resized_image[circles[0,1]-half_window:circles[0,1]+half_window, circles[0,0]-half_window:circles[0,0]+half_window, :]
        cv2.imshow("Output Image", template)
        counter = 0
        
    cv2.imshow("Original", resized_image)
    cv2.setMouseCallback("Original", detectPoints)
    cv2.waitKey(1)


# cv2.imshow("Original", resized_image)
# cv2.setMouseCallback("Original", detectPoints)
# cv2.waitKey(1)

circles[0,0]
template
resized_image<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1377952755905512, 'fraction_numerical': 0.05236220472440945, 'mean_word_length': 4.868360277136259, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '378163', 'license': 'MIT', 'n_tokens_mistral': 975, 'n_tokens_neox': 917, 'n_words': 159, 'path': 'PointSelection.ipynb', 'repo_name': 'see-insight/pointselector', 'size': '2540'}