Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7087111
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:38:00+00:00 2026-05-28T07:38:00+00:00

i’m new to image processing and opencv, but so far the easy to understand

  • 0

i’m new to image processing and opencv, but so far the easy to understand functions and good documentation have enabled me to try out and understand upto some level code like facedetection etc.

Now when i detect the faces in the webcam video stream, the program draws a square around the face. Now i want that much area of the image, in the square around the face, to be created as an another image. From what i’ve been doing, i’m getting a rectangular area of the image in which the face is not even present.

i’ve used the cv.GetSubRect() and understood its use. Like for eg:

img=cv.LoadImage("C:\opencv\me.jpg")
sub=cv.GetSubRect(img, (700,525,200,119))
cv.NamedWindow("result",1)
cv.ShowImage("result",sub)
  • gives me the cropped picture of my eye.

But i can’t get the face in my face and eye detection program.
Here’s what i’ve done:

min_size = (17,17)
        #max_size = (30,30)

        image_scale = 2
        haar_scale = 2

        min_neighbors = 2
        haar_flags = 0

        # Allocate the temporary images
        gray = cv.CreateImage((image.width, image.height), 8, 1)
        smallImage = cv.CreateImage((cv.Round(image.width / image_scale),cv.Round (image.height / image_scale)), 8 ,1)
        #eyeregion = cv.CreateImage((cv.Round(image.width / image_scale),cv.Round (image.height / image_scale)), 8 ,1)
        #cv.ShowImage("smallImage",smallImage)

        # Convert color input image to grayscale
        cv.CvtColor(image, gray, cv.CV_BGR2GRAY)

        # Scale input image for faster processing
        cv.Resize(gray, smallImage, cv.CV_INTER_LINEAR)

        # Equalize the histogram
        cv.EqualizeHist(smallImage, smallImage)

        # Detect the faces
        faces = cv.HaarDetectObjects(smallImage, faceCascade, cv.CreateMemStorage(0),
        haar_scale, min_neighbors, haar_flags, min_size)
        #, max_size)

# If faces are found
        if faces:
                for ((x, y, w, h), n) in faces:
                # the input to cv.HaarDetectObjects was resized, so scale the
                # bounding box of each face and convert it to two CvPoints
                        pt1 = (int(x * image_scale), int(y * image_scale))
                        pt2 = (int((x + w) * image_scale), int((y + h) * image_scale))
                        cv.Rectangle(image, pt1, pt2, cv.RGB(255, 0, 0), 3, 4, 0)
                        face_region = cv.GetSubRect(image,(x,int(y + (h/4)),w,int(h/2)))
                        cv.ShowImage("face",face_region)


 cv.SetImageROI(image, (pt1[0],
                        pt1[1],
                        pt2[0] - pt1[0],
                        int((pt2[1] - pt1[1]) * 0.7)))
                eyes = cv.HaarDetectObjects(image, eyeCascade,
                cv.CreateMemStorage(0),
                eyes_haar_scale, eyes_min_neighbors,
                eyes_haar_flags, eyes_min_size)    

            if eyes:
                    # For each eye found
                    for eye in eyes:

                            eye[0][0],eye[0][1] are x,y co-ordinates of the top-left corner of detected eye
                            eye[0][2],eye[0][3] are the width and height of the cvRect of the detected eye region (i mean c'mon, that can be made out from the for loop of the face detection)
                            # Draw a rectangle around the eye


                            ept1 = (eye[0][0],eye[0][1])
                            ept2 = ((eye[0][0]+eye[0][2]),(eye[0][1]+eye[0][3]))

                            cv.Rectangle(image,ept1,ept2,cv.RGB(0,0,255),1,8,0) # This is working.. 


                            ea = ept1[0]
                            eb = ept1[1]
                            ec = (ept2[0]-ept1[0])
                            ed = (ept2[1]-ept1[1])

                            # i've tried multiplying with image_scale to get the eye region within
                            # the window of eye but still i'm getting just a top-left area of the 
                            # image, top-left to my head. It does make sense to multiply with image_scale right?




                            eyeregion=cv.GetSubRect(image, (ea,eb,ec,ed))
                            cv.ShowImage("eye",eyeregion)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T07:38:01+00:00Added an answer on May 28, 2026 at 7:38 am

    I hope this code is from OpenCV/samples/Python. There is a small mistake in the arguments you have given for the co-ordinates inside cv.GetSubRect. Please replace last two lines of above program with following:

    a=pt1[0]
    b=pt1[1]
    c=pt2[0]-pt1[0]
    d=pt2[1]-pt1[1]
    face_region = cv.GetSubRect(image,(a,b,c,d))
    cv.ShowImage("face",face_region) 
    

    Make sure, you have no false detection or multiple detection.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a French site that I want to parse, but am running into
I have a jquery bug and I've been looking for hours now, I can't
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I am trying to understand how to use SyndicationItem to display feed which is
this is what i have right now Drawing an RSS feed into the php,
I want use html5's new tag to play a wav file (currently only supported

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.