def expanded_orb_descriptors(image):
    descriptor_extractor = feature.ORB(n_keypoints=200)
    descriptor_extractor.detect_and_extract(image)
    descriptors = descriptor_extractor.descriptors
    expanded = numpy.append(descriptors,
                            numpy.zeros((200 - len(descriptors), 256)) - 1, 0)
    return expanded.flatten()
    def findRetinaFeatures(self, image, n_kp, method='orb', plot=True):
        '''
        The function finds strong features in the image used for registration.
        :param image: input image. -- (1636, 1536, 3)
        :param n_kp: Number of keypoints you want to find.
        :param method: Set which algorithm should be used to find keypoints.
        :param plot: Set True, found keypoints will be plotted.
        :return keypoints and descriptors representing the found features.
        '''
        # Creating a gray image for the ORB method and creating a ROI in order to ignore the black caption at the bottom.
        grey_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
        roi = grey_image[100:1300, 100:1300]

        # Applying the ORB method and extracting the features.
        if method == 'orb':
            # Preprocessing for ORB
            roi = filters.gaussian(roi)

            orb = feature.ORB(n_keypoints=n_kp)
            orb.detect_and_extract(roi)

            keypoints = orb.keypoints
            descriptors = orb.descriptors

        # Applying the SIFT method and extracting the features.
        elif method == 'sift':
            roi = cv2.GaussianBlur(roi, (5, 5), cv2.BORDER_DEFAULT)
            sift = cv2.xfeatures2d.SIFT_create(n_kp)
            kp_cv, descriptors = sift.detectAndCompute(roi, None)

            # Convert opencv data structure to numpy array.
            keypoints = np.array([k.pt for k in kp_cv])

        # Applying the SURF method and extracting the features.
        elif method == 'surf':
            roi = cv2.GaussianBlur(roi, (5, 5), cv2.BORDER_DEFAULT)
            surf = cv2.xfeatures2d.SURF_create(n_kp)
            kp_cv, descriptors = surf.detectAndCompute(roi, None)

            # Convert opencv data structure to numpy array.
            keypoints = np.array([k.pt for k in kp_cv])

        else:
            print("Unknown string " + method)
            exit()

        # Plotting option.
        if plot == True:
            self.plotting_points(image, keypoints, number=False)

        return (keypoints, descriptors)
示例#3
0
def main(path, n_imgs_per_class=100):
    """
    Get the first three folders with photos from the folder.

    Creates for each of these models for a particular classifier.
    """
    import os
    filenames = [name for name in os.listdir(path)]
    isdir = lambda filename: os.path.isdir(os.path.join(path, filename))
    dirs = list(filter(isdir, filenames))
    dirs = sorted(dirs, key=lambda s: s.lower())[:3]
    dirs = dirs[:3]

    filepaths = []
    labels = []
    if dirs:  # supervised learning
        for cls in dirs:
            filenames = os.listdir(os.path.join(path, cls))
            filenames = sorted(filenames)
            filenames = filenames[:n_imgs_per_class]
            filenames = list(
                map(lambda x: os.path.join(path, cls, x), filenames))
            labels += [cls] * len(filenames)
            filepaths += filenames

    print("Classes: ", *dirs)
    for f in filepaths:
        print(f)

    for fp, l in zip(filepaths, labels):
        print(l, fp)

    if labels:
        #    clf = ensemble.RandomForestClassifier(n_estimators=50)
        clf = svm.SVC()
    else:
        clf = cluster.KMeans()

    pipeline = Pipeline(feature.ORB(n_keypoints=200), clf)
    pipeline.train_model(filepaths, labels)

    print("Persisting model..")
    persist(pipeline._clf, 'classifier')
    persist(pipeline._clusterizer, 'kmeans')
