Dataset#

class xeye.dataset.Dataset(source: int | str, img_types: int, label: List[str], num: int, height: int, width: int, stand_by_time: float)[source]#

Bases: object

A class for shooting and saving images in grayscale or RGB using OpenCV.

source#

the source of the camera to use, index of usb device or rtsp string (e.g source = 0 internal camera, or rtsp://admin:pass@IP:port/ISAPI/Streaming/channels/101).

Type:

int, str

img_types#

the number of types of images to collect.

Type:

int

label#

a list of strings that represent the name of the directories where the images will be saved.

Type:

List[str]

num#

the number of frames to capture for each image type.

Type:

int

height#

the height of the frames to capture.

Type:

int

width#

the width of the frames to capture.

Type:

int

standby_time#

the time to wait before capturing each frame.

Type:

float

Examples

>>> import xeye
>>> # define parameters values
>>> source = 0
>>> img_types = 2
>>> label = ['keyboard', 'mouse']
>>> num = 20
>>> height = 100
>>> width = 100
>>> standby_time = 0
>>> data = xeye.ExpDataset(source = source, img_types = img_types, label = label, num = num, height = height, width = width, stand_by_time = standby_time)
>>> data.preview()
>>> data.rgb() # or data.gray()
>>> data.compress_train_test(perc=0.2)
>>> data.compress_all()
>>> data.just_compress(name="batch_test")
compress_all() None[source]#

Saves the images shot in a unique dataset.

Raises:

ValueError – If both rgb and gray functions have not been called before compressing a dataset.

Returns:

None

compress_train_test(perc: float = 0.1) None[source]#

Saves the images shot in datasets divided by train and test like the mnist dataset.

Parameters:

perc (float) – The percentage of images to assign to the test dataset.

Raises:
  • ValueError – If both rgb and gray functions have not been called before compressing a dataset.

  • ValueError – If the percentage value for images in the test set is less than or equal to 0.

Returns:

None

gray() None[source]#

Method for shooting images in grayscale.

Returns:

None

just_compress(name: str = 'dataset_raw') None[source]#

Saves the images shot in a unique dataset without saving the y variable containing the type of the single image.

Parameters:

name (str) – The name of the dataset (npz) to be saved.

Raises:

ValueError – If both rgb and gray functions have not been called before compressing a dataset.

Returns:

None

preview(size: Tuple = (1280, 720)) None[source]#

Opens the camera stream on a window for checking the framing of the image.

Returns:

None

rgb() None[source]#

Method for shooting images in RGB.

Returns:

None

var_control() None[source]#

Print the parameters specified in the init method about the dataset to create.

ManualDataset#

class xeye.manual_dataset.ManualDataset(source: int | str, img_types: int, label: List[str], num: int, height: int, width: int, _stand_by_time=0)[source]#

Bases: Dataset

A class that enables manual capturing of images in grayscale or RGB using OpenCV.

source#

Camera source.

Type:

int, str

img_types#

Number of image types.

Type:

int

label#

List of image labels.

Type:

List[str]

num#

Number of images to be taken per image type.

Type:

int

height#

Height of the captured images.

Type:

int

width#

Width of the captured images.

Type:

int

Examples

>>> import xeye
>>> # define parameters values
>>> source = 0
>>> img_types = 2
>>> label = ['keyboard', 'mouse']
>>> num = 20
>>> height = 100
>>> width = 100
>>> data = xeye.ManualDataset(source = source, img_types = img_types, label = label, num = num, height = height, width = width)
>>> data.preview()
>>> data.rgb() # or data.gray()
>>> data.compress_train_test(perc=0.2)
>>> data.compress_all()
>>> data.just_compress(name="batch_test")
gray() None[source]#

Method for manually shooting images in grayscale.

Returns:

None

rgb() None[source]#

Method for manually shooting images in RGB.

Returns:

None

BuildDataset#

class xeye.build_dataset.BuildDataset(path: List[str], label: List[int], size: Tuple = None, color: bool = True, split: bool = True, perc: float = 0.1)[source]#

Bases: object

Builds a dataset by merging multiple datasets with the given parameters.

path#

List of paths to the numpy files containing the datasets.

Type:

List[str]

label#

List of labels corresponding to each dataset.

Type:

List[int]

size#

Tuple specifying the size of the images in the dataset. Defaults to None.

Type:

tuple

color#

Whether the images are in color or grayscale. Defaults to True.

Type:

bool

split#

Whether to split the dataset into train and test sets. Defaults to True.

Type:

bool

perc#

The percentage of data to use for the test set. Defaults to 0.1.

Type:

float

Examples

>>> import xeye
>>> # list of directory (paths for the .npz files)
>>> path = ['batch_1.npz','batch_2.npz', 'batch_3.npz']
>>> # list of labels associated with the images inside the .npz files
>>> label = [0,1,2]
>>> data = xeye.BuildDataset(path=path, label=label, size = None, color=True, split=True, perc=0.2)
>>> data.build()
build() None[source]#

Builds a new dataset by merging the datasets with the parameters indicated by the instance variables.

Raises:
  • ValueError – If the path and label lists do not have the same length.

  • ValueError – If the datasets being merged have different color spaces.

Returns:

None

Note

The method calls the _control method to check if the datasets being merged have the same color space. The resulting merged dataset is stored as a numpy array in _tensor[‘X’] and _tensor[‘y’]. If the split instance variable is set to True, the merged dataset is split into training and testing sets using the train_test_split method from scikit-learn and saved as a numpy array in the file ‘dataset.npz’. Otherwise, the merged dataset is saved as a numpy array in the file ‘datasetall.npz’.