Ask Your Question
0

what is conterpart of Mat frame_gray in python?

asked 2018-02-04 04:42:22 -0600

water gravatar image

updated 2018-02-04 05:46:30 -0600

i tried to convert these opencv code to python,but never worked_(:3 」∠)_
please help

    std::vector<Rect> faces;
    Mat frame_gray;
    cvtColor( frame, frame_gray, CV_BGR2GRAY );
    equalizeHist( frame_gray, frame_gray );
    face_cascade.detectMultiScale( frame_gray, faces, 1.1, 2, 0, Size(20, 20) );
     for( int i = 0; i < faces.size(); i++ )
     {
            Mat faceROI = frame_gray( faces[i] );
            Mat faceOrg = frame( faces[i] );
            blur(faceOrg, faceOrg, Size(25,25));  
            std::vector<Rect> eyes;
        }
        imshow( window_name, frame );
edit retag flag offensive close merge delete

Comments

sturkmen gravatar imagesturkmen ( 2018-02-04 05:06:41 -0600 )edit

1 answer

Sort by » oldest newest most voted
1

answered 2018-02-04 05:28:46 -0600

arh24 gravatar image

updated 2018-02-04 06:42:20 -0600

berak gravatar image


import numpy as np
import cv2
face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
eye_cascade = cv2.CascadeClassifier('haarcascade_eye.xml')
img = cv2.imread('sachin.jpg')
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

faces = face_cascade.detectMultiScale(gray, 1.3, 5)
for (x,y,w,h) in faces:
    cv2.rectangle(img,(x,y),(x+w,y+h),(255,0,0),2)
    roi_gray = gray[y:y+h, x:x+w]
    roi_color = img[y:y+h, x:x+w]
    eyes = eye_cascade.detectMultiScale(roi_gray)
    for (ex,ey,ew,eh) in eyes:
        cv2.rectangle(roi_color,(ex,ey),(ex+ew,ey+eh),(0,255,0),2)
   cv2.imshow('img',img)
edit flag offensive delete link more

Comments

thanks very much~

water gravatar imagewater ( 2018-02-04 05:49:15 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2018-02-04 04:42:22 -0600

Seen: 594 times

Last updated: Feb 04 '18