forked from twistedfall/opencv-rust
-
Notifications
You must be signed in to change notification settings - Fork 0
/
saliency.rs
760 lines (635 loc) · 31.8 KB
/
saliency.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
pub mod saliency {
//! # Saliency API
//!
//! Many computer vision applications may benefit from understanding where humans focus given a scene.
//! Other than cognitively understanding the way human perceive images and scenes, finding salient
//! regions and objects in the images helps various tasks such as speeding up object detection, object
//! recognition, object tracking and content-aware image editing.
//!
//! About the saliency, there is a rich literature but the development is very fragmented. The principal
//! purpose of this API is to give a unique interface, a unique framework for use and plug sever
//! saliency algorithms, also with very different nature and methodology, but they share the same
//! purpose, organizing algorithms into three main categories:
//!
//! **Static Saliency**: algorithms belonging to this category, exploit different image features that
//! allow to detect salient objects in a non dynamic scenarios.
//!
//! **Motion Saliency**: algorithms belonging to this category, are particularly focused to detect
//! salient objects over time (hence also over frame), then there is a temporal component sealing
//! cosider that allows to detect "moving" objects as salient, meaning therefore also the more general
//! sense of detection the changes in the scene.
//!
//! **Objectness**: Objectness is usually represented as a value which reflects how likely an image
//! window covers an object of any category. Algorithms belonging to this category, avoid making
//! decisions early on, by proposing a small number of category-independent proposals, that are expected
//! to cover all objects in an image. Being able to perceive objects before identifying them is closely
//! related to bottom up visual attention (saliency).
//!
//! ![Saliency diagram](https://docs.opencv.org/4.7.0/saliency.png)
//!
//! To see how API works, try tracker demo:
//! <https://github.com/fpuja/opencv_contrib/blob/saliencyModuleDevelop/modules/saliency/samples/computeSaliency.cpp>
//!
//!
//! Note: This API has been designed with PlantUML. If you modify this API please change UML.
use crate::{mod_prelude::*, core, sys, types};
pub mod prelude {
pub use { super::SaliencyConst, super::Saliency, super::StaticSaliencyConst, super::StaticSaliency, super::MotionSaliencyConst, super::MotionSaliency, super::ObjectnessConst, super::Objectness, super::StaticSaliencySpectralResidualTraitConst, super::StaticSaliencySpectralResidualTrait, super::StaticSaliencyFineGrainedTraitConst, super::StaticSaliencyFineGrainedTrait, super::MotionSaliencyBinWangApr2014TraitConst, super::MotionSaliencyBinWangApr2014Trait, super::ObjectnessBINGTraitConst, super::ObjectnessBINGTrait };
}
/// Constant methods for [crate::saliency::MotionSaliency]
pub trait MotionSaliencyConst: crate::saliency::SaliencyConst {
fn as_raw_MotionSaliency(&self) -> *const c_void;
}
/// ********************************* Motion Saliency Base Class ***********************************
pub trait MotionSaliency: crate::saliency::MotionSaliencyConst + crate::saliency::Saliency {
fn as_raw_mut_MotionSaliency(&mut self) -> *mut c_void;
}
/// Constant methods for [crate::saliency::MotionSaliencyBinWangApr2014]
pub trait MotionSaliencyBinWangApr2014TraitConst: crate::saliency::MotionSaliencyConst {
fn as_raw_MotionSaliencyBinWangApr2014(&self) -> *const c_void;
#[inline]
fn get_image_width(&self) -> Result<i32> {
return_send!(via ocvrs_return);
unsafe { sys::cv_saliency_MotionSaliencyBinWangApr2014_getImageWidth_const(self.as_raw_MotionSaliencyBinWangApr2014(), ocvrs_return.as_mut_ptr()) };
return_receive!(unsafe ocvrs_return => ret);
let ret = ret.into_result()?;
Ok(ret)
}
#[inline]
fn get_image_height(&self) -> Result<i32> {
return_send!(via ocvrs_return);
unsafe { sys::cv_saliency_MotionSaliencyBinWangApr2014_getImageHeight_const(self.as_raw_MotionSaliencyBinWangApr2014(), ocvrs_return.as_mut_ptr()) };
return_receive!(unsafe ocvrs_return => ret);
let ret = ret.into_result()?;
Ok(ret)
}
}
/// Mutable methods for [crate::saliency::MotionSaliencyBinWangApr2014]
pub trait MotionSaliencyBinWangApr2014Trait: crate::saliency::MotionSaliency + crate::saliency::MotionSaliencyBinWangApr2014TraitConst {
fn as_raw_mut_MotionSaliencyBinWangApr2014(&mut self) -> *mut c_void;
#[inline]
fn compute_saliency(&mut self, image: &dyn core::ToInputArray, saliency_map: &mut dyn core::ToOutputArray) -> Result<bool> {
extern_container_arg!(image);
extern_container_arg!(saliency_map);
return_send!(via ocvrs_return);
unsafe { sys::cv_saliency_MotionSaliencyBinWangApr2014_computeSaliency_const__InputArrayR_const__OutputArrayR(self.as_raw_mut_MotionSaliencyBinWangApr2014(), image.as_raw__InputArray(), saliency_map.as_raw__OutputArray(), ocvrs_return.as_mut_ptr()) };
return_receive!(unsafe ocvrs_return => ret);
let ret = ret.into_result()?;
Ok(ret)
}
/// This is a utility function that allows to set the correct size (taken from the input image) in the
/// corresponding variables that will be used to size the data structures of the algorithm.
/// ## Parameters
/// * W: width of input image
/// * H: height of input image
#[inline]
fn set_imagesize(&mut self, w: i32, h: i32) -> Result<()> {
return_send!(via ocvrs_return);
unsafe { sys::cv_saliency_MotionSaliencyBinWangApr2014_setImagesize_int_int(self.as_raw_mut_MotionSaliencyBinWangApr2014(), w, h, ocvrs_return.as_mut_ptr()) };
return_receive!(unsafe ocvrs_return => ret);
let ret = ret.into_result()?;
Ok(ret)
}
/// This function allows the correct initialization of all data structures that will be used by the
/// algorithm.
#[inline]
fn init(&mut self) -> Result<bool> {
return_send!(via ocvrs_return);
unsafe { sys::cv_saliency_MotionSaliencyBinWangApr2014_init(self.as_raw_mut_MotionSaliencyBinWangApr2014(), ocvrs_return.as_mut_ptr()) };
return_receive!(unsafe ocvrs_return => ret);
let ret = ret.into_result()?;
Ok(ret)
}
#[inline]
fn set_image_width(&mut self, val: i32) -> Result<()> {
return_send!(via ocvrs_return);
unsafe { sys::cv_saliency_MotionSaliencyBinWangApr2014_setImageWidth_int(self.as_raw_mut_MotionSaliencyBinWangApr2014(), val, ocvrs_return.as_mut_ptr()) };
return_receive!(unsafe ocvrs_return => ret);
let ret = ret.into_result()?;
Ok(ret)
}
#[inline]
fn set_image_height(&mut self, val: i32) -> Result<()> {
return_send!(via ocvrs_return);
unsafe { sys::cv_saliency_MotionSaliencyBinWangApr2014_setImageHeight_int(self.as_raw_mut_MotionSaliencyBinWangApr2014(), val, ocvrs_return.as_mut_ptr()) };
return_receive!(unsafe ocvrs_return => ret);
let ret = ret.into_result()?;
Ok(ret)
}
}
/// !
/// * A Fast Self-tuning Background Subtraction Algorithm.
/// *
/// * This background subtraction algorithm is inspired to the work of B. Wang and P. Dudek [2]
/// * [2] B. Wang and P. Dudek "A Fast Self-tuning Background Subtraction Algorithm", in proc of IEEE Workshop on Change Detection, 2014
/// *
///
/// the Fast Self-tuning Background Subtraction Algorithm from [BinWangApr2014](https://docs.opencv.org/4.7.0/d0/de3/citelist.html#CITEREF_BinWangApr2014)
pub struct MotionSaliencyBinWangApr2014 {
ptr: *mut c_void
}
opencv_type_boxed! { MotionSaliencyBinWangApr2014 }
impl Drop for MotionSaliencyBinWangApr2014 {
fn drop(&mut self) {
extern "C" { fn cv_MotionSaliencyBinWangApr2014_delete(instance: *mut c_void); }
unsafe { cv_MotionSaliencyBinWangApr2014_delete(self.as_raw_mut_MotionSaliencyBinWangApr2014()) };
}
}
unsafe impl Send for MotionSaliencyBinWangApr2014 {}
impl core::AlgorithmTraitConst for MotionSaliencyBinWangApr2014 {
#[inline] fn as_raw_Algorithm(&self) -> *const c_void { self.as_raw() }
}
impl core::AlgorithmTrait for MotionSaliencyBinWangApr2014 {
#[inline] fn as_raw_mut_Algorithm(&mut self) -> *mut c_void { self.as_raw_mut() }
}
impl crate::saliency::MotionSaliencyConst for MotionSaliencyBinWangApr2014 {
#[inline] fn as_raw_MotionSaliency(&self) -> *const c_void { self.as_raw() }
}
impl crate::saliency::MotionSaliency for MotionSaliencyBinWangApr2014 {
#[inline] fn as_raw_mut_MotionSaliency(&mut self) -> *mut c_void { self.as_raw_mut() }
}
impl crate::saliency::SaliencyConst for MotionSaliencyBinWangApr2014 {
#[inline] fn as_raw_Saliency(&self) -> *const c_void { self.as_raw() }
}
impl crate::saliency::Saliency for MotionSaliencyBinWangApr2014 {
#[inline] fn as_raw_mut_Saliency(&mut self) -> *mut c_void { self.as_raw_mut() }
}
impl crate::saliency::MotionSaliencyBinWangApr2014TraitConst for MotionSaliencyBinWangApr2014 {
#[inline] fn as_raw_MotionSaliencyBinWangApr2014(&self) -> *const c_void { self.as_raw() }
}
impl crate::saliency::MotionSaliencyBinWangApr2014Trait for MotionSaliencyBinWangApr2014 {
#[inline] fn as_raw_mut_MotionSaliencyBinWangApr2014(&mut self) -> *mut c_void { self.as_raw_mut() }
}
impl MotionSaliencyBinWangApr2014 {
#[inline]
pub fn default() -> Result<crate::saliency::MotionSaliencyBinWangApr2014> {
return_send!(via ocvrs_return);
unsafe { sys::cv_saliency_MotionSaliencyBinWangApr2014_MotionSaliencyBinWangApr2014(ocvrs_return.as_mut_ptr()) };
return_receive!(unsafe ocvrs_return => ret);
let ret = ret.into_result()?;
let ret = unsafe { crate::saliency::MotionSaliencyBinWangApr2014::opencv_from_extern(ret) };
Ok(ret)
}
#[inline]
pub fn create() -> Result<core::Ptr<crate::saliency::MotionSaliencyBinWangApr2014>> {
return_send!(via ocvrs_return);
unsafe { sys::cv_saliency_MotionSaliencyBinWangApr2014_create(ocvrs_return.as_mut_ptr()) };
return_receive!(unsafe ocvrs_return => ret);
let ret = ret.into_result()?;
let ret = unsafe { core::Ptr::<crate::saliency::MotionSaliencyBinWangApr2014>::opencv_from_extern(ret) };
Ok(ret)
}
}
boxed_cast_base! { MotionSaliencyBinWangApr2014, core::Algorithm, cv_MotionSaliencyBinWangApr2014_to_Algorithm }
/// Constant methods for [crate::saliency::Objectness]
pub trait ObjectnessConst: crate::saliency::SaliencyConst {
fn as_raw_Objectness(&self) -> *const c_void;
}
/// ********************************* Objectness Base Class ***********************************
pub trait Objectness: crate::saliency::ObjectnessConst + crate::saliency::Saliency {
fn as_raw_mut_Objectness(&mut self) -> *mut c_void;
}
/// Constant methods for [crate::saliency::ObjectnessBING]
pub trait ObjectnessBINGTraitConst: crate::saliency::ObjectnessConst {
fn as_raw_ObjectnessBING(&self) -> *const c_void;
#[inline]
fn write(&self) -> Result<()> {
return_send!(via ocvrs_return);
unsafe { sys::cv_saliency_ObjectnessBING_write_const(self.as_raw_ObjectnessBING(), ocvrs_return.as_mut_ptr()) };
return_receive!(unsafe ocvrs_return => ret);
let ret = ret.into_result()?;
Ok(ret)
}
#[inline]
fn get_base(&self) -> Result<f64> {
return_send!(via ocvrs_return);
unsafe { sys::cv_saliency_ObjectnessBING_getBase_const(self.as_raw_ObjectnessBING(), ocvrs_return.as_mut_ptr()) };
return_receive!(unsafe ocvrs_return => ret);
let ret = ret.into_result()?;
Ok(ret)
}
#[inline]
fn get_nss(&self) -> Result<i32> {
return_send!(via ocvrs_return);
unsafe { sys::cv_saliency_ObjectnessBING_getNSS_const(self.as_raw_ObjectnessBING(), ocvrs_return.as_mut_ptr()) };
return_receive!(unsafe ocvrs_return => ret);
let ret = ret.into_result()?;
Ok(ret)
}
#[inline]
fn get_w(&self) -> Result<i32> {
return_send!(via ocvrs_return);
unsafe { sys::cv_saliency_ObjectnessBING_getW_const(self.as_raw_ObjectnessBING(), ocvrs_return.as_mut_ptr()) };
return_receive!(unsafe ocvrs_return => ret);
let ret = ret.into_result()?;
Ok(ret)
}
}
/// Mutable methods for [crate::saliency::ObjectnessBING]
pub trait ObjectnessBINGTrait: crate::saliency::Objectness + crate::saliency::ObjectnessBINGTraitConst {
fn as_raw_mut_ObjectnessBING(&mut self) -> *mut c_void;
#[inline]
fn compute_saliency(&mut self, image: &dyn core::ToInputArray, saliency_map: &mut dyn core::ToOutputArray) -> Result<bool> {
extern_container_arg!(image);
extern_container_arg!(saliency_map);
return_send!(via ocvrs_return);
unsafe { sys::cv_saliency_ObjectnessBING_computeSaliency_const__InputArrayR_const__OutputArrayR(self.as_raw_mut_ObjectnessBING(), image.as_raw__InputArray(), saliency_map.as_raw__OutputArray(), ocvrs_return.as_mut_ptr()) };
return_receive!(unsafe ocvrs_return => ret);
let ret = ret.into_result()?;
Ok(ret)
}
#[inline]
fn read(&mut self) -> Result<()> {
return_send!(via ocvrs_return);
unsafe { sys::cv_saliency_ObjectnessBING_read(self.as_raw_mut_ObjectnessBING(), ocvrs_return.as_mut_ptr()) };
return_receive!(unsafe ocvrs_return => ret);
let ret = ret.into_result()?;
Ok(ret)
}
/// Return the list of the rectangles' objectness value,
///
/// in the same order as the *vector\<Vec4i\> objectnessBoundingBox* returned by the algorithm (in
/// computeSaliencyImpl function). The bigger value these scores are, it is more likely to be an
/// object window.
#[inline]
fn getobjectness_values(&mut self) -> Result<core::Vector<f32>> {
return_send!(via ocvrs_return);
unsafe { sys::cv_saliency_ObjectnessBING_getobjectnessValues(self.as_raw_mut_ObjectnessBING(), ocvrs_return.as_mut_ptr()) };
return_receive!(unsafe ocvrs_return => ret);
let ret = ret.into_result()?;
let ret = unsafe { core::Vector::<f32>::opencv_from_extern(ret) };
Ok(ret)
}
/// This is a utility function that allows to set the correct path from which the algorithm will load
/// the trained model.
/// ## Parameters
/// * trainingPath: trained model path
#[inline]
fn set_training_path(&mut self, training_path: &str) -> Result<()> {
extern_container_arg!(training_path);
return_send!(via ocvrs_return);
unsafe { sys::cv_saliency_ObjectnessBING_setTrainingPath_const_StringR(self.as_raw_mut_ObjectnessBING(), training_path.opencv_as_extern(), ocvrs_return.as_mut_ptr()) };
return_receive!(unsafe ocvrs_return => ret);
let ret = ret.into_result()?;
Ok(ret)
}
/// This is a utility function that allows to set an arbitrary path in which the algorithm will save the
/// optional results
///
/// (ie writing on file the total number and the list of rectangles returned by objectess, one for
/// each row).
/// ## Parameters
/// * resultsDir: results' folder path
#[inline]
fn set_bb_res_dir(&mut self, results_dir: &str) -> Result<()> {
extern_container_arg!(results_dir);
return_send!(via ocvrs_return);
unsafe { sys::cv_saliency_ObjectnessBING_setBBResDir_const_StringR(self.as_raw_mut_ObjectnessBING(), results_dir.opencv_as_extern(), ocvrs_return.as_mut_ptr()) };
return_receive!(unsafe ocvrs_return => ret);
let ret = ret.into_result()?;
Ok(ret)
}
#[inline]
fn set_base(&mut self, val: f64) -> Result<()> {
return_send!(via ocvrs_return);
unsafe { sys::cv_saliency_ObjectnessBING_setBase_double(self.as_raw_mut_ObjectnessBING(), val, ocvrs_return.as_mut_ptr()) };
return_receive!(unsafe ocvrs_return => ret);
let ret = ret.into_result()?;
Ok(ret)
}
#[inline]
fn set_nss(&mut self, val: i32) -> Result<()> {
return_send!(via ocvrs_return);
unsafe { sys::cv_saliency_ObjectnessBING_setNSS_int(self.as_raw_mut_ObjectnessBING(), val, ocvrs_return.as_mut_ptr()) };
return_receive!(unsafe ocvrs_return => ret);
let ret = ret.into_result()?;
Ok(ret)
}
#[inline]
fn set_w(&mut self, val: i32) -> Result<()> {
return_send!(via ocvrs_return);
unsafe { sys::cv_saliency_ObjectnessBING_setW_int(self.as_raw_mut_ObjectnessBING(), val, ocvrs_return.as_mut_ptr()) };
return_receive!(unsafe ocvrs_return => ret);
let ret = ret.into_result()?;
Ok(ret)
}
}
/// the Binarized normed gradients algorithm from [BING](https://docs.opencv.org/4.7.0/d0/de3/citelist.html#CITEREF_BING)
pub struct ObjectnessBING {
ptr: *mut c_void
}
opencv_type_boxed! { ObjectnessBING }
impl Drop for ObjectnessBING {
fn drop(&mut self) {
extern "C" { fn cv_ObjectnessBING_delete(instance: *mut c_void); }
unsafe { cv_ObjectnessBING_delete(self.as_raw_mut_ObjectnessBING()) };
}
}
unsafe impl Send for ObjectnessBING {}
impl core::AlgorithmTraitConst for ObjectnessBING {
#[inline] fn as_raw_Algorithm(&self) -> *const c_void { self.as_raw() }
}
impl core::AlgorithmTrait for ObjectnessBING {
#[inline] fn as_raw_mut_Algorithm(&mut self) -> *mut c_void { self.as_raw_mut() }
}
impl crate::saliency::ObjectnessConst for ObjectnessBING {
#[inline] fn as_raw_Objectness(&self) -> *const c_void { self.as_raw() }
}
impl crate::saliency::Objectness for ObjectnessBING {
#[inline] fn as_raw_mut_Objectness(&mut self) -> *mut c_void { self.as_raw_mut() }
}
impl crate::saliency::SaliencyConst for ObjectnessBING {
#[inline] fn as_raw_Saliency(&self) -> *const c_void { self.as_raw() }
}
impl crate::saliency::Saliency for ObjectnessBING {
#[inline] fn as_raw_mut_Saliency(&mut self) -> *mut c_void { self.as_raw_mut() }
}
impl crate::saliency::ObjectnessBINGTraitConst for ObjectnessBING {
#[inline] fn as_raw_ObjectnessBING(&self) -> *const c_void { self.as_raw() }
}
impl crate::saliency::ObjectnessBINGTrait for ObjectnessBING {
#[inline] fn as_raw_mut_ObjectnessBING(&mut self) -> *mut c_void { self.as_raw_mut() }
}
impl ObjectnessBING {
#[inline]
pub fn default() -> Result<crate::saliency::ObjectnessBING> {
return_send!(via ocvrs_return);
unsafe { sys::cv_saliency_ObjectnessBING_ObjectnessBING(ocvrs_return.as_mut_ptr()) };
return_receive!(unsafe ocvrs_return => ret);
let ret = ret.into_result()?;
let ret = unsafe { crate::saliency::ObjectnessBING::opencv_from_extern(ret) };
Ok(ret)
}
#[inline]
pub fn create() -> Result<core::Ptr<crate::saliency::ObjectnessBING>> {
return_send!(via ocvrs_return);
unsafe { sys::cv_saliency_ObjectnessBING_create(ocvrs_return.as_mut_ptr()) };
return_receive!(unsafe ocvrs_return => ret);
let ret = ret.into_result()?;
let ret = unsafe { core::Ptr::<crate::saliency::ObjectnessBING>::opencv_from_extern(ret) };
Ok(ret)
}
}
boxed_cast_base! { ObjectnessBING, core::Algorithm, cv_ObjectnessBING_to_Algorithm }
/// Constant methods for [crate::saliency::Saliency]
pub trait SaliencyConst: core::AlgorithmTraitConst {
fn as_raw_Saliency(&self) -> *const c_void;
}
/// ********************************* Saliency Base Class ***********************************
pub trait Saliency: core::AlgorithmTrait + crate::saliency::SaliencyConst {
fn as_raw_mut_Saliency(&mut self) -> *mut c_void;
/// \brief Compute the saliency
/// \param image The image.
/// \param saliencyMap The computed saliency map.
/// \return true if the saliency map is computed, false otherwise
#[inline]
fn compute_saliency(&mut self, image: &dyn core::ToInputArray, saliency_map: &mut dyn core::ToOutputArray) -> Result<bool> {
extern_container_arg!(image);
extern_container_arg!(saliency_map);
return_send!(via ocvrs_return);
unsafe { sys::cv_saliency_Saliency_computeSaliency_const__InputArrayR_const__OutputArrayR(self.as_raw_mut_Saliency(), image.as_raw__InputArray(), saliency_map.as_raw__OutputArray(), ocvrs_return.as_mut_ptr()) };
return_receive!(unsafe ocvrs_return => ret);
let ret = ret.into_result()?;
Ok(ret)
}
}
/// Constant methods for [crate::saliency::StaticSaliency]
pub trait StaticSaliencyConst: crate::saliency::SaliencyConst {
fn as_raw_StaticSaliency(&self) -> *const c_void;
}
/// ********************************* Static Saliency Base Class ***********************************
pub trait StaticSaliency: crate::saliency::Saliency + crate::saliency::StaticSaliencyConst {
fn as_raw_mut_StaticSaliency(&mut self) -> *mut c_void;
/// This function perform a binary map of given saliency map. This is obtained in this
/// way:
///
/// In a first step, to improve the definition of interest areas and facilitate identification of
/// targets, a segmentation by clustering is performed, using *K-means algorithm*. Then, to gain a
/// binary representation of clustered saliency map, since values of the map can vary according to
/// the characteristics of frame under analysis, it is not convenient to use a fixed threshold. So,
/// *Otsu's algorithm* is used, which assumes that the image to be thresholded contains two classes
/// of pixels or bi-modal histograms (e.g. foreground and back-ground pixels); later on, the
/// algorithm calculates the optimal threshold separating those two classes, so that their
/// intra-class variance is minimal.
///
/// ## Parameters
/// * _saliencyMap: the saliency map obtained through one of the specialized algorithms
/// * _binaryMap: the binary map
#[inline]
fn compute_binary_map(&mut self, _saliency_map: &dyn core::ToInputArray, _binary_map: &mut dyn core::ToOutputArray) -> Result<bool> {
extern_container_arg!(_saliency_map);
extern_container_arg!(_binary_map);
return_send!(via ocvrs_return);
unsafe { sys::cv_saliency_StaticSaliency_computeBinaryMap_const__InputArrayR_const__OutputArrayR(self.as_raw_mut_StaticSaliency(), _saliency_map.as_raw__InputArray(), _binary_map.as_raw__OutputArray(), ocvrs_return.as_mut_ptr()) };
return_receive!(unsafe ocvrs_return => ret);
let ret = ret.into_result()?;
Ok(ret)
}
}
/// Constant methods for [crate::saliency::StaticSaliencyFineGrained]
pub trait StaticSaliencyFineGrainedTraitConst: crate::saliency::StaticSaliencyConst {
fn as_raw_StaticSaliencyFineGrained(&self) -> *const c_void;
}
/// Mutable methods for [crate::saliency::StaticSaliencyFineGrained]
pub trait StaticSaliencyFineGrainedTrait: crate::saliency::StaticSaliency + crate::saliency::StaticSaliencyFineGrainedTraitConst {
fn as_raw_mut_StaticSaliencyFineGrained(&mut self) -> *mut c_void;
#[inline]
fn compute_saliency(&mut self, image: &dyn core::ToInputArray, saliency_map: &mut dyn core::ToOutputArray) -> Result<bool> {
extern_container_arg!(image);
extern_container_arg!(saliency_map);
return_send!(via ocvrs_return);
unsafe { sys::cv_saliency_StaticSaliencyFineGrained_computeSaliency_const__InputArrayR_const__OutputArrayR(self.as_raw_mut_StaticSaliencyFineGrained(), image.as_raw__InputArray(), saliency_map.as_raw__OutputArray(), ocvrs_return.as_mut_ptr()) };
return_receive!(unsafe ocvrs_return => ret);
let ret = ret.into_result()?;
Ok(ret)
}
}
/// the Fine Grained Saliency approach from [FGS](https://docs.opencv.org/4.7.0/d0/de3/citelist.html#CITEREF_FGS)
///
/// This method calculates saliency based on center-surround differences.
/// High resolution saliency maps are generated in real time by using integral images.
pub struct StaticSaliencyFineGrained {
ptr: *mut c_void
}
opencv_type_boxed! { StaticSaliencyFineGrained }
impl Drop for StaticSaliencyFineGrained {
fn drop(&mut self) {
extern "C" { fn cv_StaticSaliencyFineGrained_delete(instance: *mut c_void); }
unsafe { cv_StaticSaliencyFineGrained_delete(self.as_raw_mut_StaticSaliencyFineGrained()) };
}
}
unsafe impl Send for StaticSaliencyFineGrained {}
impl core::AlgorithmTraitConst for StaticSaliencyFineGrained {
#[inline] fn as_raw_Algorithm(&self) -> *const c_void { self.as_raw() }
}
impl core::AlgorithmTrait for StaticSaliencyFineGrained {
#[inline] fn as_raw_mut_Algorithm(&mut self) -> *mut c_void { self.as_raw_mut() }
}
impl crate::saliency::SaliencyConst for StaticSaliencyFineGrained {
#[inline] fn as_raw_Saliency(&self) -> *const c_void { self.as_raw() }
}
impl crate::saliency::Saliency for StaticSaliencyFineGrained {
#[inline] fn as_raw_mut_Saliency(&mut self) -> *mut c_void { self.as_raw_mut() }
}
impl crate::saliency::StaticSaliencyConst for StaticSaliencyFineGrained {
#[inline] fn as_raw_StaticSaliency(&self) -> *const c_void { self.as_raw() }
}
impl crate::saliency::StaticSaliency for StaticSaliencyFineGrained {
#[inline] fn as_raw_mut_StaticSaliency(&mut self) -> *mut c_void { self.as_raw_mut() }
}
impl crate::saliency::StaticSaliencyFineGrainedTraitConst for StaticSaliencyFineGrained {
#[inline] fn as_raw_StaticSaliencyFineGrained(&self) -> *const c_void { self.as_raw() }
}
impl crate::saliency::StaticSaliencyFineGrainedTrait for StaticSaliencyFineGrained {
#[inline] fn as_raw_mut_StaticSaliencyFineGrained(&mut self) -> *mut c_void { self.as_raw_mut() }
}
impl StaticSaliencyFineGrained {
#[inline]
pub fn default() -> Result<crate::saliency::StaticSaliencyFineGrained> {
return_send!(via ocvrs_return);
unsafe { sys::cv_saliency_StaticSaliencyFineGrained_StaticSaliencyFineGrained(ocvrs_return.as_mut_ptr()) };
return_receive!(unsafe ocvrs_return => ret);
let ret = ret.into_result()?;
let ret = unsafe { crate::saliency::StaticSaliencyFineGrained::opencv_from_extern(ret) };
Ok(ret)
}
#[inline]
pub fn create() -> Result<core::Ptr<crate::saliency::StaticSaliencyFineGrained>> {
return_send!(via ocvrs_return);
unsafe { sys::cv_saliency_StaticSaliencyFineGrained_create(ocvrs_return.as_mut_ptr()) };
return_receive!(unsafe ocvrs_return => ret);
let ret = ret.into_result()?;
let ret = unsafe { core::Ptr::<crate::saliency::StaticSaliencyFineGrained>::opencv_from_extern(ret) };
Ok(ret)
}
}
boxed_cast_base! { StaticSaliencyFineGrained, core::Algorithm, cv_StaticSaliencyFineGrained_to_Algorithm }
/// Constant methods for [crate::saliency::StaticSaliencySpectralResidual]
pub trait StaticSaliencySpectralResidualTraitConst: crate::saliency::StaticSaliencyConst {
fn as_raw_StaticSaliencySpectralResidual(&self) -> *const c_void;
#[inline]
fn write(&self, fs: &mut core::FileStorage) -> Result<()> {
return_send!(via ocvrs_return);
unsafe { sys::cv_saliency_StaticSaliencySpectralResidual_write_const_FileStorageR(self.as_raw_StaticSaliencySpectralResidual(), fs.as_raw_mut_FileStorage(), ocvrs_return.as_mut_ptr()) };
return_receive!(unsafe ocvrs_return => ret);
let ret = ret.into_result()?;
Ok(ret)
}
#[inline]
fn get_image_width(&self) -> Result<i32> {
return_send!(via ocvrs_return);
unsafe { sys::cv_saliency_StaticSaliencySpectralResidual_getImageWidth_const(self.as_raw_StaticSaliencySpectralResidual(), ocvrs_return.as_mut_ptr()) };
return_receive!(unsafe ocvrs_return => ret);
let ret = ret.into_result()?;
Ok(ret)
}
#[inline]
fn get_image_height(&self) -> Result<i32> {
return_send!(via ocvrs_return);
unsafe { sys::cv_saliency_StaticSaliencySpectralResidual_getImageHeight_const(self.as_raw_StaticSaliencySpectralResidual(), ocvrs_return.as_mut_ptr()) };
return_receive!(unsafe ocvrs_return => ret);
let ret = ret.into_result()?;
Ok(ret)
}
}
/// Mutable methods for [crate::saliency::StaticSaliencySpectralResidual]
pub trait StaticSaliencySpectralResidualTrait: crate::saliency::StaticSaliency + crate::saliency::StaticSaliencySpectralResidualTraitConst {
fn as_raw_mut_StaticSaliencySpectralResidual(&mut self) -> *mut c_void;
#[inline]
fn compute_saliency(&mut self, image: &dyn core::ToInputArray, saliency_map: &mut dyn core::ToOutputArray) -> Result<bool> {
extern_container_arg!(image);
extern_container_arg!(saliency_map);
return_send!(via ocvrs_return);
unsafe { sys::cv_saliency_StaticSaliencySpectralResidual_computeSaliency_const__InputArrayR_const__OutputArrayR(self.as_raw_mut_StaticSaliencySpectralResidual(), image.as_raw__InputArray(), saliency_map.as_raw__OutputArray(), ocvrs_return.as_mut_ptr()) };
return_receive!(unsafe ocvrs_return => ret);
let ret = ret.into_result()?;
Ok(ret)
}
#[inline]
fn read(&mut self, fn_: &core::FileNode) -> Result<()> {
return_send!(via ocvrs_return);
unsafe { sys::cv_saliency_StaticSaliencySpectralResidual_read_const_FileNodeR(self.as_raw_mut_StaticSaliencySpectralResidual(), fn_.as_raw_FileNode(), ocvrs_return.as_mut_ptr()) };
return_receive!(unsafe ocvrs_return => ret);
let ret = ret.into_result()?;
Ok(ret)
}
#[inline]
fn set_image_width(&mut self, val: i32) -> Result<()> {
return_send!(via ocvrs_return);
unsafe { sys::cv_saliency_StaticSaliencySpectralResidual_setImageWidth_int(self.as_raw_mut_StaticSaliencySpectralResidual(), val, ocvrs_return.as_mut_ptr()) };
return_receive!(unsafe ocvrs_return => ret);
let ret = ret.into_result()?;
Ok(ret)
}
#[inline]
fn set_image_height(&mut self, val: i32) -> Result<()> {
return_send!(via ocvrs_return);
unsafe { sys::cv_saliency_StaticSaliencySpectralResidual_setImageHeight_int(self.as_raw_mut_StaticSaliencySpectralResidual(), val, ocvrs_return.as_mut_ptr()) };
return_receive!(unsafe ocvrs_return => ret);
let ret = ret.into_result()?;
Ok(ret)
}
}
/// the Spectral Residual approach from [SR](https://docs.opencv.org/4.7.0/d0/de3/citelist.html#CITEREF_SR)
///
/// Starting from the principle of natural image statistics, this method simulate the behavior of
/// pre-attentive visual search. The algorithm analyze the log spectrum of each image and obtain the
/// spectral residual. Then transform the spectral residual to spatial domain to obtain the saliency
/// map, which suggests the positions of proto-objects.
pub struct StaticSaliencySpectralResidual {
ptr: *mut c_void
}
opencv_type_boxed! { StaticSaliencySpectralResidual }
impl Drop for StaticSaliencySpectralResidual {
fn drop(&mut self) {
extern "C" { fn cv_StaticSaliencySpectralResidual_delete(instance: *mut c_void); }
unsafe { cv_StaticSaliencySpectralResidual_delete(self.as_raw_mut_StaticSaliencySpectralResidual()) };
}
}
unsafe impl Send for StaticSaliencySpectralResidual {}
impl core::AlgorithmTraitConst for StaticSaliencySpectralResidual {
#[inline] fn as_raw_Algorithm(&self) -> *const c_void { self.as_raw() }
}
impl core::AlgorithmTrait for StaticSaliencySpectralResidual {
#[inline] fn as_raw_mut_Algorithm(&mut self) -> *mut c_void { self.as_raw_mut() }
}
impl crate::saliency::SaliencyConst for StaticSaliencySpectralResidual {
#[inline] fn as_raw_Saliency(&self) -> *const c_void { self.as_raw() }
}
impl crate::saliency::Saliency for StaticSaliencySpectralResidual {
#[inline] fn as_raw_mut_Saliency(&mut self) -> *mut c_void { self.as_raw_mut() }
}
impl crate::saliency::StaticSaliencyConst for StaticSaliencySpectralResidual {
#[inline] fn as_raw_StaticSaliency(&self) -> *const c_void { self.as_raw() }
}
impl crate::saliency::StaticSaliency for StaticSaliencySpectralResidual {
#[inline] fn as_raw_mut_StaticSaliency(&mut self) -> *mut c_void { self.as_raw_mut() }
}
impl crate::saliency::StaticSaliencySpectralResidualTraitConst for StaticSaliencySpectralResidual {
#[inline] fn as_raw_StaticSaliencySpectralResidual(&self) -> *const c_void { self.as_raw() }
}
impl crate::saliency::StaticSaliencySpectralResidualTrait for StaticSaliencySpectralResidual {
#[inline] fn as_raw_mut_StaticSaliencySpectralResidual(&mut self) -> *mut c_void { self.as_raw_mut() }
}
impl StaticSaliencySpectralResidual {
#[inline]
pub fn default() -> Result<crate::saliency::StaticSaliencySpectralResidual> {
return_send!(via ocvrs_return);
unsafe { sys::cv_saliency_StaticSaliencySpectralResidual_StaticSaliencySpectralResidual(ocvrs_return.as_mut_ptr()) };
return_receive!(unsafe ocvrs_return => ret);
let ret = ret.into_result()?;
let ret = unsafe { crate::saliency::StaticSaliencySpectralResidual::opencv_from_extern(ret) };
Ok(ret)
}
#[inline]
pub fn create() -> Result<core::Ptr<crate::saliency::StaticSaliencySpectralResidual>> {
return_send!(via ocvrs_return);
unsafe { sys::cv_saliency_StaticSaliencySpectralResidual_create(ocvrs_return.as_mut_ptr()) };
return_receive!(unsafe ocvrs_return => ret);
let ret = ret.into_result()?;
let ret = unsafe { core::Ptr::<crate::saliency::StaticSaliencySpectralResidual>::opencv_from_extern(ret) };
Ok(ret)
}
}
boxed_cast_base! { StaticSaliencySpectralResidual, core::Algorithm, cv_StaticSaliencySpectralResidual_to_Algorithm }
}