Coverage for src/bob/bio/face/database/cbsr_nir_vis_2.py: 70%
23 statements
« prev ^ index » next coverage.py v7.6.0, created at 2024-07-13 00:04 +0200
« prev ^ index » next coverage.py v7.6.0, created at 2024-07-13 00:04 +0200
1#!/usr/bin/env python
2# vim: set fileencoding=utf-8 :
3# Tiago de Freitas Pereira <tiago.pereira@idiap.ch>
5"""
6 CBSRNirVis2Database database: database implementation
7"""
9import os
11from clapper.rc import UserDefaults
12from sklearn.pipeline import make_pipeline
14import bob.io.base
16from bob.bio.base.database import CSVDatabase, FileSampleLoader
17from bob.bio.face.database.sample_loaders import EyesAnnotations
19rc = UserDefaults("bobrc.toml")
22class CBSRNirVis2Database(CSVDatabase):
23 """
24 This package contains the access API and descriptions for the `CASIA NIR-VIS 2.0 Database <http://www.cbsr.ia.ac.cn/english/NIR-VIS-2.0-Database.html>`.
25 The actual raw data for the database should be downloaded from the original URL.
26 This package only contains the Bob accessor methods to use the DB directly from python, with the original protocol of the database.
28 CASIA NIR-VIS 2.0 database offers pairs of mugshot images and their correspondent NIR photos.
29 The images of this database were collected in four recording sessions: 2007 spring, 2009 summer, 2009 fall and 2010 summer,
30 in which the first session is identical to the CASIA HFB database. It consists of 725 subjects in total.
31 There are [1-22] VIS and [5-50] NIR face images per subject. The eyes positions are also distributed with the images.
34 .. code-block:: latex
36 @inproceedings{li2013casia,
37 title={The casia nir-vis 2.0 face database},
38 author={Li, Stan Z and Yi, Dong and Lei, Zhen and Liao, Shengcai},
39 booktitle={Computer Vision and Pattern Recognition Workshops (CVPRW), 2013 IEEE Conference on},
40 pages={348--353},
41 year={2013},
42 organization={IEEE}
43 }
46 .. warning::
47 Use the command below to set the path of the real data::
49 $ bob config set bob.db.cbsr-nir-vis-2.directory [PATH-TO-CBSR-DATA]
53 Parameters
54 ----------
56 protocol: str
57 One of the database protocols.
58 """
60 name = "cbsr-nir-vis2"
61 category = "face"
62 dataset_protocols_name = "cbsr-nir-vis2.tar.gz"
63 dataset_protocols_urls = [
64 "https://www.idiap.ch/software/bob/databases/latest/face/cbsr-nir-vis2-cabebf97.tar.gz",
65 "http://www.idiap.ch/software/bob/databases/latest/face/cbsr-nir-vis2-cabebf97.tar.gz",
66 ]
67 dataset_protocols_hash = "cabebf97"
69 def __init__(
70 self, protocol, annotation_type="eyes-center", fixed_positions=None
71 ):
72 def load(filename):
73 extensions = [".jpg", ".bmp"]
74 for e in extensions:
75 f = os.path.splitext(filename)[0]
76 new_filename = f + e
77 if os.path.exists(new_filename):
78 return bob.io.base.load(new_filename)
79 raise ValueError("File `{0}` not found".format(str(new_filename)))
81 super().__init__(
82 name="",
83 protocol=protocol,
84 transformer=make_pipeline(
85 FileSampleLoader(
86 data_loader=load,
87 dataset_original_directory=rc.get(
88 "bob.db.cbsr-nir-vis-2.directory", ""
89 ),
90 extension=rc.get("bob.db.cbsr-nir-vis-2.extension", ".jpg"),
91 ),
92 EyesAnnotations(),
93 ),
94 annotation_type=annotation_type,
95 fixed_positions=fixed_positions,
96 )