Cv - helps you to make something around computer vision.
use Cv; my $image = Cv->LoadImage("/path/to/image", CV_LOAD_IMAGE_COLOR); $image->ShowImage("image"); Cv->WaitKey;
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.
Cvwas made along the online reference manual of C in the OpenCV documentation. For details, please refer to the http://opencv.willowgarage.com/.
CreateSomething()as a constructors.
my $img = Cv->CreateImage([ 320, 240 ], IPL_DEPTH_8U, 3); my $mat = Cv->CreateMat([ 240, 320 ], CV_8UC3);
newas a constructor, e.g. instead of
Cv::Mat->newis CreateMat(). In the calling parameters, there are some difference in CreateImage() and CreateMat(). But there are no difference in
Cv::something->new. This is because we create same object without knowing about original object in the
my $img = Cv::Image->new([ 240, 320 ], CV_8UC3);
You can omit parameters and that will be inherited.
my $img2 = $img->new; my $img3 = $img->new(CV_8UC1); # Cv::Image->new([240, 320], CV_8UC1)
IplImage*for handling an image object, and types
CvSparseMat*for a matrix object. These types are mapped as blessed reference of
Cv::SparseMat. The type of structures like
CvPointare mapped as an array. For details, please refer to the typemap.
Cv, you don't have to call cvReleaseImage() because Perl calls
DESTROYfor cleanup. So the subroutine
DESTROYhas 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.
my $mat = Cv->CreateMat(240, 320, CV_8UC3); my $mat = Cv->createMat(240, 320, CV_8UC3);
Cvcreates new destination if possible.
my $dst = $src->Add($src2);
NULLfor the destination.
my $dst = $src->Flip(\0);
my $dst = $src->Add($src2); # calling cvAdd() my $dst = $src->Add([ 1, 2, 3 ]); # cvAddS()
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.
$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
stat. But we chose to along the OpenCV documentation.
Inline C. This makes it easy to test and extend a variety. How easy is as follows.
use Cv::Config; use Inline C => Config => %Cv::Config::C;
We'll show you the tips about using
Cv that we studied from users.
use Cv; my $img = Cv::Image->new([240, 320], CV_8UC3); $img->zero->circle([ 100, 100 ], 100, CV_RGB(255, 100, 100)); print "Content-type: image/jpg\n\n"; print $img->encodeImage(".jpg")->ptr;
You can use that to convert for Imager.
use Imager; my $imager = Imager->new(data => $img->encodeImage(".ppm")->ptr);
Cvheader to the data defined in the Perl world. It is not a good manner, but you can get the way to access to that.
my $data = pack("C*", 0 .. 255); my $mat = Cv::Mat->mew([16, 16], CV_8UC1, $data); substr($data, 0x41, 1) = 'x'; print chr($mat->get([4, 1])->), "\n";
We rewrote some OpenCV samples in
Cv, and put them in sample/.
bgfg_codebook.pl calibration.pl camshiftdemo.pl capture.pl contours.pl convexhull.pl delaunay.pl demhist.pl dft.pl distrans.pl drawing.pl edge.pl facedetect.pl fback_c.pl ffilldemo.pl find_obj.pl fitellipse.pl houghlines.pl image.pl inpaint.pl kalman.pl kmeans.pl laplace.pl lkdemo.pl minarea.pl morphology.pl motempl.pl mser_sample.pl polar_transforms.pl pyramid_segmentation.pl squares.pl stereo_calib.pl stereo_match.pl tiehash.pl video.pl watershed.pl
Cv::Arr, you don't need to consider about adjusting the names, e.g. omitting "cv", lowercase name beginning, because
AUTOLOADworks in these packages. In other places, you can use
Cv::TieArr, too. See
Yuta Masuda, <firstname.lastname@example.org>
Copyright (c) 2010, 2011 by Masuda Yuta.
All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.