diff --git a/Tracking/classes.pl b/Tracking/classes.pl index 7d1d35f..7446875 100644 --- a/Tracking/classes.pl +++ b/Tracking/classes.pl @@ -30,7 +30,7 @@ The class can calculate an optical flow for a sparse feature set using the iterative Lucas-Kanade method with pyramids. -@sa calcOpticalFlowPyrLK',1,'cv::SparsePyrLKOpticalFlow::create',[[[],'']]], +@sa calcOpticalFlowPyrLK',1,'cv::SparsePyrLKOpticalFlow::create',[[[['Size','winSize','Size(21, 21)',[]],['int','maxLevel','3',[]],['TermCriteria','crit','TermCriteria(TermCriteria::COUNT+TermCriteria::EPS, 30, 0.01)',[]],['int','flags','0',[]],['double','minEigThreshold','1e-4',[]]],'']]], ['Tracker',[],'@brief Base abstract class for the long-term tracker'], ['TrackerMIL',['Tracker'],'@brief The MIL algorithm trains a classifier in an online manner to separate the object from the background. diff --git a/classes.pl b/classes.pl index 3de1644..ed74aac 100644 --- a/classes.pl +++ b/classes.pl @@ -33,6 +33,30 @@ query descriptor index, train descriptor index, train image index, and distance between descriptors.',0,'cv::DMatch',[[[],''],[[['int','_queryIdx','',[]],['int','_trainIdx','',[]],['float','_distance','',[]]],''],[[['int','_queryIdx','',[]],['int','_trainIdx','',[]],['int','_imgIdx','',[]],['float','_distance','',[]]],'']]], +['TermCriteria',[],'@brief The class defining termination criteria for iterative algorithms. + +You can initialize it by default constructor and then override any parameters, or the structure may +be fully initialized using the advanced variant of the constructor.',0,'cv::TermCriteria',[[[],''],[[['int','type','',[]],['int','maxCount','',[]],['double','epsilon','',[]]],'@param type The type of termination criteria, one of TermCriteria::Type + @param maxCount The maximum number of iterations or elements to compute. + @param epsilon The desired accuracy or change in parameters at which the iterative algorithm stops.']]], +['RNG',[],'@brief Random Number Generator + +Random number generator. It encapsulates the state (currently, a 64-bit +integer) and has methods to return scalar random values and to fill +arrays with random values. Currently it supports uniform and Gaussian +(normal) distributions. The generator uses Multiply-With-Carry +algorithm, introduced by G. Marsaglia ( + ). +Gaussian-distribution random numbers are generated using the Ziggurat +algorithm ( ), +introduced by G. Marsaglia and W. W. Tsang.',0,'cv::RNG',[[[],'@brief constructor + + These are the RNG constructors. The first form sets the state to some + pre-defined value, equal to 2\\*\\*32-1 in the current implementation. The + second form sets the state to the specified value. If you passed state=0 + , the constructor uses the above default value instead to avoid the + singular random number sequence, consisting of all zeros.'],[[['uint64','state','',[]]],'@overload + @param state 64-bit value used to initialize the RNG.']]], ['Algorithm',[],'@brief This is a base class for all more or less complex algorithms in OpenCV especially for classes of algorithms, for which there can be multiple implementations. The examples diff --git a/funclist.pl b/funclist.pl index b9d4d6f..5828d5d 100644 --- a/funclist.pl +++ b/funclist.pl @@ -133,6 +133,39 @@ @param src input array or vector of matrices. all of the matrices must have the same number of rows and the same depth. @param dst output array. It has the same number of rows and depth as the src, and the sum of cols of the src. same depth.',0,'void',['vector_Mat','src','',[]],['Mat','dst','',['/O']]], +['RNG','fill','@brief Fills arrays with random numbers. + + @param mat 2D or N-dimensional matrix; currently matrices with more than + 4 channels are not supported by the methods, use Mat::reshape as a + possible workaround. + @param distType distribution type, RNG::UNIFORM or RNG::NORMAL. + @param a first distribution parameter; in case of the uniform + distribution, this is an inclusive lower boundary, in case of the normal + distribution, this is a mean value. + @param b second distribution parameter; in case of the uniform + distribution, this is a non-inclusive upper boundary, in case of the + normal distribution, this is a standard deviation (diagonal of the + standard deviation matrix or the full standard deviation matrix). + @param saturateRange pre-saturation flag; for uniform distribution only; + if true, the method will first convert a and b to the acceptable value + range (according to the mat datatype) and then will generate uniformly + distributed random numbers within the range [saturate(a), saturate(b)), + if saturateRange=false, the method will generate uniformly distributed + random numbers in the original range [a, b) and then will saturate them, + it means, for example, that + theRNG().fill(mat_8u, RNG::UNIFORM, -DBL_MAX, DBL_MAX) will likely + produce array mostly filled with 0\'s and 255\'s, since the range (0, 255) + is significantly smaller than [-DBL_MAX, DBL_MAX). + + Each of the methods fills the matrix with the random values from the + specified distribution. As the new numbers are generated, the RNG state + is updated accordingly. In case of multiple-channel images, every + channel is filled independently, which means that RNG cannot generate + samples from the multi-dimensional Gaussian distribution with + non-diagonal covariance matrix directly. To do that, the method + generates samples from multi-dimensional standard Gaussian distribution + with zero mean and identity covariation matrix, and then transforms them + using transform to get samples from the specified Gaussian distribution.',1,'void',['Mat','mat','',['/IO']],['int','distType','',[]],['Mat','a','',[]],['Mat','b','',[]],['bool','saturateRange','false',[]]], ['Algorithm','write','@brief simplified API for language bindings * @overload',1,'void',['Ptr_FileStorage','fs','',['/C','/Ref']],['String','name','String()',['/C','/Ref']]], ['Algorithm','read','@brief Reads algorithm parameters from a file storage',1,'void',['FileNode','fn','',['/C','/Ref']]], diff --git a/genpp.pl b/genpp.pl index e21ceea..4862b95 100644 --- a/genpp.pl +++ b/genpp.pl @@ -207,6 +207,7 @@ sub default_pl { $d =~ s/^($dimtypes_re)\(\)$/"empty($REALCTYPE2PDLTYPE{$DIMTYPES{$1}[0][0]})"/e; $d =~ s/^($dimtypes_re)(\(.*\))$/$REALCTYPE2PDLTYPE{$DIMTYPES{$1}[0][0]}.$2/e; $d =~ s/([A-Za-z0-9_:]+::[A-Za-z_][A-Za-z0-9_]+)/PDL::OpenCV::$1()/g; + $d =~ s/^(TermCriteria)(\(.*\))$/"PDL::OpenCV::$1->new".(length $2 == 2 ? '' : '2').$2/e; length $d ? "\$$self->{name} = $d if !defined \$$self->{name};" : (); } sub xs_par { diff --git a/maint/genlists b/maint/genlists index d9236c7..c9041cd 100755 --- a/maint/genlists +++ b/maint/genlists @@ -25,6 +25,15 @@ my @HEADERS_FILES = do { local @ARGV = $HEADERS; grep !/^\s*#/, <> }; chomp @HEADERS_FILES; my $tdir = tempdir(CLEANUP=>1); +my %force_wrap = ( + RotatedRect => [['.*angle.*']], + RNG => [['.*']], + TermCriteria => [['.*']], +); +my $class_re = join '|', keys %force_wrap; +my $cons_re = join '|', + map "$_\\((?:".join('|', '', @{$force_wrap{$_}[0]}).")\\)", # always default + keys %force_wrap; sub process_header { my ($dir, $file) = @_; open my $fh, '<', catfile($dir, $file) or die "$file: $!"; @@ -33,9 +42,9 @@ sub process_header { make_path $outdir or die "$outdir: $!" if !-d $outdir; open my $outfh, '>', $outfile or die "$outfile: $!"; my $intext = do { local $/; <$fh> }; - $intext =~ s/(class\s+)(CV_EXPORTS)(\s+RotatedRect)/$1${2}_W$3/; - $intext =~ s/^(\s*)(RotatedRect\((?:.*angle|\)))/${1}CV_WRAP $2/gm; - $intext =~ s/^(\s*)(.*?boundingRect\()/${1}CV_WRAP $2/m; + $intext =~ s/(class\s+)(CV_EXPORTS)(\s+(?:$class_re))/$1${2}_W$3/g; + $intext =~ s/^(\s*)($cons_re)/${1}CV_WRAP $2/gm; + $intext =~ s/^(\s*)((?:.*?boundingRect|void\s+fill)\()/${1}CV_WRAP $2/gm; print $outfh $intext; $outfile; } @@ -56,6 +65,7 @@ my %force = map +($_=>1), qw( cv.sum cv.wrapperEMD cv.GeneralizedHough.detect + cv.RNG.fill cv.Algorithm.read cv.Algorithm.write cv.FileNode.keys @@ -121,7 +131,6 @@ my %class = map +($_=>1), qw( HOGDescriptor SparsePyrLKOpticalFlow DISOpticalFlow SparseOpticalFlow TermCriteria RNG RotatedRect ); -my $no_want = qr/^(TermCriteria|RNG)/; my $skip_re = join '|', qr/^cv\.ipp/, qr/^cv\.moments/, @@ -171,7 +180,7 @@ print "class: $cname\n"; die "Already got create $cname, now $name" if $dest2class2create{$dest}{$cname}; print "class::create: $cname\n"; (my $colons = $name) =~ s/\./::/g; - $args = [] if (@$args == 1 and $args->[0][0] =~ /Params/) or grep $_->[0] =~ /$no_want/, @$args; # temporary + $args = [] if @$args == 1 and $args->[0][0] =~ /Params/; # temporary $dest2class2create{$dest}{$cname} = [1, $colons, [[$args, $doc]]]; } elsif ($ret =~ /^Ptr_/ and $name =~ /^cv\.(create(.*))/) { my ($full, $cname) = ($1, $2); @@ -184,8 +193,6 @@ print "class.class: $cname @{[0+@$args]}\n"; $dest2class2create{$dest}{$cname} ||= [0, "cv::$cname", []]; push @{$dest2class2create{$dest}{$cname}[2]}, [$args, $doc]; } elsif ($inc_all or $force{$name}) { - my @foundbad = map /$no_want/, $ret, map $_->[0], @$args; - print(" skipping a $name, found (@foundbad)\n"), next if @foundbad; my (undef, @n) = split /\./, $name; unshift @n, '' if @n == 1; die "Unexpected number of elts in (@n)" if @n != 2; diff --git a/t/opencv_basic.t b/t/opencv_basic.t index 5658278..76dc443 100644 --- a/t/opencv_basic.t +++ b/t/opencv_basic.t @@ -7,6 +7,7 @@ use PDL::NiceSlice; use PDL::OpenCV; use PDL::OpenCV::Imgproc; use PDL::OpenCV::Imgcodecs; +use PDL::OpenCV::Tracking; my $data = (xvals(5,8,3)+10*yvals(5,8,3)+zvals(1,1,3))->mv(2,0); my $slice = float $data(0); @@ -23,6 +24,7 @@ my $pic2 = $pic->glue(1,$pic); is hconcat([$pic, $pic2])->dim(1), $pic->dim(1)*3, 'hconcat array-ref worked'; is +(sumElems($data))[0]->sumover, 4560, 'sumElems'; isa_ok +PDL::OpenCV::CLAHE->new, 'PDL::OpenCV::CLAHE', 'Size default OK'; +isa_ok +PDL::OpenCV::SparsePyrLKOpticalFlow->new, 'PDL::OpenCV::SparsePyrLKOpticalFlow', 'TermCriteria default OK'; { my $a = pdl float, q[[1 1] [1 2] [0 3] [0 4] [1 5]]; diff --git a/typemap b/typemap index a888035..4a72d10 100644 --- a/typemap +++ b/typemap @@ -7,6 +7,8 @@ vector_MatWrapper* T_OPENCV_VECTOR vector_StringWrapper* T_OPENCV_VECTOR vector_vector_Point2fWrapper* T_OPENCV_VECTOR RotatedRectWrapper* T_PTROBJ_SPECIAL +RNGWrapper* T_PTROBJ_SPECIAL +TermCriteriaWrapper* T_PTROBJ_SPECIAL KeyPointWrapper* T_PTROBJ_SPECIAL DMatchWrapper* T_PTROBJ_SPECIAL FileStorageWrapper* T_PTROBJ_SPECIAL