HunterDavis.com 4.0!

19Dec/075

Re-Writing the laser pointer paint program (image processing) in C/C++ – 10x speed improvement

This should significantly increase our capture and processing speed. First, install libcv1 in ubuntu, I like to get the documentation and python bindings as well, and these will install libcv1 anyway. sudo aptitdue install python-cv opencv-doc Now we'll start writing some C code. As I have the benefit of writing this article after the code, I know that one can render/display 30fps without processing, and can render/display without lag with processing as well (thank you compiled code!). You can compile opencv code in linux using the following command:

gcc `pkg-config --cflags opencv` `pkg-config --libs opencv` -o MY_PROJECT_RUNME MY_PROJECT.cpp

Well that's simple enough. The structure of the program has a few changes.

  1. Program takes first command line argument as the image filter size (try 2-10 for good results)
  2. Program no longer does image subtraction for a mask over the image, it's direct processing now
  3. Program is significantly (10x) faster, depending on speed of camera frame grabs
  4. Check out the openCV tutorial for grabbing images from a camera, then check out the code below..
  5. You can snag it here
  6. Also, please note that 'escape' will end the loop and finish the program
Comments (5) Trackbacks (0)
  1. jtemmerde gros connard

  2. Do you have a video of the laser pointer painting in action??

  3. Hey, sorry no I don’t have a video handy. Let me know if you make one and I’ll post it if you like. Once my schedule clears up a bit i’m planning on retooling it again in assembler or C++, and I’ll definitely make a vid of that.

  4. I compiled on windows, works good fixed a couple of memory leaks and it ran much faster.. I’ll submit a proper patch if you email me.

    // ADD After for loop
    cvReleaseImage(&frame); // cloned image

    // reduces cloning/creating & fixes leak
    //a helper function to convert from color to gray
    IplImage* convert_grayscale(IplImage *img)
    {
    IplImage *gray_image, *gray_img0;

    //check image is it gray or not if nor convert it to the gray
    if(img->nChannels!=1)
    {
    //convert original image to gray_scale image
    gray_image = cvCreateImage(cvSize( img->width, img->height), 8, 1 );
    cvCvtColor(img, gray_image, CV_RGB2GRAY );
    }
    else
    {
    gray_image = cvCloneImage(img);
    }

    return gray_image;
    }

  5. Hey Leaks,

    Looks good! I didn’t know if people were still interested in this, thanks for the update. If you want to send in a patch that’d be cool, I’m sure it’d be helpful to others. Thanks!


Leave a comment


No trackbacks yet.