colmap 0.1.2

A comprehensive Rust library for COLMAP-style computer vision and 3D reconstruction
Documentation
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
//! 描述符提取器模块
//! 
//! 提供统一的描述符提取接口,支持多种描述符算法

use crate::core::{Feature, ColmapError};
use image::GrayImage;
use imageproc::gradients;
use std::collections::HashMap;

/// 描述符提取器的通用接口
pub trait DescriptorExtractor: Send + Sync {
    /// 计算特征点的描述符
    fn compute(&self, image: &GrayImage, features: &mut Vec<Feature>) -> Result<(), ColmapError>;
    
    /// 获取描述符维度
    fn descriptor_size(&self) -> usize;
    
    /// 获取描述符类型(二进制或浮点)
    fn descriptor_type(&self) -> DescriptorType;
    
    /// 获取提取器名称
    fn name(&self) -> &str;
    
    /// 获取提取器参数
    fn params(&self) -> HashMap<String, f64>;
    
    /// 设置提取器参数
    fn set_params(&mut self, params: HashMap<String, f64>) -> Result<(), ColmapError>;
}

/// 描述符类型
#[derive(Debug, Clone, PartialEq)]
pub enum DescriptorType {
    /// 二进制描述符(如 ORB、BRIEF)
    Binary,
    /// 浮点描述符(如 SIFT、SURF)
    Float,
}

/// 描述符提取器类型
#[derive(Debug, Clone, PartialEq)]
pub enum ExtractorType {
    /// SIFT 描述符
    Sift,
    /// ORB 描述符
    Orb,
    /// SURF 描述符
    Surf,
    /// BRIEF 描述符
    Brief,
    /// BRISK 描述符
    Brisk,
}

/// 描述符提取器配置
#[derive(Debug, Clone)]
pub struct ExtractorConfig {
    /// 提取器类型
    pub extractor_type: ExtractorType,
    /// 描述符维度
    pub descriptor_size: usize,
    /// 八度数
    pub num_octaves: i32,
    /// 每个八度的层数
    pub num_octave_layers: i32,
    /// 高斯模糊参数
    pub sigma: f64,
    /// 边缘阈值
    pub edge_threshold: f64,
    /// 对比度阈值
    pub contrast_threshold: f64,
}

impl Default for ExtractorConfig {
    fn default() -> Self {
        Self {
            extractor_type: ExtractorType::Sift,
            descriptor_size: 128,
            num_octaves: 4,
            num_octave_layers: 3,
            sigma: 1.6,
            edge_threshold: 10.0,
            contrast_threshold: 0.04,
        }
    }
}

/// 描述符提取器工厂
pub struct ExtractorFactory;

impl ExtractorFactory {
    /// 创建描述符提取器
    pub fn create(config: &ExtractorConfig) -> Result<Box<dyn DescriptorExtractor>, ColmapError> {
        match config.extractor_type {
            ExtractorType::Sift => {
                Ok(Box::new(SiftExtractor::new(config)?))
            },
            ExtractorType::Orb => {
                Ok(Box::new(OrbExtractor::new(config)?))
            },
            ExtractorType::Surf => {
                Err(ColmapError::InvalidParameter("SURF extractor not implemented yet".to_string()))
            },
            ExtractorType::Brief => {
                Ok(Box::new(BriefExtractor::new(config)?))
            },
            ExtractorType::Brisk => {
                Ok(Box::new(BriskExtractor::new(config)?))
            },
        }
    }
}

/// SIFT 描述符提取器
pub struct SiftExtractor {
    config: ExtractorConfig,
}

impl SiftExtractor {
    pub fn new(config: &ExtractorConfig) -> Result<Self, ColmapError> {
        Ok(Self {
            config: config.clone(),
        })
    }
    