示例#4
0
def main(path):
    """
    Compare svc and rtf classifiers.

    With the directory specified by the user, main function is no longer collects 100 images.
    Then looks for files with the extension .pickle, which are stored models for previously trained directories.
    Each photo in a user directory, reduced to shades of gray, pulls marks and creates histograms.
    If any of the pictures has been classified in another class than it should function prints a number of errors and the class name.
    """
    _, cls = os.path.split(path)
    des = feature.ORB(n_keypoints=200)
    rtf = read('rtf')
    clu_rtf = read('rtf_kmeans')
    svc = read('svc')
    clu_svc = read('svc_kmeans')

    filenames = os.listdir(path)
    np.random.shuffle(filenames)
    filenames = filenames[:100]
    images = [io.imread(os.path.join(path, filename)) for filename in filenames]
    images = [color.rgb2gray(img) for img in images]

    features = [describe(img, des) for img in images]

    print("rtf")
    histograms = [histogramize(feat, clu_rtf) for feat in features]
    rtf_result = rtf.predict(histograms)

    print('svc')
    histograms = [histogramize(feat, clu_svc) for feat in features]
    svc_result = svc.predict(histograms)

    rtf_faults = rtf_result[rtf_result!=cls]
    svc_faults = svc_result[svc_result!=cls]

    print("RTF faults (", rtf_faults.size, "):", rtf_faults)
    print("SVC faults (", svc_faults.size, "):", svc_faults)
示例#5
0

# <markdowncell>
# [Panorama stitching](example_pano.ipynb)
# 
# [A longer example](adv3_panorama-stitching.ipynb)
# 
# ### Exercise
# 
# Represent the ORB keypoint of the camera-man



# <codecell>

orb = feature.ORB(n_keypoints=400, fast_threshold=0.02)   



# <codecell>

orb.detect_and_extract(camera)   



# <codecell>

coords = orb.keypoints
plt.imshow(camera, cmap='gray')
plt.plot(coords[:, 1], coords[:, 0], 'o')
plt.xlim(0, 512)
示例#6
0
    y = mask.flatten()
    logistic = LogisticRegression()
    logistic.fit(X, y)
    return logistic

def logistic_image(img, logistic):
    # actually sigmoid adjust instead of skimage bs reverse parameterization
    preds = logistic.predict_proba(img.reshape(-1, 1))
    img_mult = np.multiply(img.flatten(), preds[:,1])
    img_mult = img_mult.reshape(img.shape)
    return img_mult


#############
sift = cv2.xfeatures2d.SIFT_create()
kp1, des1 = feature.ORB(frame1,None)
kp2, des2 = sift.detectAndCompute(frame2,None)

#################
def ng_structure_tensor(frame):
    kernel = np.array([[-3,0,3],[-10,0,10],[-3,0,3]],dtype=np.float)/32.


Axx, Axy, Ayy = feature.structure_tensor(frame_sig, sigma=100)
l1, l2 = feature.structure_tensor_eigvals(Axx, Axy, Ayy)
l1_arr = np.array(l1)
l2_arr = np.array(l2)

#fig, ax = plt.subplots(3,2)
ax[0,0].imshow(frame_sig)
ax[1,0].imshow(l1_arr)
示例#7
0
"""
from sys import exit, argv
from skimage import io, feature, exposure
import numpy as np
import json
from models.db_mysql import Effectives
from models import db_mysql
from models.engine import get_engine
import itertools
import logging
from slit_utils import get_image
from sqlalchemy.orm import Session

logging.basicConfig(level=logging.DEBUG)

orb = feature.ORB()


def extract_orb(img):
    print img
    orb.detect_and_extract(img)
    ret = orb.descriptors
    print ret
    return ret


def extract_kp(img):
    kps = feature.corner_peaks(feature.corner_harris(img), min_distance=2)
    bb = feature.BRIEF(patch_size=5)  # iPad specific(or not)
    bb.extract(img, kps)
    return bb.descriptors
def pipeline():
    """Check have been selected marks."""
    return Pipeline(
        feature.ORB(n_keypoints=200),
        ensemble.RandomForestClassifier(),
    )