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 8647507
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T13:05:25+00:00 2026-06-12T13:05:25+00:00

Not quite sure where I’m going wrong – I’m trying to train OpenCV for

  • 0

Not quite sure where I’m going wrong – I’m trying to train OpenCV for object detection with +/- images that I’ve taken myself. All the steps work ok, but ultimately my Python script won’t read my XML cascade file (but will load one of the built-in face detection files).

For what it’s worth, I’m on Mac Lion running Python 2.7.3.

My process:

  1. Create a collection file with bounding boxes on the positive images
  2. Create a list of negative images
  3. Use opencv_createsamples using the following command: opencv_createsamples -info collection.txt -bg negativeImages.txt -vec positiveVectorFile.vec -num 20 -w 32 -h 24
  4. Check vector file: images are a bit squished but look ok
  5. Run traincascade program using the following command: opencv_traincascade -data directoryToStoreFiles -vec positiveVectorFile.vec -bg negativeImageList.txt -numPos 16 -numNeg 20 -numStages 5 -mem 1000 -maxHitRate 0.95 -w 32 -h 24

Then I run the following Python script (which works with the usual face-detection XML):

import cv
img = cv.LoadImage("test.jpg", 0)

# load detection file (various files for different views and uses)
cascade = cv.Load("cascade.xml")        # doesn't work
#cascade = cv.Load("frontalface.xml")   # works

# detect faces, return as list
detected = cv.HaarDetectObjects(img, cascade, cv.CreateMemStorage())

# iterate detected objects, drawing a rectangle around each
for (x,y, w,h), n in detected:
    cv.Rectangle(img, (x,y), (x+w, y+h), 255)

# create a window to display the results
windowTitle = "Test Cascade"
cv.NamedWindow(windowTitle, cv.CV_WINDOW_AUTOSIZE)

# display tested image until the escape key is pressed
while True:
    cv.ShowImage(windowTitle, img)

    # watch for escape key (ASCII 20)
    key = cv.WaitKey(20)
    if key == 27:

        # save the image to file is specified
        if saveIt == True:
            cv.SaveImage("detected.png", img)

        # ... and quit
        exit()

The result is the error:
cv2.error: The node does not represent a user object (unknown type?)

I’ve uploaded the cascade file here: http://pastebin.com/w7uRjyN7. Not sure if it’s my cascade file, some other problem along the way, or something obvious?

  • 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-12T13:05:26+00:00Added an answer on June 12, 2026 at 1:05 pm

    Well, it appears that cyberdecker’s suggestion was one of a few problems: that cv2 has entirely different commands for everything and is required when using opencv_traincascade. My code, which now works (though my cascade doesn’t quite yet):

    #import library - MUST use cv2 if using opencv_traincascade
    import cv2
    
    # rectangle color and stroke
    color = (0,0,255)       # reverse of RGB (B,G,R) - weird
    strokeWeight = 1        # thickness of outline
    
    # set window name
    windowName = "Object Detection"
    
    # load an image to search for faces
    img = cv2.imread("test.jpg")
    
    # load detection file (various files for different views and uses)
    cascade = cv2.CascadeClassifier("cascade.xml")
    
    # preprocessing, as suggested by: http://www.bytefish.de/wiki/opencv/object_detection
    # img_copy = cv2.resize(img, (img.shape[1]/2, img.shape[0]/2))
    # gray = cv2.cvtColor(img_copy, cv2.COLOR_BGR2GRAY)
    # gray = cv2.equalizeHist(gray)
    
    # detect objects, return as list
    rects = cascade.detectMultiScale(img)
    
    # display until escape key is hit
    while True:
    
        # get a list of rectangles
        for x,y, width,height in rects:
            cv2.rectangle(img, (x,y), (x+width, y+height), color, strokeWeight)
    
        # display!
        cv2.imshow(windowName, img)
    
        # escape key (ASCII 27) closes window
        if cv2.waitKey(20) == 27:
            break
    
    # if esc key is hit, quit!
    exit()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm not quite sure where I'm going wrong with this implementation and what adjustment
Not quite sure how to go about describing what it is I'm trying to
Im not quite sure what I am doing wrong here, I have folloed the
I'm not quite sure what's going on, but several issues are occurring on our
Not quite sure what's going sideways here. The below function should clear all the
Not quite sure I have the question fully formed, but what I'm trying to
Im not quite sure. I have a table that consists of 2 foreach loops(2
I am not quite sure of what i am doing wrong, basically in my
Not quite sure how to phrase the title here. The issue is that I
Not quite sure if I asked correctly, but basically I have an array that

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.