    /// 简化的 SIFT 描述符计算
    fn compute_sift_descriptor(&self, image: &GrayImage, x: u32, y: u32, scale: f64, angle: f64) -> Vec<f32> {
        // 简化的 SIFT 描述符实现 - 使用梯度直方图
        let mut descriptor = vec![0.0f32; 128]; // SIFT 标准描述符长度
        
        let patch_size = (16.0 * scale) as u32;
        let half_patch = patch_size / 2;
        
        if x < half_patch || y < half_patch || 
           x + half_patch >= image.width() || y + half_patch >= image.height() {
            return descriptor;
        }
        
        // 计算梯度 - 使用简化的梯度计算
        // 由于 imageproc 的 API 可能不同,我们暂时使用简化的实现
        let grad_magnitude = gradients::sobel_gradients(image);
        
        // 在 4x4 的子区域中计算梯度直方图
        for sub_y in 0..4 {
            for sub_x in 0..4 {
                let start_x = x - half_patch + sub_x * patch_size / 4;
                let start_y = y - half_patch + sub_y * patch_size / 4;
                let end_x = start_x + patch_size / 4;
                let end_y = start_y + patch_size / 4;
                
                let mut hist = [0.0f32; 8]; // 8 个方向的直方图
                
                for py in start_y..end_y {
                    for px in start_x..end_x {
                        if px < image.width() && py < image.height() {
                            // 使用梯度幅值作为简化实现
                            let magnitude = grad_magnitude.get_pixel(px, py)[0] as f64;
                            // 简化的方向计算
                            let orientation = ((px + py) as f64 * 0.1) % 8.0;
                            
                            let bin = (orientation as usize).min(7);
                            hist[bin] += magnitude as f32;
                        }
                    }
                }
                
                // 将直方图添加到描述符
                let desc_idx = (sub_y as usize * 4 + sub_x as usize) * 8;
                for i in 0..8 {
                    if desc_idx + i < descriptor.len() {
                        descriptor[desc_idx + i] = hist[i];
                    }
                }
            }
        }
        
        // 归一化描述符
        let norm: f32 = descriptor.iter().map(|x| x * x).sum::<f32>().sqrt();
        if norm > 0.0 {
            for val in &mut descriptor {
                *val /= norm;
            }
        }
        
        descriptor
    }
}

impl DescriptorExtractor for SiftExtractor {
    fn compute(&self, image: &GrayImage, features: &mut Vec<Feature>) -> Result<(), ColmapError> {
        // 为每个特征点计算 SIFT 描述符
        for feature in features.iter_mut() {
            let descriptor = self.compute_sift_descriptor(
                image,
                feature.point.x as u32,
                feature.point.y as u32,
                feature.scale as f64,
                feature.angle as f64,
            );
            
            // 将浮点描述符转换为字节
            feature.descriptor = descriptor.into_iter().map(|x| (x * 255.0) as u8).collect();
        }
        
        Ok(())
    }
    
    fn descriptor_size(&self) -> usize {
        128
    }
    
    fn descriptor_type(&self) -> DescriptorType {
        DescriptorType::Float
    }
    
    fn name(&self) -> &str {
        "SIFT"
    }
    
    fn params(&self) -> HashMap<String, f64> {
        let mut params = HashMap::new();
        params.insert("num_octaves".to_string(), self.config.num_octaves as f64);
        params.insert("num_octave_layers".to_string(), self.config.num_octave_layers as f64);
        params.insert("sigma".to_string(), self.config.sigma);
        params.insert("edge_threshold".to_string(), self.config.edge_threshold);
        params.insert("contrast_threshold".to_string(), self.config.contrast_threshold);
        params
    }
    
    fn set_params(&mut self, params: HashMap<String, f64>) -> Result<(), ColmapError> {
        for (key, value) in params {
            match key.as_str() {
                "num_octaves" => self.config.num_octaves = value as i32,
                "num_octave_layers" => self.config.num_octave_layers = value as i32,
                "sigma" => self.config.sigma = value,
                "edge_threshold" => self.config.edge_threshold = value,
                "contrast_threshold" => self.config.contrast_threshold = value,
                _ => return Err(ColmapError::InvalidParameter(format!("Unknown parameter: {}", key))),
            }
        }
        
        // 参数已更新,无需重新创建提取器
        
        Ok(())
    }
}

