from cam import stream
import cv2


def resize(img):
    res = cv2.resize(img, None, fx=2, fy=2, interpolation=cv2.INTER_CUBIC)
    cv2.imshow('resized', res)


stream(resize)
from cam import stream
from window import show_horizontal_stack_images
import cv2
import numpy as np

# red color boundaries (R,B and G)
lower = [1, 0, 20]
upper = [60, 40, 200]

# create NumPy arrays from the boundaries
lower = np.array(lower, dtype="uint8")
upper = np.array(upper, dtype="uint8")


def mask_by_color_range(img):
    # create color range mask
    mask = cv2.inRange(img, lower, upper)

    # convert mask to 3 channel for horizontal stacking
    mask_3_channel = cv2.cvtColor(mask, cv2.COLOR_GRAY2BGR)

    # apply mask to image
    masked_result = cv2.bitwise_and(img, img, mask=mask)

    #show window
    show_horizontal_stack_images('RGB -> Color Mask -> Masked Result',
                                 [img, mask_3_channel, masked_result])


stream(mask_by_color_range)
Пример #3
0
from cam import stream
from window import show_horizontal_stack_images
import cv2


def convert_from_rgb_to_gray(img):
    #convert to gray
    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    #convert back to 3 channel to enable horizontal stacking
    gray_3_channel = cv2.cvtColor(gray, cv2.COLOR_GRAY2BGR)
    #show window
    show_horizontal_stack_images('RGB -> GRAY', [img, gray_3_channel])


stream(convert_from_rgb_to_gray)
Пример #4
0

def translate_by_angle(angle, img):
    rows, cols, _ = img.shape
    translate_x = 100 * math.cos(angle / math.pi)
    translate_y = 100 * math.sin(angle / math.pi)
    matrix = [[1, 0, translate_x], [0, 1, translate_y]]
    M = np.float32(matrix)
    dst = cv2.warpAffine(img, M, (cols, rows))
    return dst


def translate(img):
    global matrix, angle, angle_step
    # translate input image by matrix defined at top of file
    static_translation = translate_static(matrix, img)

    # increment angle for angle-based translation
    angle += angle_step

    # translate input image dynamically by incrementing angle
    angle_based_translation = translate_by_angle(angle, img)

    #show window
    show_horizontal_stack_images(
        'RGB -> Static Translation -> Angle-based Translation ',
        [img, static_translation, angle_based_translation])


stream(translate)
Пример #5
0
from cam import stream
from window import show_horizontal_stack_images
import cv2


def canny_edges(img):
    # find edges
    edges = cv2.Canny(img, 100, 200)

    # convert back to 3 channel to enable horizontal stacking
    edges_3_channel = cv2.cvtColor(edges, cv2.COLOR_GRAY2BGR)

    show_horizontal_stack_images('RGB -> Canny Edges ', [img, edges_3_channel])


stream(canny_edges)
Пример #6
0
from cam import stream
from window import show_horizontal_stack_images
import cv2


def convert_from_rgb_to_hsv(img):
    #convert to HSV
    hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
    #show window
    show_horizontal_stack_images('RGB -> HSV', [img, hsv])


stream(convert_from_rgb_to_hsv)