source code opencv [closed]

asked 2018-11-13 10:15:19 -0600

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

berak gravatar image

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

import 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
edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by sturkmen
close date 2020-10-18 10:31:49.261621

Comments

do you have a link for that code ?

berak gravatar imageberak ( 2018-11-13 10:20:19 -0600 )edit
1

Here is link: gender detection

supra56 gravatar imagesupra56 ( 2018-11-13 10:50:49 -0600 )edit
1

hehe, gillevi used to hang around here, too, once ;)

berak gravatar imageberak ( 2018-11-13 10:54:27 -0600 )edit

@ander5991 -- ofc. the opencv (c++) src code is here

(but i doubt, that's what you wanted to know. it far more sounds like you only copypasted the python code above, and now need an explanation ...)

maybe, reading the blogposts mentioned above would help ?

berak gravatar imageberak ( 2018-11-14 01:09:17 -0600 )edit