Exemplo n.º 1
0
    def __init__(self, *args, **kwargs):
        """
        Constructor for CollectProcess class.
        Initialize the fast, brisk and bf detectors. Loads the templates data and
        create the directory for collection.

        :param args:
        :param kwargs:
        """
        self.__fast = cv2.FastFeatureDetector_create(threshold=50,
                                                     nonmaxSuppression=50)
        self.__br = cv2.BRISK_create()
        self.__bf = cv2.BFMatcher(cv2.NORM_HAMMING, crossCheck=True)

        try:
            model_type = kwargs['model_type']
        except KeyError:
            model_type = 'CT'

        self.__templates = make_templates(model_type, self.__fast, self.__br)

        self.__modes = args
        self.__kwargs = kwargs

        self.__dp = DataPath()

        self.__file_index = self.__dp.get_index('collected')
        self.__dir = os.path.join(self.__dp.collected, str(self.__file_index))
        os.mkdir(self.__dir)

        self.__index = 0

        col_names = ('detections', 'intensity', 'fast_kp', 'process_time')
        self.__df = pd.DataFrame(columns=col_names)
Exemplo n.º 2
0
def live_demo():

    # initialises fastfeaturedetector to get initial points of interests
    fast = cv2.FastFeatureDetector_create(threshold=50, nonmaxSuppression=50)

    # initialises Binary Robust Invariant Scalable Keypoints for
    # keypoint descriptor analyze
    br = cv2.BRISK_create()

    # BruteForce matcher to compare matches
    bf = cv2.BFMatcher(cv2.NORM_HAMMING, crossCheck=True)

    from src.process import ImageProcess as ip
    from src.templates import make_templates

    # initialize the data of the templates
    ct_models = make_templates('CT', fast, br)
    start = time()
    while True:

        # captures the screen with ImageGrab in RGB.
        screen = np.array(ImageGrab.grab(bbox=(0, 27, 800, 627)))
        # converts it to BGR
        screen = cv2.cvtColor(screen, cv2.COLOR_RGB2BGR)

        process = ip(screen, ct_models, fast, br, bf, 'draw')
        print('Loop took: {:.5} seconds'.format(time() - start))

        cv2.imshow('AimAssistant', process.image)
        start = time()
        if cv2.waitKey(25) & 0xFF == ord('q'):
            cv2.destroyAllWindows()
            break
Exemplo n.º 3
0
def steps(example=0):

    from src.process import ImageProcess as ip
    from src.templates import make_templates
    from src.paths import DataPath

    options = [
        'norm', 'gray', 'blurred1', 'opening1', 'threshold1', 'masked1',
        'opening2', 'blurred2', 'threshold2'
    ]

    fast = cv2.FastFeatureDetector_create(threshold=50, nonmaxSuppression=50)
    br = cv2.BRISK_create()
    bf = cv2.BFMatcher(cv2.NORM_HAMMING, crossCheck=True)

    ct_models = make_templates('CT', fast, br)

    dp = DataPath()

    try:
        file = os.listdir(dp.examples)[example]
    except KeyError:
        print('Invalid example')

    for option in options:

        image = cv2.imread(os.path.join(dp.examples, file))

        process = ip(image, ct_models, fast, br, bf, 'draw', debug=option)

        if option == 'norm':
            test_image = cv2.cvtColor(process.test, cv2.COLOR_BGR2RGB)
            plt.imshow(test_image)
        else:
            plt.imshow(process.test, cmap='gray')

        plt.show()
Exemplo n.º 4
0
def samples():

    from src.process import ImageProcess as ip
    from src.templates import make_templates
    from src.paths import DataPath

    fast = cv2.FastFeatureDetector_create(threshold=50, nonmaxSuppression=50)
    br = cv2.BRISK_create()
    bf = cv2.BFMatcher(cv2.NORM_HAMMING, crossCheck=True)

    ct_models = make_templates('CT', fast, br)

    dp = DataPath()

    for file in os.listdir(dp.examples):

        image = cv2.imread(os.path.join(dp.examples, file))

        process = ip(image, ct_models, fast, br, bf, 'draw')

        image = cv2.cvtColor(process.image, cv2.COLOR_BGR2RGB)

        plt.imshow(image)
        plt.show()