@@ -397,4 +397,210 @@ module.exports = ({ cv, utils, getTestImg }) => {
397397 }
398398 } ) ;
399399
400+ describe ( 'accumulate' , ( ) => {
401+ const srcData = [
402+ [ [ 1 , 2 , 3 ] , [ 4 , 5 , 6 ] ] ,
403+ [ [ 7 , 8 , 9 ] , [ 10 , 11 , 12 ] ]
404+ ]
405+ const dstData = [
406+ [ [ 1 , 1 , 1 ] , [ 1 , 1 , 1 ] ] ,
407+ [ [ 1 , 1 , 1 ] , [ 1 , 1 , 1 ] ]
408+ ]
409+ const maskData = [
410+ [ 255 , 0 ] ,
411+ [ 0 , 255 ]
412+ ]
413+ const expectedData = [
414+ [ [ 2 , 3 , 4 ] , [ 1 , 1 , 1 ] ] ,
415+ [ [ 1 , 1 , 1 ] , [ 11 , 12 , 13 ] ]
416+ ]
417+ const src = new cv . Mat ( srcData , cv . CV_8UC3 )
418+ const dstDepth8 = new cv . Mat ( dstData , cv . CV_8UC3 )
419+ let dst
420+ const mask = new cv . Mat ( maskData , cv . CV_8UC1 )
421+
422+ it ( 'should throw if dst has not a depth of CV_32F or CV_64F' , ( ) => {
423+ expect ( ( ) => cv . accumulate ( src , dstDepth8 ) ) . to . throw ( 'Imgproc::Accumulate - dst must has a depth of CV_32F or CV_64F' ) ;
424+ } ) ;
425+
426+ generateAPITests ( {
427+ getDut : ( ) => cv ,
428+ methodName : 'accumulate' ,
429+ methodNameSpace : 'Imgproc' ,
430+ beforeHook : ( ) => dst = new cv . Mat ( dstData , cv . CV_32FC3 ) ,
431+ getRequiredArgs : ( ) => ( [
432+ src ,
433+ dst ,
434+ mask
435+ ] ) ,
436+ expectOutput : ( ) => {
437+ channelIndices = [ 'x' , 'y' , 'z' ]
438+ for ( let row = 0 ; row < dst . rows ; row ++ ) {
439+ for ( let col = 0 ; col < dst . cols ; col ++ ) {
440+ for ( let channel = 0 ; channel < dst . channels ; channel ++ ) {
441+ expect ( dst . at ( row , col ) [ channelIndices [ channel ] ] ) . to . be . closeTo ( expectedData [ row ] [ col ] [ channel ] , 1e-5 ) ;
442+ }
443+ }
444+ }
445+ }
446+ } ) ;
447+ } ) ;
448+
449+ describe ( 'accumulateProduct' , ( ) => {
450+ const srcData1 = [
451+ [ [ 1 , 2 , 3 ] , [ 4 , 5 , 6 ] ] ,
452+ [ [ 7 , 8 , 9 ] , [ 10 , 11 , 12 ] ]
453+ ]
454+ const srcData2 = [
455+ [ [ 2 , 2 , 2 ] , [ 2 , 2 , 2 ] ] ,
456+ [ [ 2 , 2 , 2 ] , [ 2 , 2 , 2 ] ]
457+ ]
458+ const dstData = [
459+ [ [ 1 , 1 , 1 ] , [ 1 , 1 , 1 ] ] ,
460+ [ [ 1 , 1 , 1 ] , [ 1 , 1 , 1 ] ]
461+ ]
462+ const maskData = [
463+ [ 255 , 0 ] ,
464+ [ 0 , 255 ]
465+ ]
466+ const expectedData = [
467+ [ [ 3 , 5 , 7 ] , [ 1 , 1 , 1 ] ] ,
468+ [ [ 1 , 1 , 1 ] , [ 21 , 23 , 25 ] ]
469+ ]
470+
471+ const src1 = new cv . Mat ( srcData1 , cv . CV_8UC3 )
472+ const src2 = new cv . Mat ( srcData2 , cv . CV_8UC3 )
473+ let dst
474+ const dstDepth8 = new cv . Mat ( dstData , cv . CV_8UC3 )
475+ const mask = new cv . Mat ( maskData , cv . CV_8UC1 )
476+
477+ it ( 'should throw if dst has not a depth of CV_32F or CV_64F' , ( ) => {
478+ expect ( ( ) => cv . accumulateProduct ( src1 , src2 , dstDepth8 ) ) . to . throw ( 'Imgproc::AccumulateProduct - dst must has a depth of CV_32F or CV_64F' ) ;
479+ } ) ;
480+
481+ generateAPITests ( {
482+ getDut : ( ) => cv ,
483+ methodName : 'accumulateProduct' ,
484+ methodNameSpace : 'Imgproc' ,
485+ beforeHook : ( ) => dst = new cv . Mat ( dstData , cv . CV_32FC3 ) ,
486+ getRequiredArgs : ( ) => ( [
487+ src1 ,
488+ src2 ,
489+ dst ,
490+ mask
491+ ] ) ,
492+ expectOutput : ( ) => {
493+ channelIndices = [ 'x' , 'y' , 'z' ]
494+ for ( let row = 0 ; row < dst . rows ; row ++ ) {
495+ for ( let col = 0 ; col < dst . cols ; col ++ ) {
496+ for ( let channel = 0 ; channel < dst . channels ; channel ++ ) {
497+ expect ( dst . at ( row , col ) [ channelIndices [ channel ] ] ) . to . be . closeTo ( expectedData [ row ] [ col ] [ channel ] , 1e-5 ) ;
498+ }
499+ }
500+ }
501+ }
502+ } ) ;
503+ } ) ;
504+
505+ describe ( 'accumulateSquare' , ( ) => {
506+ const srcData = [
507+ [ [ 1 , 2 , 3 ] , [ 4 , 5 , 6 ] ] ,
508+ [ [ 7 , 8 , 9 ] , [ 10 , 11 , 12 ] ]
509+ ]
510+ const dstData = [
511+ [ [ 1 , 1 , 1 ] , [ 1 , 1 , 1 ] ] ,
512+ [ [ 1 , 1 , 1 ] , [ 1 , 1 , 1 ] ]
513+ ]
514+ const maskData = [
515+ [ 255 , 0 ] ,
516+ [ 0 , 255 ]
517+ ]
518+ const expectedData = [
519+ [ [ 2 , 5 , 10 ] , [ 1 , 1 , 1 ] ] ,
520+ [ [ 1 , 1 , 1 ] , [ 101 , 122 , 145 ] ]
521+ ]
522+
523+ const src = new cv . Mat ( srcData , cv . CV_8UC3 )
524+ let dst
525+ const dstDepth8 = new cv . Mat ( dstData , cv . CV_8UC3 )
526+ const mask = new cv . Mat ( maskData , cv . CV_8UC1 )
527+
528+ it ( 'should throw if dst has not a depth of CV_32F or CV_64F' , ( ) => {
529+ expect ( ( ) => cv . accumulateSquare ( src , dstDepth8 ) ) . to . throw ( 'Imgproc::AccumulateSquare - dst must has a depth of CV_32F or CV_64F' ) ;
530+ } ) ;
531+
532+ generateAPITests ( {
533+ getDut : ( ) => cv ,
534+ methodName : 'accumulateSquare' ,
535+ methodNameSpace : 'Imgproc' ,
536+ beforeHook : ( ) => dst = new cv . Mat ( dstData , cv . CV_32FC3 ) ,
537+ getRequiredArgs : ( ) => ( [
538+ src ,
539+ dst ,
540+ mask
541+ ] ) ,
542+ expectOutput : ( ) => {
543+ channelIndices = [ 'x' , 'y' , 'z' ]
544+ for ( let row = 0 ; row < dst . rows ; row ++ ) {
545+ for ( let col = 0 ; col < dst . cols ; col ++ ) {
546+ for ( let channel = 0 ; channel < dst . channels ; channel ++ ) {
547+ expect ( dst . at ( row , col ) [ channelIndices [ channel ] ] ) . to . be . closeTo ( expectedData [ row ] [ col ] [ channel ] , 1e-5 ) ;
548+ }
549+ }
550+ }
551+ }
552+ } ) ;
553+ } ) ;
554+
555+ describe ( 'accumulateWeighted' , ( ) => {
556+ const srcData = [
557+ [ [ 1 , 2 , 3 ] , [ 4 , 5 , 6 ] ] ,
558+ [ [ 7 , 8 , 9 ] , [ 10 , 11 , 12 ] ]
559+ ]
560+ const dstData = [
561+ [ [ 1 , 1 , 1 ] , [ 1 , 1 , 1 ] ] ,
562+ [ [ 1 , 1 , 1 ] , [ 1 , 1 , 1 ] ]
563+ ]
564+ const alpha = 0.7
565+ const maskData = [
566+ [ 255 , 0 ] ,
567+ [ 0 , 255 ]
568+ ]
569+ const expectedData = [
570+ [ [ ( 1 - alpha ) * 1 + alpha * 1 , ( 1 - alpha ) * 1 + alpha * 2 , ( 1 - alpha ) * 1 + alpha * 3 ] , [ 1 , 1 , 1 ] ] ,
571+ [ [ 1 , 1 , 1 ] , [ ( 1 - alpha ) * 1 + alpha * 10 , ( 1 - alpha ) * 1 + alpha * 11 , ( 1 - alpha ) * 1 + alpha * 12 ] ]
572+ ]
573+
574+ const src = new cv . Mat ( srcData , cv . CV_8UC3 )
575+ let dst
576+ const dstDepth8 = new cv . Mat ( dstData , cv . CV_8UC3 )
577+ const mask = new cv . Mat ( maskData , cv . CV_8UC1 )
578+
579+ it ( 'should throw if dst has not a depth of CV_32F or CV_64F' , ( ) => {
580+ expect ( ( ) => cv . accumulateWeighted ( src , dstDepth8 , alpha ) ) . to . throw ( 'Imgproc::AccumulateWeighted - dst must has a depth of CV_32F or CV_64F' ) ;
581+ } ) ;
582+
583+ generateAPITests ( {
584+ getDut : ( ) => cv ,
585+ methodName : 'accumulateWeighted' ,
586+ methodNameSpace : 'Imgproc' ,
587+ beforeHook : ( ) => dst = new cv . Mat ( dstData , cv . CV_32FC3 ) ,
588+ getRequiredArgs : ( ) => ( [
589+ src ,
590+ dst ,
591+ alpha ,
592+ mask
593+ ] ) ,
594+ expectOutput : ( ) => {
595+ channelIndices = [ 'x' , 'y' , 'z' ]
596+ for ( let row = 0 ; row < dst . rows ; row ++ ) {
597+ for ( let col = 0 ; col < dst . cols ; col ++ ) {
598+ for ( let channel = 0 ; channel < dst . channels ; channel ++ ) {
599+ expect ( dst . at ( row , col ) [ channelIndices [ channel ] ] ) . to . be . closeTo ( expectedData [ row ] [ col ] [ channel ] , 1e-5 ) ;
600+ }
601+ }
602+ }
603+ }
604+ } ) ;
605+ } ) ;
400606} ;
0 commit comments