opencv find centre of face in facedetction
Question: I need to find the centre of a rectangle that gets put around a face when it's
detected in OpenCV. I am using Python in Visual Studio.

Here is the code I am running:

* * *
    
    
    #!/usr/bin/env python
    
    from cv2 import *
    
    import sys
    
    cascPath = sys.argv[1]
    faceCascade = CascadeClassifier(cascPath)
    
    video_capture = VideoCapture(0)
    
    while True:
        # Capture frame-by-frame
        ret, frame = video_capture.read()
    
        gray = cvtColor(frame, COLOR_BGR2GRAY)
    
        faces = faceCascade.detectMultiScale(
            gray,
            scaleFactor=1.1,
            minNeighbors=5,
            minSize=(30, 30),
            flags=CASCADE_SCALE_IMAGE
        )
    
    
        # Draw a rectangle around the faces
        for (x, y, w, h) in faces:
            rectangle(frame, (x, y), (x+w, y+h), (0, 255, 0), 2)
    
        font = FONT_HERSHEY_SIMPLEX
    
        # Draw text on the frame    
        putText(frame, 'Hayden' ,(10,100), font, 2,(255,255,255),2,LINE_AA)
    
        # Display the resulting frame
        imshow('Video', frame)
    
    
        if waitKey(1) & 0xFF == ord('q'):
            break
    
    # When everything is done, release the capture
    video_capture.release()
    destroyAllWindows()
    

* * *

All I want to do is find the centre of the rectangle, any help will be greatly
appreciated!


Answer: I'm really sorry but I don't know python. The code for this in C++ is:

    
    
    Point center = Point(rectangle.x + rectangle.width)/2, (rectangle.y + rectangle.height)/2);
    

I'd be surprised if this didn't translate almost exactly to python

