Esempio n. 1
0
def hsv(arg):
    # 定义hsv空间的相应值
    LH = cv2.getTrackbarPos("LH", "TrackBars")
    LS = cv2.getTrackbarPos("LS", "TrackBars")
    LV = cv2.getTrackbarPos("LV", "TrackBars")
    LH = cv2.getTrackbarPos("LH", "TrackBars")
    UH = cv2.getTrackbarPos("UH", "TrackBars")
    US = cv2.getTrackbarPos("US", "TrackBars")
    UV = cv2.getTrackbarPos("UV", "TrackBars")

    # 定义对比度和亮度的调节值
    Ncnum = cv2.getTrackbarPos("NContrast", "TrackBars")
    Nbnum = cv2.getTrackbarPos("NBrightness", "TrackBars")
    Pcnum = cv2.getTrackbarPos("PContrast", "TrackBars")
    Pbnum = cv2.getTrackbarPos("PBrightness", "TrackBars")

    # 将hsv空间的底层值和顶层值进行归纳总结
    lower = np.array([LH, LS, LV])
    upper = np.array([UH, US, UV])

    # 使用对应的参数对图像进行操作,从而取得相应的roi区域
    adjusted = imutils.adjust_brightness_contrast(image,
                                                  contrast=float(Ncnum),
                                                  brightness=float(-Nbnum))
    adjusted2 = imutils.adjust_brightness_contrast(adjusted,
                                                   contrast=float(Pcnum),
                                                   brightness=float(Pbnum))
    image_hsv = cv2.cvtColor(adjusted2, cv2.COLOR_BGR2HSV)
    mask = cv2.inRange(image_hsv, lower, upper)
    image_res = cv2.bitwise_and(adjusted2, adjusted2, mask=mask)
    cv2.imshow("res", adjusted2)
    cv2.imshow("hsv", image_hsv)
    cv2.imshow("return", image_res)
Esempio n. 2
0
def display_image_grid(img_path):
    face_images = []
    image = cv2.imread(img_path)
    image = imutils.resize(image, width=600)
    output = None
    for angle in angles_agmentation:
        num_rows, num_cols = image.shape[:2]
        rotation_matrix = cv2.getRotationMatrix2D((num_cols/2, num_rows/2), angle, 1)
        image_rotation = cv2.warpAffine(image, rotation_matrix, (num_cols, num_rows))
        line = None 
        for brightness in brightness_agmentation:
            image_brightness = imutils.adjust_brightness_contrast(image_rotation, brightness=brightness)
            faces = exctract_faces(image_brightness)
            if len(faces) == 1:
                face_image = faces[0]["image"]
                face_image = cv2.resize(face_image, (50, 50))
                face_images.append(face_image)
                if line is None:
                    line = face_image
                else:
                    line = np.concatenate((line,face_image),axis=1)
        if output is None:
            output = line
        else:
            output = np.concatenate((output,line),axis=0)
    return output
Esempio n. 3
0
def embed_dataset(dataset_dir):
    people = [f for f in os.listdir(dataset_dir) if f != '.DS_Store']
    knownNames = []
    knownEmbeddings = []
    for person_name in tqdm(people):
        person_images_dir = os.path.join(dataset_dir, person_name)
        person_images_path = [
            os.path.join(person_images_dir, file_name) 
            for file_name in os.listdir(person_images_dir) 
            if file_name != '.DS_Store'
        ]
        person_images = [
            cv2.imread(imagePath)
            for imagePath in person_images_path
        ]
        for img in tqdm(person_images):
            image = imutils.resize(img, width=600)
            if True:
                for angle in angles_agmentation:
                    num_rows, num_cols = image.shape[:2]
                    rotation_matrix = cv2.getRotationMatrix2D((num_cols/2, num_rows/2), angle, 1)
                    image_rotation = cv2.warpAffine(image, rotation_matrix, (num_cols, num_rows))
                    for brightness in brightness_agmentation:
                        image_brightness = imutils.adjust_brightness_contrast(image_rotation, brightness=brightness)
                        faces = exctract_faces(image_brightness)
                        if len(faces) == 1:
                            face_image = faces[0]["image"]
                            vec = embed_face(face_image, embedder)
                            knownNames.append(person_name)
                            knownEmbeddings.append(vec.flatten())

    return knownNames, knownEmbeddings
Esempio n. 4
0
def adjust(img):
    brightness = float('50')
    contrast = float('-10')
    img = imutils.adjust_brightness_contrast(
        img,
        contrast=contrast,
        brightness=brightness,
    )
    return img
Esempio n. 5
0
 def adjust_brightness_dynamic(self):
     self.image = imutils.adjust_brightness_contrast(self.image, 0, 0)
     return self.image
Esempio n. 6
0
from __future__ import print_function
import argparse
import cv2
import os
from imutils import adjust_brightness_contrast

# construct the argument parser and parse the arguments
ap = argparse.ArgumentParser()
ap.add_argument("-i", "--image", required=True, help="path to input image")
ap.add_argument('-b', '--brightness', default=0,
                help='Brightness, negative is darker, positive is brighter')
ap.add_argument('-c', '--contrast', default=0,
                help='Contrast, positive value for more contrast')
args = vars(ap.parse_args())
brightness = float(args['brightness'])
contrast = float(args['contrast'])
file_name = os.path.abspath(args['image'])
if os.path.isfile(file_name) is False:
    print(file_name)
    print('Cannot open image, quitting...')
    exit()

image = cv2.imread(file_name)

cv2.namedWindow('Original')
cv2.namedWindow('Adjusted')
adjusted = adjust_brightness_contrast(image, contrast=contrast, brightness=brightness)
cv2.imshow('Original', image)
cv2.imshow('Adjusted', adjusted)
cv2.waitKey(0)
Esempio n. 7
0
def adjust_brightness_dynamic(image, brightness=0.0, contrast=0.0):
    out = imutils.adjust_brightness_contrast(image, brightness=brightness, contrast=contrast)
    return out