Esempio n. 1
0
def produce_frames(frames):
    bg = np.array(Image.open('bg.jpg'))
    bg = cv2.cvtColor(bg, cv2.COLOR_BGR2RGB)
    bg_s = np.array(Image.open('bg_s.jpg'))
    bg_s = cv2.cvtColor(bg_s, cv2.COLOR_BGR2RGB)

    frames_generated = []
    for frame in frames:
        res1 = cv2.bitwise_and(frame, bg)
        res2 = cv2.bitwise_and(cv2.bitwise_not(frame), bg_s)
        res = cv2.bitwise_xor(res1, res2)

        frames_generated.append(res)

    return frames_generated
Esempio n. 2
0
import numpy as np
from cv2 import cv2

#Create 300*300 numpy array and 250*250 white rectangle inside it
rectangle = np.zeros((300, 300), dtype="uint8")
cv2.rectangle(rectangle, (25, 25), (275, 275), 255, -1)
cv2.imshow("rectangle", rectangle)

#Create 300*300 numpy array and 150 radius white circle inside it
circle = np.zeros((300, 300), dtype="uint8")
cv2.circle(circle, (150, 150), 150, 255, -1)
cv2.imshow("circle", circle)

# performing the bitwise oprations
bitwiseAnd = cv2.bitwise_and(rectangle, circle)
cv2.imshow("AND", bitwiseAnd)
cv2.waitKey(0)

bitwiseOr = cv2.bitwise_or(rectangle, circle)
cv2.imshow("OR", bitwiseOr)
cv2.waitKey(0)

bitwiseXor = cv2.bitwise_xor(rectangle, circle)
cv2.imshow("XOR", bitwiseXor)
cv2.waitKey(0)

bitwiseNot = cv2.bitwise_not(rectangle, circle)
cv2.imshow("Not", bitwiseNot)
cv2.waitKey(0)
Esempio n. 3
0
from cv2 import cv2
import numpy as np
img1 = cv2.imread("bib.png")
img2 = cv2.imread("ml.png")
bit_and = cv2.bitwise_and(img2, img1)
bit_or = cv2.bitwise_or(img2, img1)
bit_xor = cv2.bitwise_xor(img1, img2)
bit_not = cv2.bitwise_not(img1)
bit_not2 = cv2.bitwise_not(img2)
cv2.imshow("img1", img1)
cv2.imshow("img2", img2)
cv2.imshow("bit_and", bit_and)
cv2.imshow("bit_or", bit_or)
cv2.imshow("bit_xor", bit_xor)
cv2.imshow("bit_not", bit_not)
cv2.imshow("bit_not2", bit_not2)
cv2.waitKey(0)
Esempio n. 4
0
from cv2 import cv2 as cv
import numpy as np

blank = np.zeros((400, 400), dtype='uint8')

rectangle = cv.rectangle(blank.copy(), (30, 30), (370, 370), 255, -1)
circle = cv.circle(blank.copy(), (200, 200), 200, 255, -1)

cv.imshow('Rectangle', rectangle)
cv.imshow('Circle', circle)

#bitwise AND. Exactly what you imagine
bitwiseAND = cv.bitwise_and(rectangle, circle)
cv.imshow('bitWiseAND', bitwiseAND)

#bitwise OR
bitwiseOR = cv.bitwise_or(rectangle, circle)
cv.imshow('bitWiseOR', bitwiseOR)

#bitwise XOR
bitwiseXOR = cv.bitwise_xor(rectangle, circle)
cv.imshow('bitwiseXOR', bitwiseXOR)

#bitwise NOT
bitwiseNOT = cv.bitwise_not(bitwiseXOR)
cv.imshow('bitwisenot', bitwiseNOT)

cv.waitKey(0)
Esempio n. 5
0
from cv2 import cv2
import numpy as np

img = np.zeros((460, 819, 3), np.uint8)
#print(img.shape)
cv2.rectangle(img, (400, 0), (500, 230), (255, 255, 255), -1)
img2 = cv2.imread('img1.png')
#print(img2.shape)
#bitwise operations
bitand = cv2.bitwise_and(img, img2)
bitnot = cv2.bitwise_not(img)
bitor = cv2.bitwise_or(img, img2)
bitxor = cv2.bitwise_xor(img, img2)
cv2.imshow('image', img)
cv2.imshow('image2', img2)
cv2.imshow('bitand', bitand)
cv2.imshow('bitnot', bitnot)
cv2.imshow('bitor', bitor)
cv2.imshow('bitxor', bitxor)

cv2.waitKey(0)
cv2.destroyAllWindows()
Esempio n. 6
0
                                           **lk_params)
    # Select good points
    if p1[st == 1] is not None:
        good_new = p1[st == 1]
    if p0[st == 1] is not None:
        good_old = p0[st == 1]
    # draw the tracks
    for i, (new, old) in enumerate(zip(good_new, good_old)):
        a, b = new.ravel()
        c, d = old.ravel()
        # mask = cv2.line(mask, (a,b),(c,d), color[i].tolist(), 2)
        frame = cv2.circle(frame, (a, b), 5, color[i].tolist(), -1)
    # img = cv2.add(frame,mask)
    img1 = frame

    cur_diff = cv2.bitwise_xor(frame_gray, old_gray)
    # diff = diff * number_mask
    # frame = cv2.circle(frame,(diff.mean(axis=1), diff.mean(axis=0)),8,0,-1)
    # ret, diff = cv2.threshold(diff, 100, 255, cv2.THRESH_BINARY) ###이진화
    # contours, image = cv2.findContours(diff,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
    if cur_diff.any():
        p1, st, err = cv2.calcOpticalFlowPyrLK(old_diff, cur_diff, p0, None,
                                               **lk_params)
        # Select good points
        if p1[st == 1] is not None:
            good_new = p1[st == 1]
        if p0[st == 1] is not None:
            good_old = p0[st == 1]
        # draw the tracks
        for i, (new, old) in enumerate(zip(good_new, good_old)):
            a, b = new.ravel()
