示例#1
0
def read_img(img_path: str,
             scale: float = 0.0,
             concat_gray: bool = False) -> None:
    '''
        Reading and showing image function
        Args:
            img_path: str - path to your image data
            scale: float - in order to rescale your image
            concat_gray: bool - if requires to show RGB and GRAY
                                in one window
    '''
    img = cv.imread(img_path)

    if scale:
        img = rescale_frame(img, scale)

    if concat_gray:
        # This method firstly transforms BGR to GRAY - 3D -> 1D
        # and then from 1D -> 3D but remains still gray
        gray = cv.cvtColor(img, cv.COLOR_BGR2GRAY)
        gray_BGR = cv.cvtColor(gray, cv.COLOR_GRAY2BGR)

        # Matrix concatenation
        img = np.hstack((img, gray_BGR))

    show_img(img, 'Image')
import cv2 as cv
import numpy as np
from basic_functions.helpers import show_img

if __name__ == "__main__":
    img_path = "data/images/city.jpg"

    # Reading image as gray scale
    img = cv.imread(img_path)
    gray = cv.cvtColor(img, cv.COLOR_BGR2GRAY)

    # Empty image to draw contours
    blank = np.zeros(img.shape, dtype='uint8')

    # Exerting Gaussian blur
    blur = cv.GaussianBlur(gray, (5, 5), cv.BORDER_DEFAULT)
    # Canny for edge detection
    canny = cv.Canny(blur, 125, 175)

    ret, thresh = cv.threshold(gray, 125, 255, cv.THRESH_BINARY)
    cv.imshow('Thresh', thresh)

    contours, hierarchies = cv.findContours(thresh, cv.RETR_LIST,
                                            cv.CHAIN_APPROX_SIMPLE)

    print(f"Founded countours: {len(contours)}")

    cv.drawContours(blank, contours, -1, (0, 0, 255), 1)
    show_img(blank)
示例#3
0
import cv2 as cv
import numpy as np
from basic_functions.helpers import show_img

if __name__ == "__main__":
    img_path = "data/images/cat.jpg"
    img = cv.imread(img_path)

    # Averaging
    average = cv.blur(img, (3, 3))
    img_average = np.hstack((img, average))

    show_img(img_average, "Image & Averaging")

    # Gaussian Blur
    gauss = cv.GaussianBlur(img, (5, 5), 0)
    img_gauss = np.hstack((img, gauss))

    show_img(img_gauss, "Image & GaussianBlur")

    # Median Blur
    median = cv.medianBlur(img, 7)
    img_median = np.hstack((img, median))

    show_img(img_median, "Image & MedianBlur")

    # Bilateral
    bilateral = cv.bilateralFilter(img, 10, 35, 25)
    img_bilateral = np.hstack((img, bilateral))

    show_img(img_bilateral, "Image & Bilateral")
示例#4
0
from basic_functions.read_data import read_img, read_video
from basic_functions.transformations import translate, rotate
from basic_functions.helpers import show_img

if __name__ == "__main__":
    img_path = "data/images/city.jpg"

    # Reading image
    img = cv.imread(img_path)

    # Splitting into 3 colors
    b, g, r = cv.split(img)

    # distinct_colors = np.hstack((b, g, r))
    distinct_colors = cv.resize(distinct_colors, (1200, 400))
    show_img(distinct_colors, "Distinct colors")

    # Merging it back together
    img_merged = cv.merge((b, g, r))
    show_img(img_merged, "Merged")

    # Adding to images
    # Saturation of 2 images
    bg_add = cv.add(b, g)
    show_img(bg_add, "Blue and Green")

    gr_add = cv.add(g, r)
    show_img(gr_add, "Green and Red")

    # Weighted adding
    # result = img_1 * alpha + img_2 * beta + gamma
import cv2 as cv
import numpy as np
from basic_functions.read_data import read_img, read_video
from basic_functions.helpers import show_img

if __name__ == "__main__":
    img_path = "data/images/city.jpg"

    # Reading image
    img = cv.imread(img_path)

    # Blurring
    blur = cv.GaussianBlur(img, (3, 3), cv.BORDER_DEFAULT)

    img_blur = np.hstack((img, blur))
    show_img("Image and Blur image", img_blur)

    # Edge Cascade
    canny_img = cv.Canny(img, 125, 175)
    canny_blur = cv.Canny(blur, 125, 175)

    canny = np.hstack((canny_img, canny_blur))
    show_img("Canny edges on Image and Blur", canny)

    # Image dilation
    dilated = cv.dilate(canny_blur, (7, 7), iterations=3)

    canny_dilated = np.hstack((canny_blur, dilated))
    show_img("Dilated Canny edges", canny_dilated)

    # Image erosion