Exemple #1
0
def test_funcs(img1, img2):
    img3 = img2

    funcs.show(img1)
    funcs.save(img1, filename='out_1.png')

    #funcs.getWidth funcs.getHeight
    print funcs.getWidth(img1), funcs.getHeight(img1)

    #funcs.mix
    mixed_pics = funcs.mix(img1, img3, .5)
    funcs.show(mixed_pics)

    #funcs.tint
    tinted_pic = funcs.tint(img1, (0, 0, 255), .5)
    funcs.show(tinted_pic)

    #funcs.grayscale
    gray_pic = funcs.grayscale(img1)
    funcs.show(gray_pic)
    gray_pic_2 = funcs.grayscale(img1, two_dimensional=True)
    funcs.show(gray_pic_2)

    #funcs.rotate
    img_rotate = funcs.rotate(img1, 180)
    funcs.show(img_rotate)
Exemple #2
0
def getSeam(img, blur=1):

    img = img.copy()
    img = funcs.grayscale(img, True)
    img = np.float32(cv2.GaussianBlur(img, (blur, blur), 0))
    derivative_kernel = np.float32([[-1, 0, 1], [-2, 0, 2], [-1, 0, 1]])
    Ix = cv2.filter2D(img, -1, derivative_kernel)
    Iy = cv2.filter2D(img, -1, derivative_kernel.T)
    path = Ix**2 + Iy**2
    path = path**.5

    kernel = np.float32([[1, 1, 1]])
    h, w = img.shape[:2]
    for i in range(1, h):
        row = path[i - 1, :]
        row = cv2.erode(row, kernel.T)
        path[i:i + 1, :] += row.T
    x = np.argmin(path[-1])
    y = h - 1
    seam = []
    seam.append(x)
    while y > 0:
        y -= 1
        minX = seam[0] - 1
        maxX = seam[0] + 2
        x = np.argmin(path[y, max(minX, 0):min(maxX, w - 1)]) + x
        if x != 0:
            x -= 1
        seam.insert(0, x)
    return seam
Exemple #3
0
def getSeam(img, blur=1, debug=False, attractor=np.zeroes(img.shape)):

    img_original = img.copy()
    img = img.copy()
    img = funcs.grayscale(img, True)
    img = np.float32(cv2.GaussianBlur(img, (blur, blur), 0))
    derivative_kernel = np.float32([[-1, 0, 1], [-2, 0, 2], [-1, 0, 1]])
    Ix = cv2.filter2D(img, -1, derivative_kernel)
    Iy = cv2.filter2D(img, -1, derivative_kernel.T)
    path = Ix**2 + Iy**2
    path = path**.5

    path += (atrractor * 100.0)

    if debug:
        pic_1_c_0 = path.copy()
        funcs.save(pic_1_c_0, "output/pic_1_a.png")

    kernel = np.float32([[1, 1, 1]])
    h, w = img.shape[:2]
    for i in range(1, h):
        row = path[i - 1, :]
        row = cv2.erode(row, kernel.T)
        path[i:i + 1, :] += row.T
    if debug:
        pic_1_c_1 = path.copy()
        funcs.save(pic_1_c_1, "output/pic_1_b.png")
    x = np.argmin(path[-1])
    y = h - 1
    seam = []
    seam.append(x)
    while y > 0:
        y -= 1
        minX = seam[0] - 1
        maxX = seam[0] + 2
        x = np.argmin(path[y, max(minX, 0):min(maxX, w - 1)]) + x
        if x != 0:
            x -= 1
        seam.insert(0, x)
    if debug:
        funcs.save(showSeam(pic_1_c_0, seam), "output/pic_1_c_1.png")
        funcs.save(showSeam(pic_1_c_1, seam), "output/pic_1_c_2.png")
        funcs.save(showSeam(img_original, seam), "output/pic_1_c_0.png")
    return seam
Exemple #4
0
pic1 = cv2.imread('input/pic1.png')
pic2 = cv2.imread('input/pic2.png')

pic_2_a_1 = mark_features(pic1, blur=15)
cv2.imwrite('output/pic_2_a_1.png', pic_2_a_1)
pic_2_a_2 = mark_features(pic2, blur=15)
cv2.imwrite('output/pic_2_a_2.png', pic_2_a_2)

pic_2_b, M2 = draw_mathces(pic1, pic2)
cv2.imwrite('output/pic_2_b.png', pic_2_b)

h2, w2 = pic2.shape[:2]
pic_2_d = cv2.warpPerspective(pic1, M2, (w2, h2))
cv2.imwrite('output/pic_2_d.png', pic_2_d)

pic_2_e = np.float32(funcs.grayscale(pic2)) - funcs.grayscale(pic_2_d)
pic_2_e -= np.min(pic_2_e)
pic_2_e /= np.max(pic_2_e)
pic_2_e *= 255.999999
pic_2_e = np.uint8(pic_2_e)
cv2.imwrite('output/pic_2_e.png', pic_2_e)

minX, minY, maxX, maxY = getBoundingRectangle(w2, h2, M2)
M3 = np.float32([[1, 0, -minX if minX < 0 else 0],
                 [0, 1, -minY if minY < 0 else 0], [0, 0, 1]])
warp_dim_x = int((abs(minX) if minX < 0 else 0) +
                 (abs(maxX) if maxX > w2 else w2))
warp_dim_y = int((abs(minY) if minY < 0 else 0) +
                 (abs(maxY) if maxY > h2 else h2))
pic1_warp = cv2.warpPerspective(pic1, M3.dot(M2), (warp_dim_x, warp_dim_y))
pic2_warp = cv2.warpPerspective(pic2, M3, (warp_dim_x, warp_dim_y))
import cv2
import numpy as np
import funcs

cv2.namedWindow("webcam", cv2.WND_PROP_FULLSCREEN)
cv2.setWindowProperty("webcam", cv2.WND_PROP_FULLSCREEN, 1)

cap = cv2.VideoCapture(0)

ret, frame = cap.read()
lastFrame = funcs.grayscale(frame)
"""
while True:
    ret,frame=cap.read()
    frame=funcs.grayscale(frame)
    output=np.uint8(np.abs(lastFrame*1.0-frame))
    lastFrame=frame
    
    output=np.uint8((output>50)*255.0)
    cv2.imshow("webcam",output)
    key=cv2.waitKey(1)
    if key==27:
	break

cap.release()
cv2.destroyAllWindows()
"""