0 Replies - 411 Views - Last Post: 14 May 2013 - 06:37 AM Rate Topic: -----

#1 lailailai  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 14-May 13

Get return value from cv.HaarDetectObjects() method

Posted 14 May 2013 - 06:37 AM

hello guys,please help me, i having trouble with getting return value from cv.HaarDetectObjects() method
which i already bold below.
i struggle this for these days already if can solve will be very thankful.

import sys
import cv2.cv as cv

def detect(image):
    image_size = cv.GetSize(image)
    print image_size
    #create grayscale version
    grayscale = cv.CreateImage(image_size,8,1)
    cv.CvtColor(image,grayscale,cv.CV_BGR2GRAY)

    #create storage
    print "Before Create Storage"
    storage = cv.CreateMemStorage(0)
    #cv.ClearMemStorage(storage)

    #equlize histogram
    print "Before Equlize histogram"
    cv.EqualizeHist(grayscale,grayscale)

    #detect objects
    print "Before Detect Objects"
    cascade = cv.Load('C:/OpenCV2.43/data/haarcascades/haarcascade_frontalface_alt.xml')
    faces = [b]cv.HaarDetectObjects(grayscale, cascade, storage, 1.2, 2,0,(20,20))[/b]
    print "After Detect Objects"
    if faces:
        print'face detected'
        for i in faces:
            print i
            cv.Rectangle(image,(i[0][0],1[0][1]),
                         (int(i[0][0] + i[0][2]), int(i[0][1] + i[0][3])),
                         cv.RGB(0,255,0),3,8,0)

if __name__ == "__main__":
    #print "OpenCV version : %s (%d,%d,%d)" %(cv.CV_VERSION,
    #                                         cv.CV_MAJOR_VERSION,
    #                                         cv.CV_MINOR_VERSION,
    #                                         cv.CV_SUBMINOR_VERSION)
    print "Press Esc to exit..."

    #create windows
    cv.NamedWindow('Camera',cv.CV_WINDOW_AUTOSIZE)

    #create capture device
    device = 0 # assume we want first device
    capture = cv.CreateCameraCapture(0)
    cv.SetCaptureProperty(capture,cv.CV_CAP_PROP_FRAME_WIDTH,640)
    cv.SetCaptureProperty(capture,cv.CV_CAP_PROP_FRAME_HEIGHT,480)

    # check capture device is ok
    if not capture:
        print"Error Opening Capture Device"
        sys.exit(1)
    else:
        print "Device Found"

    while True:
        print "inside while loop"
        frame = cv.QueryFrame(capture)
        if frame is None:
            break

        #mirror
        cv.Flip(frame,None,1)
        print "before detect"
        #face Detection
        detect(frame)
        print "after detect"
        #display webcam image
        cv.ShowImage('Camera',frame)

        #handle events
        k = cv.WaitKey(10)

        if k == 0x1b: #ESC
            print'ESC pressed. Exiting software...'
            break




Is This A Good Question/Topic? 0
  • +

Page 1 of 1