def preProcessing(img):
    imgGray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    imgBlur = cv2.GaussianBlur(imgGray, (5, 5), 1)
    imgCanny = cv2.Canny(imgBlur, 200, 200)
    kernel = np.ones((5, 5))
    imgDial = cv2.dilate(imgCanny, kernel, iterations=2)
    imgThres = cv2.erode(imgDial, kernel, iterations=1)
    group = stackImages(
        0.5, [[img, imgGray, imgBlur], [imgCanny, imgDial, imgThres]])
    cv2.imshow("preprocessing", group)
    return imgThres
예제 #2
0
cv2.createTrackbar("sat_max", "controles", 225, 255, onChange)
cv2.createTrackbar("val", "controles", 0, 255, onChange)
cv2.createTrackbar("val_max", "controles", 225, 255, onChange)

while True:
    tesla = cv2.imread("resources/tesla.jpg")
    tesla_resized = cv2.resize(tesla, (300, 200))
    hsv = cv2.cvtColor(tesla_resized, cv2.COLOR_BGR2HSV)

    hue = cv2.getTrackbarPos("hue", "controles")
    hue_max = cv2.getTrackbarPos("hue_max", "controles")
    sat = cv2.getTrackbarPos("sat", "controles")
    sat_max = cv2.getTrackbarPos("sat_max", "controles")
    val = cv2.getTrackbarPos("val", "controles")
    val_max = cv2.getTrackbarPos("val_max", "controles")
    print(hue, hue_max, sat, sat_max, val, val_max)
    lower = np.array([hue, sat, val])
    upper = np.array([hue_max, sat_max, val_max])

    mask = cv2.inRange(hsv, lower, upper)
    imageOutpu = cv2.bitwise_and(tesla_resized, tesla_resized, mask=mask)
    group = stackImages(0.5, ([tesla_resized, hsv, mask, imageOutpu]))

    # cv2.imshow("tesla", tesla)
    # cv2.imshow("tesla_resized", tesla_resized)
    cv2.imshow("hsv", hsv)
    cv2.imshow("mask", mask)
    cv2.imshow("mask222", imageOutpu)
    cv2.imshow("grouoed", group)

    cv2.waitKey(1)
예제 #3
0
        print("2")
        cv2.circle(final_result, (x, y), 10, dor_colour[count], cv2.FILLED)
        if x != 0 and y != 0:
            newpoint.append([x, y, count])
        count += 1
        print("3")
    return newpoint


def draw_points(my_points, mycolour):
    for points in my_points:
        print(points)
        cv2.circle(final_result, (points[0], points[1]), 10,
                   mycolour[points[2]], cv2.FILLED)


while True:
    success, img = cam.read()
    final_result = img.copy()

    np = findcolor(img, mycolour, dor_colour)
    if len(np) != 0:
        for i in np:
            my_points.append(i)
        draw_points(np, dor_colour)
    cv2.imshow("res", final_result)
    cv2.waitKey(1)
    stackImages(0.5, [img, img])
    if cv2.waitKey(1) & 0xFF == ord('q'):
        cv2.destroyAllWindows()
        break
예제 #4
0
import cv2
import numpy as np
from function import stackImages
from function import getContours



shapes = cv2.imread("resources/shapes2.png")
gray_image = cv2.cvtColor(shapes, cv2.COLOR_BGR2GRAY)
blur_image = cv2.GaussianBlur(gray_image,(7,7),1)
image_canny = cv2.Canny(gray_image,50,50)
blank = np.zeros_like(gray_image)
shapes_copy = shapes.copy()
getContours(image_canny, shapes_copy)
group_image = stackImages(0.5,([shapes,gray_image,blur_image],[image_canny,shapes_copy,blank]))

# cv2.imshow("shapes orginal", shapes)
# cv2.imshow("gray image", gray_image)
cv2.imshow("group image", group_image)

cv2.waitKey(0)