Ejemplo n.º 1
0
# -- TODO: use 3d model instead --
projectionImage = templateImage  # The 3d model in obj format. For now it's just the template image

outVideo = cv2.VideoWriter(
    '../results/outpy.avi', cv2.VideoWriter_fourcc('M', 'J', 'P', 'G'), 10,
    (backgroundVideo[0].shape[1], backgroundVideo[0].shape[0]))

templateImage = projectionImage

for i in range(len(backgroundVideo)):
    backgroundImage = backgroundVideo[i]
    projectionImageCropped = projectionImage  # Currently no cropping is needed

    # Extract features and match
    # -- Note: if index out of range error occurs, lower numMatches variable in matchFeatures.py --
    pts1, pts2 = matchFeatures(templateImage, backgroundImage)

    # Compute homography using RANSAC
    M, mask = cv2.findHomography(
        pts1, pts2, cv2.RANSAC, 8.0
    )  # If performance sub-optimal, consider change the inlier threshold here

    # Generate composite image
    # TODO: -- replace the composite function with the 3D model version --
    compositeImage = compositeWarp(M, projectionImageCropped, backgroundImage)
    outVideo.write(compositeImage)
    if i % 50 == 0:
        print("Frame {} is recorded.".format(i))
    # cv2.imshow("Composite image", compositeImage)
    # cv2.waitKey(0)
num_tri = 30

print("Extracting logo image SIFT features... \n")
logopath = 'logos'
logoImages = extractFeaturesBulk.extractFeaturesBulk(logopath)
print("Done \n")
print("Extracting test image SIFT features... \n")
testpath = 'test'
testImages = extractFeaturesBulk.extractFeaturesBulk(testpath)
print("Done \n")
for i in range(len(testImages)):
    for j in range(len(logoImages)):
        print('\n')
        print("********************************************************")
        t = time.process_time()
        pairs = matchFeatures.matchFeatures(logoImages[j], testImages[i], dthr)
        elapsed_time = time.process_time() - t
        print("Pairs created in ", elapsed_time)
        t = time.process_time()
        Dab, a, b = FGCT.extract_triangles(testImages[i], logoImages[j], pairs,
                                           num_tri)
        elapsed_time = time.process_time() - t
        print("Triangles  created in ", elapsed_time)
        t = time.process_time()
        correspodence1, correspodence2, consistensy, Dtemp = FGCT.FGCT(
            Dab, alpha, sigma)
        elapsed_time = time.process_time() - t
        print("FGCT  elapsed time is ", elapsed_time)
        print("Correspodence 1 is", correspodence1)
        print("Correspodence 2 is", correspodence2)
        print("********************************************************")
Ejemplo n.º 3
0
import cv2
from matchFeatures import matchFeatures
from matchFeatures import plotMatches
from compositeWarp import compositeWarp
from skimage import color
from loadVid import loadVid

im1 = cv2.imread('../data/Squirtle_card.jpg', 0)
im1 = np.rot90(im1)
#im2 = cv2.imread('../data/cv_desk.png',0)
backgroundVideo = np.load("../readVideo/squirtle_parallel.npy")
im2 = backgroundVideo[0]
#cv2.imshow("Card image", im1)
#cv2.waitKey(0)
# Test for matchFeatures
pts1, pts2 = matchFeatures(im1, im2)

# Convert the images to grayscale if they are RGBs
im1Shape = im1.shape
im2Shape = im2.shape
im1Gray = None
im2Gray = None
numMatches = 10
if len(im1Shape) == 3:
    im1Gray = color.rgb2gray(im1)
else:
    im1Gray = im1

if len(im2Shape) == 3:
    im2Gray = color.rgb2gray(im2)
else:
Ejemplo n.º 4
0
imageBPoints = getInterestPoints(imageB, feature_width) 

'''
print('proj4.py: got interest points')
print(imageAPoints)
'''

# %% Create feature vectors at each interest point. Szeliski 4.1.2
# % !!! You will need to implement get_features. !!!

# intake a set of points. Output a set of features
imageA_features = getFeatures(imageA, imageAPoints, feature_width)

imageB_features = getFeatures(imageB, imageBPoints, feature_width)

matched = matchFeatures(imageA_features, imageB_features)

print('proj4.py: matched')
#print(matched)

showCorrespondence(imageA, imageB, matched)


#turn feature list into 2 lists of coords
#for feat in matched:
	#coordAlist.append(feat[0])
	#coordBlist.append(feat[2][1][0]) ??????


'''
# %% Match features. Szeliski 4.1.3