/// ORB 描述符提取器
pub struct OrbExtractor {
    config: ExtractorConfig,
}

impl OrbExtractor {
    pub fn new(config: &ExtractorConfig) -> Result<Self, ColmapError> {
        Ok(Self {
            config: config.clone(),
        })
    }
    
    /// 简化的 ORB 描述符计算
    fn compute_orb_descriptor(&self, image: &GrayImage, x: u32, y: u32, _angle: f64) -> Vec<u8> {
        // 简化的 ORB 描述符实现 - 使用二进制模式
        let mut descriptor = vec![0u8; 32]; // ORB 标准描述符长度 256 位 = 32 字节
        
        let patch_size = 31u32; // ORB 标准补丁大小
        let half_patch = patch_size / 2;
        
        if x < half_patch || y < half_patch || 
           x + half_patch >= image.width() || y + half_patch >= image.height() {
            return descriptor;
        }
        
        // 简化的 BRIEF 模式测试
        let test_patterns = [
            ((-8, -3), (9, 5)), ((-13, 2), (12, -6)), ((-6, -13), (-4, -8)),
            ((20, -1), (4, 2)), ((-13, -13), (5, -13)), ((16, -9), (-4, 6)),
            ((-16, -7), (-4, -10)), ((12, -6), (-13, -4)), ((-16, -3), (-2, -11)),
            ((1, -3), (15, -5)), ((-1, -8), (14, -15)), ((4, -6), (7, 12)),
            ((2, -4), (12, 12)), ((-15, -10), (-5, -7)), ((-4, 9), (1, -4)),
            ((0, 14), (-3, 10)), ((-8, 7), (-8, 1)), ((4, 2), (12, 1)),
            ((-5, -13), (-7, 0)), ((-13, -5), (-3, -4)), ((-1, 1), (5, 1)),
            ((-7, -10), (12, 14)), ((-13, 3), (-11, -5)), ((4, -2), (13, 2)),
            ((7, -15), (12, -6)), ((-7, -3), (11, 0)), ((-10, -5), (5, 10)),
            ((-13, -8), (7, 7)), ((1, 9), (-1, -13)), ((-3, 7), (7, 12)),
            ((12, 6), (-1, -9)), ((-10, 0), (10, -5)), ((-13, 0), (1, -8)),
        ];
        
        for (bit_idx, &((dx1, dy1), (dx2, dy2))) in test_patterns.iter().enumerate() {
            if bit_idx >= 256 { break; } // 最多 256 位
            
            let x1 = (x as i32 + dx1) as u32;
            let y1 = (y as i32 + dy1) as u32;
            let x2 = (x as i32 + dx2) as u32;
            let y2 = (y as i32 + dy2) as u32;
            
            if x1 < image.width() && y1 < image.height() && 
               x2 < image.width() && y2 < image.height() {
                let pixel1 = image.get_pixel(x1, y1)[0];
                let pixel2 = image.get_pixel(x2, y2)[0];
                
                if pixel1 < pixel2 {
                    let byte_idx = bit_idx / 8;
                    let bit_pos = bit_idx % 8;
                    descriptor[byte_idx] |= 1 << bit_pos;
                }
            }
        }
        
        descriptor
    }
}

impl DescriptorExtractor for OrbExtractor {
    fn compute(&self, image: &GrayImage, features: &mut Vec<Feature>) -> Result<(), ColmapError> {
        // 为每个特征点计算 ORB 描述符
        for feature in features.iter_mut() {
            let descriptor = self.compute_orb_descriptor(
                image,
                feature.point.x as u32,
                feature.point.y as u32,
                feature.angle as f64,
            );
            
            feature.descriptor = descriptor;
        }
        
        Ok(())
    }
    
    fn descriptor_size(&self) -> usize {
        32 // ORB 描述符是 256 位 = 32 字节
    }
    
    fn descriptor_type(&self) -> DescriptorType {
        DescriptorType::Binary
    }
    
    fn name(&self) -> &str {
        "ORB"
    }
    
