Saturday, June 1, 2013

OpenCV ARM - Hello World

Here is a sample application that utilizes OpenCV in my customized Debian disto. Sample codes are posted below. The demo simply displays images captured by the camera. This can be extended to utilize other opencv functions.
import as cv

cv.NamedWindow( "mycamera", 1 )
capture = cv.CreateCameraCapture( 0 )

while True:
    img = cv.QueryFrame( capture )
    cv.ShowImage( "mycamera", img )
    if cv.WaitKey(20) > 0:

cv.DestroyWindow( "mycamera" )

Below is the C/C++ equivalent of the above Python script.

#include <opencv2/highgui/highgui.hpp>
using namespace cv;

int main( int argc, const char** argv )
    cvNamedWindow( "mycamera", 1 ); // create camera window
    CvCapture *capture = cvCreateCameraCapture( 0 ); // start capturing frames from camera (i.e. /dev/video0 device)

        IplImage* img = cvQueryFrame( capture ); // grab and retrieve frame
        cvShowImage( "mycamera", img ); // display image within window
        if( waitKey(20) > 0 ) // press any key to exit (interval=20ms)
    // cleanups
    cvReleaseCapture( &capture ); // stop capturing/reading // not needed in python (?)
    cvDestroyWindow( "mycamera" ); // end camera window
    return 0;

- thanks to for formating the codes. (best viewed with Firefox browser)
- webcam can also be tested with guvcview (Applications Menu->Multimedia->guvcview)

1 comment:

  1. I will never Cheap Archeage Gold consider defeat and I will remove from my vocabulary such words and phrases as quit, cannot, unable, impossible, out of the question, improbable, failure, unworkable, hopeless, and retreat; for they are the words of fools. I will avoid despair but if this disease of the mind should infect me then I will work on in despair. I will toil and I will endure. I will ignore the Archeage Gold obstacles at my feet and keep mine eyes on the goals above my head, for Buy Archeage Gold I know that where dry desert ends, green grass grows.