Ask Your Question

ianymu's profile - activity

2019-09-17 10:37:01 -0600 received badge  Notable Question (source)
2017-05-06 07:39:04 -0600 received badge  Popular Question (source)
2016-06-14 16:54:36 -0600 received badge  Popular Question (source)
2014-04-25 16:44:20 -0600 received badge  Editor (source)
2014-04-25 16:41:31 -0600 asked a question Anyone use the Python (facedetect.py) got the problem with TypeError?

Recently, I use the python example (Facedetect.py)

But I get the problem with that

File "facedetect.py", line 63, in (module)

cascade = cv.Load(options.cascade)

TypeError: OpenCV returned Null

I am really confused with that problem, and really want solve that problem as soon as possible, anyone can help me, please?

the Code is

#!/usr/bin/python
The program finds faces in a camera image or video stream and displays a red box around them.
import sys
import cv2.cv as cv
from optparse import OptionParser
#!/usr/bin/python
The program finds faces in a camera image or video stream and displays a red box around them.

import sys
import cv2.cv as cv
from optparse import OptionParser     
min_size = (20, 20)
image_scale = 2
haar_scale = 1.2
min_neighbors = 2
haar_flags = 0
def detect_and_draw(img, cascade):
# allocate temporary images
    gray = cv.CreateImage((img.width,img.height), 8, 1)
    small_img = cv.CreateImage((cv.Round(img.width / image_scale),
                   cv.Round (img.height / image_scale)), 8, 1)

    # convert color input image to grayscale
    cv.CvtColor(img, gray, cv.CV_BGR2GRAY)
    # scale input image for faster processing
    cv.Resize(gray, small_img, cv.CV_INTER_LINEAR)
    cv.EqualizeHist(small_img, small_img)

    if(cascade):
        t = cv.GetTickCount()
        faces = cv.HaarDetectObjects(small_img, cascade, cv.CreateMemStorage(0),
                                     haar_scale, min_neighbors, haar_flags, min_size)
        t = cv.GetTickCount() - t
        print "time taken for detection = %gms" % (t/(cv.GetTickFrequency()*1000.))
        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(img, pt1, pt2, cv.RGB(255, 0, 0), 3, 8, 0)

    cv.ShowImage("video", img)

if __name__ == '__main__':
    parser = OptionParser(usage = "usage: %prog [options] [filename|camera_index]")
    parser.add_option("-c", "--cascade", action="store", dest="cascade", type="str", help="Haar cascade file, default %default", default = "../data/haarcascades/haarcascade_frontalface_alt.xml")
    (options, args) = parser.parse_args()

    cascade = cv.Load(options.cascade)
    if len(args) != 1:
        parser.print_help()
        sys.exit(1)
    input_name = args[0]
    if input_name.isdigit():
        capture = cv.CreateCameraCapture(int(input_name))
    else:
        capture = None

    cv.NamedWindow("video", 1)

    #size of the video
    width = 160
    height = 120

    if width is None:
        width = int(cv.GetCaptureProperty(capture, cv.CV_CAP_PROP_FRAME_WIDTH))
    else:
        cv.SetCaptureProperty(capture,cv.CV_CAP_PROP_FRAME_WIDTH,width)

    if height is None:
    height = int(cv.GetCaptureProperty(capture, cv.CV_CAP_PROP_FRAME_HEIGHT))
    else:
    cv.SetCaptureProperty(capture,cv.CV_CAP_PROP_FRAME_HEIGHT,height)

    if capture:
        frame_copy = None
        while True:

            frame = cv.QueryFrame(capture)
            if not frame:
                cv.WaitKey(0)
                break
            if not frame_copy:
                frame_copy = cv.CreateImage((frame.width,frame.height),
                                            cv.IPL_DEPTH_8U, frame.nChannels)

            if frame.origin == cv.IPL_ORIGIN_TL:
               cv.Copy(frame, frame_copy)
            else:
                cv.Flip(frame, frame_copy, 0)

            detect_and_draw(frame_copy, cascade)

            if cv.WaitKey(10) >= 0:
                break
    else:
        image = cv.LoadImage(input_name, 1)
            detect_and_draw(image, cascade)
            cv.WaitKey(0)

        cv.DestroyWindow("video")
2014-04-22 11:27:17 -0600 asked a question The Opencv problem with OpenCV Error: Bad argument (Array should be CvMat or IplImage) in cvGetSize

Recently, I do my final project for my bachelor degree with Beaglebone Black.

I got problems is: 1: when I run python program like following command with pyhton using the Ubuntu (XFCE Desktop) connect with Beaglebone Black

!/usr/bin/python

import cv2.cv as cv iport time

cv.NamedWindow("camera", 1)

capture = cv.CaptureFromCAM(0) cv.SetCaptureProperty(capture, 3, 360) cv.SetCaptureProperty(capture, 4, 240)

while True: img = cv.QueryFrame(capture)

 cv.Smooth(img,img,cv.CV_BLURK,3)
 hue_img = cv.CreateImage(cv.GetSize(img), 8, 3)
 cv.CvtColor(img,hue_img, cv.CV_BGR2HSV)

 threshold_img = cv.CreateImage(cv.GetSize(hue_img), 8, 1)
 cv.InRangeS(hue_img, (38, 120, 60), (75, 255, 255), threshold_img)

 cv.ShowImage("Color Tracking", img)
 cv.ShowImage("threshold", threshold_img)

 if cv.WaitKey(10) == 27:
        break

and then, I run this python file use "./name.py"

**it show : init done OpenCV Error: Bad argument (Array should be CvMat or IplImage) in cvGetSize, file /home/ubuntu/finalproject/(this is my opencv directory)

opencv-2.4.7/modules/core/src/array.cpp, line 1238 Traceback (most recent call last): File “./example.py”, line 16, in <module> hug_img = cv.CreateImage(cv.Getsize(img), 8, 3) cv2.erro: Array should be CvMat or IplImage**

Should I re-install OpenCV on my Beaglebone Black Board, or reset something?

Thank you