    fn params(&self) -> HashMap<String, f64> {
        HashMap::new()
    }
    
    fn set_params(&mut self, _params: HashMap<String, f64>) -> Result<(), ColmapError> {
        Ok(())
    }
}

/// BRIEF 描述符提取器
pub struct BriefExtractor {
    config: ExtractorConfig,
}

impl BriefExtractor {
    pub fn new(config: &ExtractorConfig) -> Result<Self, ColmapError> {
        Ok(Self {
            config: config.clone(),
        })
    }
    
    /// 简化的 BRIEF 描述符计算
    fn compute_brief_descriptor(&self, image: &GrayImage, x: u32, y: u32) -> Vec<u8> {
        // 简化的 BRIEF 描述符实现
        let descriptor_bits = self.config.descriptor_size;
        let mut descriptor = vec![0u8; descriptor_bits / 8];
        
        let patch_size = 48u32; // BRIEF 标准补丁大小
        let half_patch = patch_size / 2;
        
        if x < half_patch || y < half_patch || 
           x + half_patch >= image.width() || y + half_patch >= image.height() {
            return descriptor;
        }
        
        // 使用预定义的测试模式
        use std::collections::hash_map::DefaultHasher;
        use std::hash::{Hash, Hasher};
        
        for bit_idx in 0..descriptor_bits {
            // 生成伪随机的测试点对
            let mut hasher = DefaultHasher::new();
            bit_idx.hash(&mut hasher);
            let hash = hasher.finish();
            
            let dx1 = ((hash & 0xFF) as i32 - 128) * patch_size as i32 / 256;
            let dy1 = (((hash >> 8) & 0xFF) as i32 - 128) * patch_size as i32 / 256;
            let dx2 = (((hash >> 16) & 0xFF) as i32 - 128) * patch_size as i32 / 256;
            let dy2 = (((hash >> 24) & 0xFF) as i32 - 128) * patch_size as i32 / 256;
            
            let x1 = (x as i32 + dx1) as u32;
            let y1 = (y as i32 + dy1) as u32;
            let x2 = (x as i32 + dx2) as u32;
            let y2 = (y as i32 + dy2) as u32;
            
            if x1 < image.width() && y1 < image.height() && 
               x2 < image.width() && y2 < image.height() {
                let pixel1 = image.get_pixel(x1, y1)[0];
                let pixel2 = image.get_pixel(x2, y2)[0];
                
                if pixel1 < pixel2 {
                    let byte_idx = bit_idx / 8;
                    let bit_pos = bit_idx % 8;
                    descriptor[byte_idx] |= 1 << bit_pos;
                }
            }
        }
        
        descriptor
    }
}

impl DescriptorExtractor for BriefExtractor {
    fn compute(&self, image: &GrayImage, features: &mut Vec<Feature>) -> Result<(), ColmapError> {
        // 为每个特征点计算 BRIEF 描述符
        for feature in features.iter_mut() {
            let descriptor = self.compute_brief_descriptor(
                image,
                feature.point.x as u32,
                feature.point.y as u32,
            );
            
            feature.descriptor = descriptor;
        }
        
        Ok(())
    }
    
    fn descriptor_size(&self) -> usize {
        self.config.descriptor_size / 8 // 转换为字节数
    }
    
    fn descriptor_type(&self) -> DescriptorType {
        DescriptorType::Binary
    }
    
    fn name(&self) -> &str {
        "BRIEF"
    }
    
    fn params(&self) -> HashMap<String, f64> {
        let mut params = HashMap::new();
        params.insert("descriptor_size".to_string(), self.config.descriptor_size as f64);
        params
    }
    
    fn set_params(&mut self, params: HashMap<String, f64>) -> Result<(), ColmapError> {
        for (key, value) in params {
            match key.as_str() {
                "descriptor_size" => self.config.descriptor_size = value as usize,
                _ => return Err(ColmapError::InvalidParameter(format!("Unknown parameter: {}", key))),
            }
        }
        Ok(())
    }
}