Esempio n. 7
0
from cv2 import cv2
import numpy as np 

img1 = cv2.imread("./sources/bitwise-1.png")
img2 = cv2.imread("./sources/bitwise-2.png")

bit_and = cv2.bitwise_and(img2,img1)
bit_or = cv2.bitwise_or(img2,img1)
bit_xor = cv2.bitwise_xor(img1,img2)
bit_xor2 = cv2.bitwise_xor(img2,img1)

cv2.imshow("birlesim",bit_and)
cv2.imshow("birlesim or",bit_or)
cv2.imshow("birlesim xor",bit_xor)
cv2.imshow("birlesim xor2",bit_xor2)




cv2.waitKey(0)
cv2.rectangle(square, (50, 50), (250, 250), 255, -2)
cv2.imshow("Square", square)
cv2.waitKey()

# Making a ellipse
ellipse = np.zeros((300, 300), np.uint8)
cv2.ellipse(ellipse, (150, 150), (150, 150), 30, 0, 180, 255, -1)
cv2.imshow("Ellipse", ellipse)
cv2.waitKey()

cv2.destroyAllWindows()

# Shows only were they intersect
And = cv2.bitwise_and(square, ellipse)
cv2.imshow("AND", And)
cv2.waitKey()

# Shows where either square or ellipse is
bitwiseOr = cv2.bitwise_or(square, ellipse)
cv2.imshow("OR", bitwiseOr)

# Shows where either exist by itself
bitwiseXor = cv2.bitwise_xor(square, ellipse)
cv2.imshow("XOR", bitwiseXor)
cv2.waitKey()

# Shows everything that isn't part of the square
bitwiseNot_sq = cv2.bitwise_not(square)
cv2.imshow("NOT - square", bitwiseNot_sq)
cv2.waitKey()
Esempio n. 9
0
def find_text(image):
    """attempt to isolate the text in the image.
    
    :param image: input image
    :type image: cv2 image
    :return: contours, cropped image, if text is found
    :rtype: cv2 cnts, cv2 image, boolean
    """
    # convert to GRAYSCALE
    g_label = convert.bgr_to_gray(image)

    # binarise the image
    _, thresh = cv2.threshold(g_label, 127, 255,
                              cv2.THRESH_BINARY | cv2.THRESH_OTSU)

    # detect edges
    canny = features.apply_canny(thresh, 175, 190)

    # blur
    blur = filters.median_blur(canny, 3)

    # xor between canny and blur to attempt to remove some fo the lines from the diamond
    text_im = cv2.bitwise_xor(canny, blur)

    # blur again
    text_blur = filters.apply_gaussian_blur(text_im, 3)

    # attemtp to dilate the text so it is one big blob
    kernel_rect = cv2.getStructuringElement(cv2.MORPH_RECT, (5, 1))
    dilated = cv2.dilate(text_blur, kernel_rect, iterations=6)

    # attempt to remove anythin gthat is not veritcal or horizontal i.e. lines form the diamond
    kernel_cross = cv2.getStructuringElement(cv2.MORPH_CROSS, (7, 7))
    erosion = cv2.erode(dilated, kernel_cross, iterations=2)

    # threshold the image again
    _, thresh_dilated = cv2.threshold(erosion, 127, 255, cv2.THRESH_BINARY)

    # blur again
    td_blur = filters.median_blur(thresh_dilated, 9)

    # dilate the text into itself
    kernel_rect2 = cv2.getStructuringElement(cv2.MORPH_RECT, (3, 2))
    td_dilate = cv2.dilate(td_blur, kernel_rect2, iterations=10)

    for _ in range(12):
        td_dilate = filters.apply_gaussian_blur(td_dilate, 5)
        td_dilate = cv2.dilate(td_blur, kernel_rect2, iterations=10)

    kernel_rect3 = cv2.getStructuringElement(cv2.MORPH_RECT, (4, 8))
    td_dilate = cv2.dilate(td_dilate, kernel_rect3, iterations=3)

    # find contours that encompass the areas text could be
    _, cnts, _ = cv2.findContours(td_dilate.copy(), cv2.RETR_EXTERNAL,
                                  cv2.CHAIN_APPROX_SIMPLE)

    # report whether contours weere foun
    if cnts:
        found = True
        # optimise the contours found to only include the important ones
        bbox = find_optimal_components_subset(cnts, td_dilate)
        # crop to the optimal height, keep the entire width
        im = utils.crop_to_bbox(image, bbox, ignore='x')
    else:
        found = False
        im = image

    return im, found