Example #1
0
     def verification(self):
         ap = argparse.ArgumentParser()
         ap.add_argument("-i","--image", required=True, help="path to input image")
         args=vars(ap.parse_args())

         print("[INFO] starting video stream ...")
         vs = VideoSteam(usePiCamera=True).start()
         time.sleep(60.0)

         found =set()

         while True:

             frame=vs.read()
             frame=imutils.resize(frame,width=400)

             barcodes=pyzbar.decode(frame)
             for barcode in barcodes:
                 (x,y,w,h)= barcode.rect
                 cv2.retangle(image,(x,y),(x+w,y+h),(0,0,255),2)
             
                 barcodeData = barcode.data.decode("utf-8")
                 barcodeType = barcode.type

                 text= "{} ({})".format(barcodeData, barcodeType)
             cv2.putText(image,text,(x,y-10), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0,0,255),2)
             if barcodeData not in found:
                return None
             else:
                 found.intersection(barcodeData)
Example #2
0
def face_detect(path, file_name):
    img = cv2.imread(path)
    cascade = cv2.CascadeClassifier('/root/Semi/kyberi/body10/haarcascade_upperbody.xml')
    rects = cascade.detectMultiScale(img, 1.3, 4, cv2.cv.CV_HAAR_SCALE_IMAGE, (20,20))
    if len(rects) == 0:
        return False
    rects[:, 2:] += rects[:, :2]
    for x1, y1, x2, y2 in rects:
        cv2.retangle(img, (x1, y1), (x2, y2), (127, 255,0), 2)
        cv2.imwrite('%s/%s-%s' % (FACES_DIR, PCAP, file_name), img)
    return True
Example #3
0
def detect(grey, orig_img):
    faces = face_cascade.detectMultiScale(grey, 1.1, 5)
    for (x, y, w, h) in faces:
        cv2.retangle(orig_img, (x, y), (x + w, y + h), (255, 0, 0), 2)
        roi_grey = grey[y:y + h, x:x + w]
        roi_color = orig_img[y:y + h, x:x + w]
        smiles = smile_cascade.detectMultiScale(roi_grey, 1.7, 22)

        for (sx, sy, sw, sh) in smiles:
            cv2.rectangle(roi_color, (sx, sy), (sx + sw, sy + sh), (0, 255, 0))

        eye = eye_cascade.detectMultiscale(roi_grey, 1.1, 22)

        for (ex, ey, ew, eh) in eye:
            cv2.rectangle(roi_color, (ex, ey), (ex + ew, ey + eh), (0, 255, 0),
                          2)

    return orig_img
def face_detect(path, file_name):
    img = cv2.imread(path)
    # apply a classifier that is trained in advanced for detecting faces
    # in a front-facing orientation
    cascade = cv2.CascadeClassifier('/home/bytegirl/Desktop/haarcascade_upperbody.xml')
    # returns retangle coordinates that correspnd to where the face
    # was detected in the image.
    rects = cascade.detectMultiScale(img, 1.3, 4, cv2.cv.CV_HAAR_SCALE_IMAGE, (20,20))
    if len(rects) == 0:
        return False
    rects[:, 2:] += rects[:, :2]
    # highlight the faces in the image
    # draw a green retangle over the area
    for x1, y1, x2, y2 in rects:
        cv2.retangle(img, (x1, y1), (x2, y2), (127, 255,0), 2)
        # write out the resulting image
        cv2.imwrite('%s/%s-%s' % (FACES_DIR, PCAP, file_name), img)
    return True
Example #5
0
def face_detect(path, file_name):

    img = cv2.imread(path)
    cascade = cv2.CasecadeClassifier("haarcascade_frontalface_alt.xml")
    rects = cascade.detectMultiScale(img, 1.3, 4, cv2.cv.CV_HAAR_SCALE_IMAGE,
                                     (20, 20))

    if len(rects) == 0:
        return False

    rects[:, 2:] += rects[:, :2]

    # highlight the faces in the image
    for x1, y1, x2, y2 in rects:
        cv2.retangle(img, (x1, y1), (x2, y2), (127, 255, 0), 2)

    cv2.imwrite("%s/%s-%s" % (faces_directory, pcap_file, file_name), img)

    return True