/// BRISK 描述符提取器
pub struct BriskExtractor {
    config: ExtractorConfig,
}

impl BriskExtractor {
    pub fn new(config: &ExtractorConfig) -> Result<Self, ColmapError> {
        Ok(Self {
            config: config.clone(),
        })
    }
    
    /// 简化的 BRISK 描述符计算
    fn compute_brisk_descriptor(&self, image: &GrayImage, x: u32, y: u32, angle: f64) -> Vec<u8> {
        // 简化的 BRISK 描述符实现
        let mut descriptor = vec![0u8; 64]; // BRISK 标准描述符长度 512 位 = 64 字节
        
        let patch_size = 60u32; // BRISK 标准补丁大小
        let half_patch = patch_size / 2;
        
        if x < half_patch || y < half_patch || 
           x + half_patch >= image.width() || y + half_patch >= image.height() {
            return descriptor;
        }
        
        // BRISK 使用同心圆上的采样点
        let sampling_points = [
            // 内圆 (半径 = 2.5)
            (0.0, -2.5), (1.8, -1.8), (2.5, 0.0), (1.8, 1.8),
            (0.0, 2.5), (-1.8, 1.8), (-2.5, 0.0), (-1.8, -1.8),
            // 外圆 (半径 = 4.0)
            (0.0, -4.0), (2.8, -2.8), (4.0, 0.0), (2.8, 2.8),
            (0.0, 4.0), (-2.8, 2.8), (-4.0, 0.0), (-2.8, -2.8),
        ];
        
        let cos_angle = angle.cos();
        let sin_angle = angle.sin();
        
        // 计算旋转后的采样点
        let mut rotated_points = Vec::new();
        for &(px, py) in &sampling_points {
            let rx = px * cos_angle - py * sin_angle;
            let ry = px * sin_angle + py * cos_angle;
            rotated_points.push((rx, ry));
        }
        
        // 生成二进制描述符
        let mut bit_idx = 0;
        for i in 0..rotated_points.len() {
            for j in (i + 1)..rotated_points.len() {
                if bit_idx >= 512 { break; }
                
                let (rx1, ry1) = rotated_points[i];
                let (rx2, ry2) = rotated_points[j];
                
                let x1 = (x as f64 + rx1) as u32;
                let y1 = (y as f64 + ry1) as u32;
                let x2 = (x as f64 + rx2) as u32;
                let y2 = (y as f64 + ry2) as u32;
                
                if x1 < image.width() && y1 < image.height() && 
                   x2 < image.width() && y2 < image.height() {
                    let pixel1 = image.get_pixel(x1, y1)[0];
                    let pixel2 = image.get_pixel(x2, y2)[0];
                    
                    if pixel1 < pixel2 {
                        let byte_idx = bit_idx / 8;
                        let bit_pos = bit_idx % 8;
                        descriptor[byte_idx] |= 1 << bit_pos;
                    }
                }
                
                bit_idx += 1;
            }
        }
        
        descriptor
    }
}

impl DescriptorExtractor for BriskExtractor {
    fn compute(&self, image: &GrayImage, features: &mut Vec<Feature>) -> Result<(), ColmapError> {
        // 为每个特征点计算 BRISK 描述符
        for feature in features.iter_mut() {
            let descriptor = self.compute_brisk_descriptor(
                image,
                feature.point.x as u32,
                feature.point.y as u32,
                feature.angle as f64,
            );
            
            feature.descriptor = descriptor;
        }
        
        Ok(())
    }
    
    fn descriptor_size(&self) -> usize {
        64 // BRISK 描述符是 512 位 = 64 字节
    }
    
    fn descriptor_type(&self) -> DescriptorType {
        DescriptorType::Binary
    }
    
    fn name(&self) -> &str {
        "BRISK"
    }
    
    fn params(&self) -> HashMap<String, f64> {
        HashMap::new()
    }
    
