Ask Your Question

AuroraPhields's profile - activity

2013-04-22 14:15:28 -0600 received badge  Critic (source)
2013-04-22 14:15:21 -0600 received badge  Supporter (source)
2013-04-21 13:49:32 -0600 received badge  Student (source)
2013-04-21 09:15:29 -0600 asked a question template matching: slow manual pixel access using integral image

I am trying to do a sort of template matching that looks for dark blobs in my image. I am using a template of a black square surrounded by a white square as the template and running this image across all valid x,y in the image of concern. I thought that it would be much faster than using the template matching functions to use an integral image and collect data from only 8 points for every x,y that I want to check since eventually I need to do this check for multiple sizes of the template.

However, my code has been exceedingly slow, so I think that what I am doing is not compatible with how OpenCV/numpy store and access data. What is the fastest way to do this sort of matching? Is the way I'm accessing the pixels in the image manually with a for loop the problem?

I'm using OpenCV 2.4 with python 2.7 and importing numpy. I'm passing a binary 250x400 pixel image to the function and my code is below:

def estimate_pupil(img, r): # estimates the x,y position of the pupil in img # REALLY REALLY SLOW RIGHT NOW

    # create an integral image ii to do fast pupil location estimation
    ii = cv2.integral(img);

    h = img.shape[0];
    w = img.shape[1];

    best = 0;
    bestx = 0;
    besty = 0;
    # loop through all positions x,y
            for y in range(h-6*r-1):
                    for x in range(w-6*r-1):
                            #print "(x,y) is " + str(x) + " " + str(y);
                            bright = ii[y+6*r,x+6*r] - ii[y+6*r,x] - \
                                    ii[y,x+6*r] - ii[y,x];
                            i = x+2*r;
                            j = y+2*r;
                            dark = ii[j+r,i+r] - ii[j+r,i] - \
                                    ii[j,i+r] - ii[j,i];
                            matchval = 2*dark - bright;
                            if matchval > best:
                                    best = matchval;
                                    bestx = i + r;
                                    besty = j + r;

    return bestx, besty;
2013-04-21 08:50:58 -0600 asked a question Usb splitter used to access multiple cameras

I am running on Mac OS X 10.7 and using OpenCV 2.4 with Python 2.7. I am trying to access two webcams on a single port with a usb splitter because my second port is giving my trouble (see below*).

I bought a usb splitter and have both webcams plugged in but I cannot figure out how to read both cameras from the same port. Ideally I would like to read them simultaneously, but if not I'd like to at least be able to alternate between the two without having to unplug one or the other. The problem is when both are plugged into the usb splitter regardless of position, opencv defaults to the logitech camera so I can never read from the lifecam without unplugging the logitech cam. Does anyone know how to access different ports from a usb splitter?


  • My original code using 2 usb ports fails for some reason even though QuickTime can access either camera on the second usb port

cameraEye = cv2.VideoCapture(1); cameraWorld = cv2.VideoCapture(2);

while True: frameWorldRetVal, frameWorld = cameraWorld.read(); scaledWorld = cv2.resize(frameWorld,None,fx=0.5,fy=0.5); cv2.imshow('TheWorld',scaledWorld); frameEyeRetVal, frameEye = cameraEye.read(); #code to process eye image

The code works fine when I use my friend's computer (also a Mac) and should work fine with mine but apparently my second usb port is faulty because I receive the following error when trying to access the second camera.

Cleaned up camera. OpenCV Error: Assertion failed (ssize.area() > 0) in resize, file /opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_tarballs_ports_graphics_opencv/opencv/work/opencv-2.4.4/modules/imgproc/src/imgwarp.cpp, line 1725 Traceback (most recent call last): File "gaze-tracker.py", line 768, in <module> scaledWorld = cv2.resize(frameWorld,None,fx=0.5,fy=0.5); cv2.error: /opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_tarballs_ports_graphics_opencv/opencv/work/opencv-2.4.4/modules/imgproc/src/imgwarp.cpp:1725: error: (-215) ssize.area() > 0 in function resize

It's definitely the second port (not the camera) because I've tried tried switching them and all sorts of combinations. QuickTime of course is able to access either camera from this port.

Any suggestions are appreciated!