<jupyter_start><jupyter_text><jupyter_code>!pip uninstall -y opencv-python opencv-contrib-python
!pip install opencv-contrib-python==3.4.2.17
import cv2
import numpy as np
from urllib.request import urlopen
from google.colab.patches import cv2_imshow
import matplotlib.pyplot as plt
def show_figure(img, size=(10, 10)):
    plt.figure(figsize=size)
    plt.axis("off")
    plt.imshow(cv2.cvtColor(img, cv2.COLOR_BGR2RGB))
url = f"https://raw.githubusercontent.com/jafetimbre/ms-school-stuff/master/image-processing/coin_counter/res/manual/10bani.jpg"
req = urlopen(url)
arr = np.asarray(bytearray(req.read()), dtype=np.uint8)
base = cv2.imdecode(arr, -1)
show_figure(base)
url = f"https://raw.githubusercontent.com/jafetimbre/ms-school-stuff/master/image-processing/coin_counter/res/manual/conis.jpg"
req = urlopen(url)
arr = np.asarray(bytearray(req.read()), dtype=np.uint8)
coins = cv2.imdecode(arr, -1)
show_figure(coins)
roi = (100, 950, 665, 665)
coin = coins[roi[1]:roi[1]+roi[3], roi[0]:roi[0]+roi[2]]
show_figure(coin)
im1 = base.copy()
im2 = coin.copy()

WCANNY = False

sift = cv2.xfeatures2d.SIFT_create(5000)
bf = cv2.BFMatcher()

g1 = cv2.cvtColor(im1, cv2.COLOR_BGR2GRAY)
g2 = cv2.cvtColor(im2, cv2.COLOR_BGR2GRAY)

if WCANNY:
    b1 = cv2.GaussianBlur(g1, (5, 5), 0)
    b2 = cv2.GaussianBlur(g2, (5, 5), 0)

    g1 = cv2.Canny(b1, 30, 150)
    g2 = cv2.Canny(b2, 30, 150)


k1, d1 = sift.detectAndCompute(g1, None)
k2, d2 = sift.detectAndCompute(g2, None)

matches = bf.knnMatch(d1, d2, k=2)

good_matches = []
for m1, m2 in matches:
  if m1.distance < 0.2*m2.distance:
    good_matches.append([m1])

SIFT_matches = cv2.drawMatchesKnn(im1, k1, im2, k2, good_matches, None, flags=2)

show_figure(SIFT_matches)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15678449258836943, 'fraction_numerical': 0.062143671607753706, 'mean_word_length': 5.136363636363637, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 1, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '48187', 'license': 'MIT', 'n_tokens_mistral': 814, 'n_tokens_neox': 769, 'n_words': 132, 'path': 'image-processing/coin_counter/testing.ipynb', 'repo_name': 'jafetimbre/ms-school-stuff', 'size': '1754'}