Пример #1
0
import glob
import cv2
import numpy as np
from PIL import Image
import init_auv as auv

imdir = '/Users/Mackeprang/Dropbox (Personlig)/Master Thesis/Pictures/20181005_084733.9640_Mission_1'
#imdir = auv.datasetPath_Mads()["Images"]
filenames = auv.imagesFilePath(imdir, '*.png')

prev_frame = None
orb = cv2.ORB_create()
bf = cv2.BFMatcher(cv2.NORM_HAMMING, crossCheck=True)
for i, frame in enumerate(filenames):
    if auv.image_broken(frame):
        continue
    img = cv2.imread(frame)
    gray = auv.preprocess_image(img, unsharp=False)
    if prev_frame is None:
        prev_frame = gray
        kp1, des1 = orb.detectAndCompute(prev_frame, None)
    print "Numbers of features: " + str(len(kp1))
    kp2, des2 = orb.detectAndCompute(gray, None)
    matches = bf.match(des1, des2)
    matches = sorted(matches, key=lambda x: x.distance)
    img_match = cv2.drawMatches(prev_frame,
                                kp1,
                                gray,
                                kp2,
                                matches[:10],
                                None,
import glob
import cv2
import numpy as np
from PIL import Image
import  init_auv as auv
im_filename = '*.png'
imdir = '/Users/Mackeprang/Dropbox (Personlig)/Master Thesis/Pictures/20181005_084733.9640_Mission_1'
filenames = auv.imagesFilePath(imdir)
images = []
prev_frame = None

hsv = np.zeros_like(cv2.imread(filenames[0]))
hsv[...,1] = 255
for i,frame in enumerate(filenames):
    if auv.image_broken(frame):
        continue
    img = cv2.imread(frame)
    gray = auv.preprocess_image(img,size=None)

    if prev_frame is None:
        prev_frame = gray
        continue
    flow = cv2.calcOpticalFlowFarneback(prev_frame, gray, None, 0.5, 3, 30, 3, 5, 1.2, 0)
    mag, ang = cv2.cartToPolar(flow[..., 0], flow[..., 1])
    hsv[..., 0] = ang * 180 / np.pi / 2
    hsv[..., 2] = cv2.normalize(mag, None, 0, 255, cv2.NORM_MINMAX)
    bgr = cv2.cvtColor(hsv, cv2.COLOR_HSV2BGR)
    cv2.imshow("Match", bgr)
    key = cv2.waitKey()
    if key & 0xFF == ord('q'):
        break