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

  • Home
  • SEARCH
  • 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 9078995
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T19:44:52+00:00 2026-06-16T19:44:52+00:00

I am trying to detect the face from the webcam using opencv python on

  • 0

I am trying to detect the face from the webcam using opencv python on ubuntu. I got this online code and tried running this program and I am getting the as NULL array pointer is passed, I guess it is not able to capture the video from webcam but with the same code(only capture camera) I got the camera on and it captured the video. Here is my code:

import cv
from opencv import highgui
HAAR_CASCADE_PATH = "/home/OpenCV-2.3.1/data/haarcascades/haarcascade_frontalface_default.xml"

CAMERA_INDEX = 0 
def detect_faces(image):
 faces = []
 detected = cv.HaarDetectObjects(image, cascade, storage, 1.2, 2, cv.CV_HAAR_DO_CANNY_PRUNING, (100,100))
if detected:
    for (x,y,w,h),n in detected:
        faces.append((x,y,w,h))
return faces

if __name__ == "__main__":
cv.NamedWindow("Video", cv.CV_WINDOW_AUTOSIZE)

capture = cv.CaptureFromCAM(0)
storage = cv.CreateMemStorage()
cascade = cv.Load(HAAR_CASCADE_PATH)
print cascade
faces = []

i = 0
c = -1
while (c == -1):
    image = cv.QueryFrame(capture)


    # Only run the Detection algorithm every 5 frames to improve performance
    #if i%5==0:
    faces = detect_faces(image)
    #print image

    for (x,y,w,h) in faces:
        cv.Rectangle(image, (x,y), (x+w,y+h), 255)


    cv.ShowImage("w1", image)
    i += 1

And Error I am getting is:

Traceback (most recent call last):
File "/home/OpenCV-2.3.1/webcam_try.py", line 38, in <module>
faces = detect_faces(frame)
File "/home/OpenCV-2.3.1/webcam_try.py", line 13, in detect_faces
detected = cv.cvHaarDetectObjects(frame, cascade, storage, 1.2, 2,    cv.CV_HAAR_DO_CANNY_PRUNING,(100,100))
 File "/usr/lib/pymodules/python2.7/opencv/cv.py", line 1626, in cvHaarDetectObjects
 return _cv.cvHaarDetectObjects(*args)
 NotImplementedError: Wrong number of arguments for overloaded function     'cvHaarDetectObjects'.
 Possible C/C++ prototypes are:
  cvHaarDetectObjects_Shadow(CvArr const *,CvHaarClassifierCascade *,CvMemStorage *,double,int,int,CvSize)
  cvHaarDetectObjects_Shadow(CvArr const *,CvHaarClassifierCascade *,CvMemStorage *,double,int,int)
  cvHaarDetectObjects_Shadow(CvArr const *,CvHaarClassifierCascade *,CvMemStorage *,double,int)
  cvHaarDetectObjects_Shadow(CvArr const *,CvHaarClassifierCascade *,CvMemStorage *,double)
  cvHaarDetectObjects_Shadow(CvArr const *,CvHaarClassifierCascade *,CvMemStorage *)
  • 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-06-16T19:44:53+00:00Added an answer on June 16, 2026 at 7:44 pm

    Your code worked fine for me (although I’m running OpenCV v2.4.3 instead of your version, 2.3.1). I started working from the same online code (posted here) last week, and I eventually gave up on using cv and switched to the new cv2 library.

    So. I’ve updated your code so that it uses the new cv2 interface.

    The cv2 Python interface for running Haar Cascade Classifiers is much easier to use. Check out the documentation for cv2.CascadeClassifier.detectMultiScale() here. The new cv2 interface simplifies your code significantly. Here are the highlights:

    1. You no longer have to worry about creating memory buffers.
    2. The results that are returned from detectMultiScale come back in a super useful form, eliminating the need for your old code’s detect_faces() function!
    3. You only need to provide one parameter: the image itself. All other parameters are optional. I’ve included the parameters you were using in the revised code below, but feel free to remove them.

    One piece of advice: if your code is running slowly, one of the best things you can do is increase the minSize. For my webcam, using (100,100) causes a super-slow frame rate of about 0.2fps. Changing it to (300,300) boosts it to the respectable 20fps.

    The code should work on your existing installation since you’re running 2.3.1, but if it doesn’t then try upgrading to the latest version.

    import cv2
    import cv2.cv as cv
    
    HAAR_CASCADE_PATH = "/home/OpenCV-2.3.1/data/haarcascades/haarcascade_frontalface_default.xml";
    
    CAMERA_INDEX = 0;
    
    if __name__ == "__main__":
    
        # Open window, load webcam and load Haar cascade classifier
        cv2.namedWindow("Video", cv.CV_WINDOW_AUTOSIZE)
        capture = cv2.VideoCapture(CAMERA_INDEX);
        cascade = cv2.CascadeClassifier(HAAR_CASCADE_PATH);
    
        i = 0;
    
        while True:
            # Grab frame from webcam
            retVal, image = capture.read(); # note: ignore retVal
    
            # Only run the Detection algorithm every 5 frames to improve performance
            #if i%5==0:
            faces = cascade.detectMultiScale(image, scaleFactor=1.2, 
                                            minNeighbors=2, minSize=(100,100), 
                                            flags=cv.CV_HAAR_DO_CANNY_PRUNING);
    
            # Draw rectangles on image, and then show it
            for (x,y,w,h) in faces:
                cv2.rectangle(image, (x,y), (x+w,y+h), 255)
            cv2.imshow("Video", image)
    
            i += 1;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to detect 7 digit numbers from plain text and this is the
I used the code from here to find Face. Im trying to draw both
We're trying to detect usage of global variables in our js code by using
I'm trying to develop a software where can detect face recognition using Kinect. Until
I'm trying to use opencv to save frames from a webcam as jpgs or
I am trying to detect an http response code of 302. This is my
I am trying to detect when a route transition occurs. I've located this code
What I am currently trying to do is use the Face API to detect
Trying to detect left click vs right click (without using jQuery!) and I have
I am trying to detect whether a block of text (from a textarea) contains

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.