Cv is the Perl interface to the OpenCV computer vision library that originally developed by Intel.
I'm making this module to use the computer vision more easily like a slogan of perl "Easy things should be easy, hard things should be possible."
The features are as follows.
- Cv was made along the online reference manual of C in the OpenCV documentation. For details, please refer to the http://opencv.willowgarage.com/.
- You can use CreateSomething() as a constructors.
my $img = Cv->CreateImage([ 320, 240 ], IPL_DEPTH_8U, 3);
my $mat = Cv->CreateMat([ 240, 320 ], CV_8UC3);
- You can also use new as a constructor. But be careful when you use it because the arguments are same as CreateMat().
my $img = Cv::Image->new([ 240, 320 ], CV_8UC3);
my $img2 = $img->new;
- The OpenCV has a type IplImage* for handling an image object, and types CvMat*, CvMatND* and CvSparseMat* for a matrix object. These types are mapped as blessed reference of Cv::Image, Cv::Mat, Cv::MatND and Cv::SparseMat. The type of structures like CvSize and CvPoint are mapped as an array. For details, please refer to the typemap.
- You have to call cvReleaseImage() when you'll destroy the image object in the OpenCV application programs. But in the Cv, you don't have to call cvReleaseImage() because Perl calls DESTROY for cleanup. So the subroutine DESTROY has often been defined as an alias of cvReleaseImage(), cvReleaseMat(), ... and cvReleaseSomething().
- Some functions, eg. cvQueryFrame() return a reference but that cannot be destroyed. In this case, the reference is blessed with Cv::Somthing::Ghost, and identified. And disable destroying.
- You can use name of method, omitting "cv" from the OpenCV function name, and also use lowercase name beginning. For example, you can call cvCreateMat() as:
my $mat = Cv->CreateMat(240, 320, CV_8UC3);
my $mat = Cv->createMat(240, 320, CV_8UC3);
- When you omit the destination image or matrix (often named "dst"), Cv creates new destination if possible.
my $dst = $src->Add($src2);
- Some functions in the OpenCV can handle inplace that use source image as destination one. To tell requesting inplace, you can use \0 as NULL for the destination.
my $dst = $src->Flip(\0);
- cvAddS() and cvAdd() are integrated into Add(). Because we can identify them.
my $dst = $src->Add($src2); # calling cvAdd()
my $dst = $src->Add([ 1, 2, 3 ]); # cvAddS()
- cvGet1D() and cvGet2D() are integrated.
my $val = $src->Get($idx1); # calling cvGet1D()
my $val = $src->Get($idx1, $idx2); # cvGet2D()
- cvFillConvexPoly() handles the array of points CvPoint. The function also needs the number of elements separately. Because the array of the language C is only a pointer to the beginning of it. In the Perl, the array unlike in C, we can know the number of elements. So, you don't need to pass the number of elements for cvFindCornerSubPix(), cvCreateMatND() and so, too.
- cvMinMaxLoc() stores values in given variables.
$src->MinMaxLoc(my $min, my $max);
- In the Perl, you would think that even when multiple values returned to the caller might be more natural to use the return value like localtime and stat. But we chose to along the OpenCV documentation.
- We have a configuration to use Inline C. This makes it easy to test and extend a variety. How easy is as follows.
use Inline C => Config => %Cv::Config::C;
my $image = Cv->LoadImage("/path/to/image", CV_LOAD_IMAGE_COLOR);