def face_detect(path, file_name):
    img = cv2.imread(path)
    # apply a classifier that is trained in advanced for detecting faces
    # in a front-facing orientation
    cascade = cv2.CascadeClassifier(
        '/home/bytegirl/Desktop/haarcascade_upperbody.xml')
    # returns retangle coordinates that correspnd to where the face
    # was detected in the image.
    rects = cascade.detectMultiScale(img, 1.3, 4, cv2.cv.CV_HAAR_SCALE_IMAGE,
                                     (20, 20))
    if len(rects) == 0:
        return False
    rects[:, 2:] += rects[:, :2]
    # highlight the faces in the image
    # draw a green retangle over the area
    for x1, y1, x2, y2 in rects:
        cv2.retangle(img, (x1, y1), (x2, y2), (127, 255, 0), 2)
        # write out the resulting image
        cv2.imwrite('%s/%s-%s' % (FACES_DIR, PCAP, file_name), img)
    return True
Example #7
0
def face_mask_image():
    global RGB_image

    print('[Info] Loading Face Detector Model...')
    proto_Path = os.path.sep.join(['face_detector', 'deploy.prototxt'])
    weights_Path = os.path.sep.join(
        ['face_detection', 'res10_300x300_ssd_iter_140000.caffemodel'])

    net = cv2.dnn.readNet(proto_Path, weights_Path)

    print('[Info] loading face mask detector model........')
    # load the face mask detector model
    model = load_model('face_mask_detector.model')

    # load image input and grab the image spatial / dimensions

    image = cv2.imread('./images/out.jpg')

    (h, w) = image.shape[:2]

    # construct a blob from the image
    blob = cv2.dnn.blobFromImage(image, 1.0, (300, 300), (104.0, 177.0, 123.0))

    # pass the blob through the network and get the face user face_detection

    print('[Info] computing Face Detection......please wait')

    net.setInput(blob)

    user_detections = net.forward()

    # looping over user_detections
    for i in range(0, user_detections.shape[2]):
        # probability associated with user_detections

        confirm = user_detections[0, 0, i, 2]

        # filter weak user_detections by ensuring confirm is greater then min confirm

        if confirm > 0.5:
            # compute the x, y coordinates

            coor_box = user_detections[0, 0, i, 3:7] * np.array([w, h, w, h])
            (startX, startY, endX, endY) = coor_box.astype('int')

            # ensure the coor_box are with in the dimentions of the frame.
            (startX, startY) = (max(0, startX), max(0, startY))
            (endX, endY) = (min(w - 1, endX), min(h - 1, endY))

            # extract the face ROI, convert , convert iy from BGR to Rgb channel
            #   and resize it to 224 x224, and preprocess it.

            face_change = image[startY:endY, startX:endX]
            face_change = cv2.cvtColor(face_change, cv2.COLOR_BGB2RGB)
            face_change = cv2.resize(face_change, (224, 224))
            face_change = img_to_array(face_change)
            face_change = preprocess_input(face_change)
            face_change = np.expand_dims(face_change, axis=0)

            # pass the face_change through the model to determine if user has mask or not

            (with_mask, with_out_mask) = model.predict(face_change)[0]

            #determin the class label and color used to draw coor_box retangle output frame

            label = "Mask" if with_mask > with_out_mask else "No Mask"

            color = (0, 255, 0) if label == "Mask" else (0, 0, 255)

            # Probability in label
            label = "{}: {:.2f}%".format(label,
                                         max(with_mask, with_out_mask) * 100)

            # label retangle output frame

            cv2.putText(image, label, (startX, startY - 10),
                        cv2.FONT_HERSHEY_SIMPLEX, 0.45, color, 2)

            cv2.retangle(image, (startX, startY), (endX, endY), color, 2)

            RGB_image = cv2.cvrColor(image, cv2.COLOR_B2B2RGB)
Example #8
0
#!/usr/bin/env python
# coding: utf8
# author: youdi

import numpy as np
import cv2

img = np.zeros(shape=(512, 512, 3), dtype=np.uint8)

cv2.retangle(img, (384, 0), (510, 128), (0, 255, 0), 3)