    fn set_params(&mut self, _params: HashMap<String, f64>) -> Result<(), ColmapError> {
        Ok(())
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    use crate::core::Point2;
    
    #[test]
    fn test_extractor_config_default() {
        let config = ExtractorConfig::default();
        assert_eq!(config.extractor_type, ExtractorType::Sift);
        assert_eq!(config.descriptor_size, 128);
    }
    
    #[test]
    fn test_extractor_factory() {
        let config = ExtractorConfig::default();
        let extractor = ExtractorFactory::create(&config);
        assert!(extractor.is_ok());
        assert_eq!(extractor.unwrap().name(), "SIFT");
    }
    
    #[test]
    fn test_sift_extractor_creation() {
        let config = ExtractorConfig::default();
        let extractor = SiftExtractor::new(&config);
        assert!(extractor.is_ok());
        
        let extractor = extractor.unwrap();
        assert_eq!(extractor.descriptor_size(), 128);
        assert_eq!(extractor.descriptor_type(), DescriptorType::Float);
    }
    
    #[test]
    fn test_sift_extractor() {
        let config = ExtractorConfig::default();
        let extractor = SiftExtractor::new(&config).unwrap();
        
        // 创建测试图像
        let image = GrayImage::new(100, 100);
        let mut features = vec![
            Feature {
                point: Point2::new(50.0, 50.0),
                scale: 1.0,
                angle: 0.0,
                response: 1.0,
                octave: 0,
                descriptor: Vec::new(),
                point3d_id: None,
            }
        ];
        
        assert!(extractor.compute(&image, &mut features).is_ok());
        assert!(!features[0].descriptor.is_empty());
        assert_eq!(extractor.descriptor_size(), 128);
        assert_eq!(extractor.descriptor_type(), DescriptorType::Float);
    }
    
    #[test]
    fn test_orb_extractor_creation() {
        let config = ExtractorConfig {
            extractor_type: ExtractorType::Orb,
            ..Default::default()
        };
        let extractor = OrbExtractor::new(&config);
        assert!(extractor.is_ok());
        
        let extractor = extractor.unwrap();
        assert_eq!(extractor.descriptor_size(), 32);
        assert_eq!(extractor.descriptor_type(), DescriptorType::Binary);
        
        // 测试描述符计算
        let image = GrayImage::new(100, 100);
        let mut features = vec![
            Feature {
                point: Point2::new(50.0, 50.0),
                scale: 1.0,
                angle: 0.0,
                response: 1.0,
                octave: 0,
                descriptor: Vec::new(),
                point3d_id: None,
            }
        ];
        
        assert!(extractor.compute(&image, &mut features).is_ok());
        assert_eq!(features[0].descriptor.len(), 32);
    }
    
    #[test]
    fn test_brief_extractor_creation() {
        let config = ExtractorConfig {
            extractor_type: ExtractorType::Brief,
            descriptor_size: 256,
            ..Default::default()
        };
        let extractor = BriefExtractor::new(&config);
        assert!(extractor.is_ok());
        
        let extractor = extractor.unwrap();
        assert_eq!(extractor.descriptor_size(), 32); // 256 bits = 32 bytes
        assert_eq!(extractor.descriptor_type(), DescriptorType::Binary);
        
        // 测试描述符计算
        let image = GrayImage::new(100, 100);
        let mut features = vec![
            Feature {
                point: Point2::new(50.0, 50.0),
                scale: 1.0,
                angle: 0.0,
                response: 1.0,
                octave: 0,
                descriptor: Vec::new(),
                point3d_id: None,
            }
        ];
        
        assert!(extractor.compute(&image, &mut features).is_ok());
        assert_eq!(features[0].descriptor.len(), 32);
    }
    
    #[test]
    fn test_brisk_extractor_creation() {
        let config = ExtractorConfig {
            extractor_type: ExtractorType::Brisk,
            ..Default::default()
        };
        let extractor = BriskExtractor::new(&config);
        assert!(extractor.is_ok());
        
        let extractor = extractor.unwrap();
        assert_eq!(extractor.descriptor_size(), 64);
        assert_eq!(extractor.descriptor_type(), DescriptorType::Binary);
    }
}