PDL-OpenCV
view release on metacpan or search on metacpan
use PDL::OpenCV::Videoio;
use PDL::OpenCV::Imgproc;
use PDL::OpenCV::Objdetect;
use PDL::OpenCV::Highgui;
|],
[act => q|
# initialise some objects
$cap = PDL::OpenCV::VideoCapture->new4(0);
$lsd = PDL::OpenCV::LineSegmentDetector->new;
($facedata) = grep -f, map "$_/haarcascades/haarcascade_frontalface_alt.xml",
qw(/usr/share/opencv4 /usr/local/share/opencv4);
$cc = $facedata ? PDL::OpenCV::CascadeClassifier->new2($facedata) : undef;
|],
[act => q|
print <<'EOF';
Toggles: 'l' lines, 'm' mirror, 'f' face-detection (if Haar cascades found)
'q' in the window quits
EOF
($showlines, $mirror, $face) = (1, 1, 1);
while (1) {
($image,$res) = $cap->read;
last if !$res;
$image = $image->slice(',-1:0') if $mirror;
$gray = cvtColor($image, COLOR_BGR2GRAY);
if ($showlines) {
($lines) = $lsd->detect($gray);
GENERATED/PDL/OpenCV/Objdetect.pm view on Meta::CPAN
$res = $obj->load($filename);
Parameters:
=over
=item filename
Name of the file from which the classifier is loaded. The file may contain an old
HAAR classifier trained by the haartraining application or a new cascade classifier trained by the
traincascade application.
=back
=cut
#line 231 "Objdetect.pm"
#line 274 "../genpp.pl"
GENERATED/PDL/OpenCV/Objdetect.pm view on Meta::CPAN
=head2 read
=for ref
Reads a classifier from a FileStorage node.
=for example
$res = $obj->read($node);
@note The file may contain a new cascade classifier (trained traincascade application) only.
=cut
#line 250 "Objdetect.pm"
#line 958 "/home/osboxes/.perlbrew/libs/perl-5.32.0@normal/lib/perl5/x86_64-linux/PDL/PP.pm"
GENERATED/PDL/OpenCV/Objdetect.pm view on Meta::CPAN
Detects objects of different sizes in the input image. The detected objects are returned as a list
of rectangles. NO BROADCASTING.
=for example
$objects = $obj->detectMultiScale($image); # with defaults
$objects = $obj->detectMultiScale($image,$scaleFactor,$minNeighbors,$flags,$minSize,$maxSize);
The function is parallelized with the TBB library.
@note
- (Python) A face detection example using cascade classifiers can be found at
opencv_source_code/samples/python/facedetect.py
Parameters:
=over
=item image
Matrix of the type CV_8U containing an image where objects are detected.
GENERATED/PDL/OpenCV/Objdetect.pm view on Meta::CPAN
Parameter specifying how much the image size is reduced at each image scale.
=item minNeighbors
Parameter specifying how many neighbors each candidate rectangle should have
to retain it.
=item flags
Parameter with the same meaning for an old cascade as in the function
cvHaarDetectObjects. It is not used for a new cascade.
=item minSize
Minimum possible object size. Objects smaller than that are ignored.
=item maxSize
Maximum possible object size. Objects larger than that are ignored. If `maxSize == minSize` model is evaluated on single scale.
=back
GENERATED/PDL/OpenCV/Objdetect.pm view on Meta::CPAN
Parameter specifying how much the image size is reduced at each image scale.
=item minNeighbors
Parameter specifying how many neighbors each candidate rectangle should have
to retain it.
=item flags
Parameter with the same meaning for an old cascade as in the function
cvHaarDetectObjects. It is not used for a new cascade.
=item minSize
Minimum possible object size. Objects smaller than that are ignored.
=item maxSize
Maximum possible object size. Objects larger than that are ignored. If `maxSize == minSize` model is evaluated on single scale.
=back
GENERATED/PDL/OpenCV/Objdetect.pm view on Meta::CPAN
#line 274 "../genpp.pl"
=head2 convert
=for ref
=for example
$res = PDL::OpenCV::CascadeClassifier::convert($oldcascade,$newcascade);
=cut
#line 617 "Objdetect.pm"
#line 394 "../genpp.pl"
=head1 METHODS for PDL::OpenCV::HOGDescriptor
Objdetect/funclist.pl view on Meta::CPAN
(
['','groupRectangles','@overload',0,'void',['vector_Rect','rectList','',['/IO','/Ref']],['vector_int','weights','',['/O','/Ref']],['int','groupThreshold','',[]],['double','eps','0.2',[]]],
['CascadeClassifier','empty','@brief Checks whether the classifier has been loaded.',1,'bool'],
['CascadeClassifier','load','@brief Loads a classifier from a file.
@param filename Name of the file from which the classifier is loaded. The file may contain an old
HAAR classifier trained by the haartraining application or a new cascade classifier trained by the
traincascade application.',1,'bool',['String','filename','',['/C','/Ref']]],
['CascadeClassifier','read','@brief Reads a classifier from a FileStorage node.
@note The file may contain a new cascade classifier (trained traincascade application) only.',1,'bool',['FileNode','node','',['/C','/Ref']]],
['CascadeClassifier','detectMultiScale','@brief Detects objects of different sizes in the input image. The detected objects are returned as a list
of rectangles.
@param image Matrix of the type CV_8U containing an image where objects are detected.
@param objects Vector of rectangles where each rectangle contains the detected object, the
rectangles may be partially outside the original image.
@param scaleFactor Parameter specifying how much the image size is reduced at each image scale.
@param minNeighbors Parameter specifying how many neighbors each candidate rectangle should have
to retain it.
@param flags Parameter with the same meaning for an old cascade as in the function
cvHaarDetectObjects. It is not used for a new cascade.
@param minSize Minimum possible object size. Objects smaller than that are ignored.
@param maxSize Maximum possible object size. Objects larger than that are ignored. If `maxSize == minSize` model is evaluated on single scale.
The function is parallelized with the TBB library.
@note
- (Python) A face detection example using cascade classifiers can be found at
opencv_source_code/samples/python/facedetect.py',1,'void',['Mat','image','',[]],['vector_Rect','objects','',['/O','/Ref']],['double','scaleFactor','1.1',[]],['int','minNeighbors','3',[]],['int','flags','0',[]],['Size','minSize','Size()',[...
['CascadeClassifier','detectMultiScale','@overload
@param image Matrix of the type CV_8U containing an image where objects are detected.
@param objects Vector of rectangles where each rectangle contains the detected object, the
rectangles may be partially outside the original image.
@param numDetections Vector of detection numbers for the corresponding objects. An object\'s number
of detections is the number of neighboring positively classified rectangles that were joined
together to form the object.
@param scaleFactor Parameter specifying how much the image size is reduced at each image scale.
@param minNeighbors Parameter specifying how many neighbors each candidate rectangle should have
to retain it.
@param flags Parameter with the same meaning for an old cascade as in the function
cvHaarDetectObjects. It is not used for a new cascade.
@param minSize Minimum possible object size. Objects smaller than that are ignored.
@param maxSize Maximum possible object size. Objects larger than that are ignored. If `maxSize == minSize` model is evaluated on single scale.',1,'void',['Mat','image','',[]],['vector_Rect','objects','',['/O','/Ref']],['vector_int','numDetections...
['CascadeClassifier','detectMultiScale','@overload
This function allows you to retrieve the final stage decision certainty of classification.
For this, one needs to set `outputRejectLevels` on true and provide the `rejectLevels` and `levelWeights` parameter.
For each resulting detection, `levelWeights` will then contain the certainty of classification at the final stage.
This value can then be used to separate strong from weaker classifications.
A code sample on how to use it efficiently can be found below:
@code
Objdetect/funclist.pl view on Meta::CPAN
vector<double> weights;
vector<int> levels;
vector<Rect> detections;
CascadeClassifier model("/path/to/your/model.xml");
model.detectMultiScale(img, detections, levels, weights, 1.1, 3, 0, Size(), Size(), true);
cerr << "Detection " << detections[0] << " with weight " << weights[0] << endl;
@endcode',1,'void',['Mat','image','',[]],['vector_Rect','objects','',['/O','/Ref']],['vector_int','rejectLevels','',['/O','/Ref']],['vector_double','levelWeights','',['/O','/Ref']],['double','scaleFactor','1.1',[]],['int','minNeighbors','3',[]],[...
['CascadeClassifier','isOldFormatCascade','',1,'bool'],
['CascadeClassifier','getOriginalWindowSize','',1,'Size'],
['CascadeClassifier','getFeatureType','',1,'int'],
['CascadeClassifier','convert','',0,'bool',['String','oldcascade','',['/C','/Ref']],['String','newcascade','',['/C','/Ref']]],
['HOGDescriptor','getDescriptorSize','@brief Returns the number of coefficients required for the classification.',1,'size_t'],
['HOGDescriptor','checkDetectorSize','@brief Checks if detector size equal to descriptor size.',1,'bool'],
['HOGDescriptor','getWinSigma','@brief Returns winSigma value',1,'double'],
['HOGDescriptor','setSVMDetector','@brief Sets coefficients for the linear SVM classifier.
@param svmdetector coefficients for the linear SVM classifier.',1,'void',['Mat','svmdetector','',[]]],
['HOGDescriptor','load','@brief loads HOGDescriptor parameters and coefficients for the linear SVM classifier from a file.
@param filename Path of the file to read.
@param objname The optional name of the node to read (if empty, the first top-level node will be used).',1,'bool',['String','filename','',['/C','/Ref']],['String','objname','String()',['/C','/Ref']]],
['HOGDescriptor','save','@brief saves HOGDescriptor parameters and coefficients for the linear SVM classifier to a file
@param filename File name
t/tracking.t view on Meta::CPAN
for (1..2) {
my $cpy = $imgb->copy;
my ($pts) = ellipse2Poly([250,250],[200,100],45,60,120+$_,1);
rectangle($cpy, $_, $_+1, [255,0,0,0]) for $pts->dog;
imshow("ud", $cpy), waitKey(300) if $ENV{AUTHOR_TESTING};
}
}
my $cc = PDL::OpenCV::CascadeClassifier->new;
my $CC_DIR = '';
my ($loaded) = $cc->load($CC_DIR.'/haarcascades/haarcascade_frontalface_alt.xml') if $CC_DIR;
die "Failed to load" if $CC_DIR and !$loaded;
my $vfile='t/frames.avi';
my $vc = PDL::OpenCV::VideoCapture->new;
die if !$vc->open($vfile, CAP_ANY);
isnt $vc->getBackendName, undef, 'getBackendName works';
my ($frame, $res) = $vc->read;
ok $res, 'read a frame right';
is_deeply [$frame->dims], [3,720,528], 'right dims' or diag $frame->info;
( run in 0.947 second using v1.01-cache-2.11-cpan-49f99fa48dc )