Ask Your Question

Revision history [back]

source code opencv

where i can find the source code of the functions below this code?(i saw on the internet page of github but i can't find any information of source code) best regards

port imutils import time import cv2 import time

initialize the camera and grab a reference to the raw camera capture

camera = cv2.VideoCapture(0) MODEL_MEAN_VALUES = (78.4263377603, 87.7689143744, 114.895847746) gender_list = ['Male', 'Female']

def initialize_caffe_model(): gender_net = cv2.dnn.readNetFromCaffe( "gender_net_definitions/deploy.prototxt", "models/gender_net.caffemodel")

return (gender_net)

def capture_loop(gender_net): font = cv2.FONT_HERSHEY_SIMPLEX # capture frames from the camera

for frame in camera.capture_continuous(rawCapture, format="bgr", use_video_port=True):

while(camera.isOpened()):
    start_time=time.time()
    ret, image = camera.read()
    face_cascade = cv2.CascadeClassifier('OpenCV/haarcascades/haarcascade_frontalface_alt.xml')
    gray = cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)
    faces = face_cascade.detectMultiScale(gray, 1.1, 5)
    print("Found "+str(len(faces))+" face(s)")

    #Draw a rectangle around every found face
    for (x,y,w,h) in faces:

cv2.rectangle(image,(x,y),(x+w,y+h),(255,255,0),2) face_img = image[y:y+h, x:x+w].copy() blob = cv2.dnn.blobFromImage(face_img, 1, (227, 227), MODEL_MEAN_VALUES) # Predict gender gender_net.setInput(blob) gender_preds = gender_net.forward() gender = gender_list[gender_preds[0].argmax()]

        print(gender)

        print("--- %s seconds ---" % (time.time() - start_time))
        overlay_text = "%s" % (gender)
        cv2.putText(image, overlay_text ,(x,y), font, 2,(255,255,255),2,cv2.LINE_AA)

    cv2.imshow("Image", image)

    key = cv2.waitKey(1) & 0xFF
click to hide/show revision 2
None

updated 2018-11-13 10:19:45 -0600

berak gravatar image

source code opencv

where i can find the source code of the functions below this code?(i saw on the internet page of github but i can't find any information of source code) best regards

port

import imutils
import time
import cv2
import time

time # initialize the camera and grab a reference to the raw camera capture

capture camera = cv2.VideoCapture(0) MODEL_MEAN_VALUES = (78.4263377603, 87.7689143744, 114.895847746) gender_list = ['Male', 'Female']

'Female'] def initialize_caffe_model(): gender_net = cv2.dnn.readNetFromCaffe( "gender_net_definitions/deploy.prototxt", "models/gender_net.caffemodel")

"models/gender_net.caffemodel")

    return (gender_net)

def capture_loop(gender_net): font = cv2.FONT_HERSHEY_SIMPLEX # capture frames from the camera

camera # for frame in camera.capture_continuous(rawCapture, format="bgr", use_video_port=True):

use_video_port=True):
    while(camera.isOpened()):
     start_time=time.time()
     ret, image = camera.read()
     face_cascade = cv2.CascadeClassifier('OpenCV/haarcascades/haarcascade_frontalface_alt.xml')
     gray = cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)
     faces = face_cascade.detectMultiScale(gray, 1.1, 5)
     print("Found "+str(len(faces))+" face(s)")

     #Draw a rectangle around every found face
     for (x,y,w,h) in faces:

cv2.rectangle(image,(x,y),(x+w,y+h),(255,255,0),2) face_img = image[y:y+h, x:x+w].copy() blob = cv2.dnn.blobFromImage(face_img, 1, (227, 227), MODEL_MEAN_VALUES) # Predict gender gender_net.setInput(blob) gender_preds = gender_net.forward() gender = gender_list[gender_preds[0].argmax()]

gender_list[gender_preds[0].argmax()]

            print(gender)

         print("--- %s seconds ---" % (time.time() - start_time))
         overlay_text = "%s" % (gender)
         cv2.putText(image, overlay_text ,(x,y), font, 2,(255,255,255),2,cv2.LINE_AA)

     cv2.imshow("Image", image)

     key = cv2.waitKey(1) & 0xFF