<commit_before>"""
Compute control-points using OpenCV
===================================

Compute interest points (using the OpenCV's SURF detector) on pairs of images,
match them, and then filter them out using RANSAC.


main function:    `gen_pairwise_surf_control_points`

"""


import numpy as np

import cv2
import hsi


def get_surf_kps(img_fn, img=None, center_out=0,
                 cness_thresh=1000, min_pts=10, max_pts=300):
    """ Return the opened gray-scale OpenCV image and its SURF keypoints

    Points "in the middle" of the frames are left out
    (center_out = proportioned of space left out).
    """
    assert center_out < 1, "Too high center part to remove"
    # initialize the SURF keypoint detector and descriptor
    surf = cv2.SURF(cness_thresh)
    # load the gray-scale image
    if img is None:
        img = cv2.imread(img_fn, 0)
    # detect and describe SURF keypoints
    cvkp, ds = surf.detect(img, None, None)
    # re-arrange the data properly
    ds.shape = (-1, surf.descriptorSize())  # reshape to (n_pts, desc_size)
    kp = np.array([p.pt for p in cvkp])
    cness = np.array([p.response for p in cvkp])
    # filter out points in the middle (likely to be on the moving actor)
    if center_out > 0:
        rx = img.shape[1]<commit_msg>bugfix for version 2.4.8 of cv2<commit_after>"""
Compute control-points using OpenCV
===================================

Compute interest points (using the OpenCV's SURF detector) on pairs of images,
match them, and then filter them out using RANSAC.


main function:    `gen_pairwise_surf_control_points`

"""


import numpy as np

import cv2
import hsi

assert 'SURF' in dir(cv2), "SURF is not available in the cv2 package (version {}).\
                            some linux distribitions removed it as it contains \
                            properitery algorithms\
                            In ubuntu do \
                            sudo add-apt-repository --yes ppa:xqms/opencv-nonfree\
                            sudo apt-get update \
                            sudo apt-get install libopencv-nonfree-dev\
                             ".format(cv2.__version__)

def get_surf_kps(img_fn, img=None, center_out=0,
                 cness_thresh=1000, min_pts=10, max_pts=300):
    """ Return the opened gray-scale OpenCV image and its SURF keypoints

    Points "in the middle" of the frames are left out
    (center_out = proportioned of space left out).
    """
    assert center_out < 1, "Too high center part to remove"
    # initialize the SURF keypoint detector and descriptor
    surf = cv2.SURF(cness_thresh)
    # load the gray-scale image
    if img is None:
        img = cv2.imread(img_fn, 0)
    # detect and describe SURF keypoints
    cvkp, ds = surf.detectAndCompute(img, None, None)
    # re-arrange the data properly
    ds.shape = (-1, surf.descriptorSize())  # reshape to (n_pts, desc_size)
    kp = np.array([p.pt for p in cvkp])
    cness = np.array([p.response for p in cvkp])
    # filter out points in the middle (likely to be on the moving actor)
    if center_out > 0:
        rx = img.shape[1]
{'fraction_non_alphanumeric': 0.10327132777421424, 'fraction_numerical': 0.013790891597177678, 'mean_word_length': 2.5891829689298045, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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}}
{'dir': 'git-commits-cleaned', 'id': '2456849', 'n_tokens_mistral': 1006, 'n_tokens_neox': 945, 'n_words': 342}