• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

paulmthompson / WhiskerToolbox / 14366745472

09 Apr 2025 08:51PM UTC coverage: 13.06% (+0.1%) from 12.935%
14366745472

push

github

paulmthompson
clang format and tidy for points header

0 of 2 new or added lines in 1 file covered. (0.0%)

26 existing lines in 4 files now uncovered.

210 of 1608 relevant lines covered (13.06%)

1.25 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/WhiskerToolbox/DataManager/Media/Image_Data.cpp
1

2
#include "Media/Image_Data.hpp"
3

4
#include "utils/string_manip.hpp"
5

6
#include <opencv2/core/core.hpp>
7
#include <opencv2/imgcodecs.hpp>
8
#include <opencv2/imgproc.hpp>
9

10
#include <cstddef>
11
#include <iostream>
12
#include <set>
13

14

15
ImageData::ImageData() = default;
×
16

17
void ImageData::doLoadMedia(std::string const & dir_name) {
×
18

19
    auto file_extensions = std::set<std::string>{".png", ".jpg"};
×
20

21
    for (auto const & entry: std::filesystem::directory_iterator(dir_name)) {
×
22
        if (file_extensions.count(entry.path().extension().string())) {
×
23
            _image_paths.push_back(dir_name / entry.path());
×
24
        }
25
    }
×
26

27
    if (_image_paths.empty()) {
×
28
        std::cout << "Warning: No images found in directory with matching extensions ";
×
29
        for (auto const & i: file_extensions) {
×
30
            std::cout << i << " ";
×
31
        }
32
        std::cout << std::endl;
×
33
    }
34

35
    setTotalFrameCount(static_cast<int>(_image_paths.size()));
×
36
}
×
37

38
cv::Mat convert_to_display_format(cv::Mat & image, ImageData::DisplayFormat format) {
×
39
    cv::Mat converted_image;
×
40
    if (format == ImageData::DisplayFormat::Gray) {
×
41
        cv::cvtColor(image, converted_image, cv::COLOR_BGR2GRAY);
×
42
        // std::cout << "Converting to Gray" << std::endl;
43
    } else if (format == ImageData::DisplayFormat::Color) {
×
44
        cv::cvtColor(image, converted_image, cv::COLOR_BGR2BGRA);
×
45
        // std::cout << "Converting to 4channel" << std::endl;
46
    }
47
    return converted_image;
×
48
}
×
49

50
void ImageData::doLoadFrame(int frame_id) {
×
51

52
    if (frame_id > _image_paths.size()) {
×
53
        std::cout << "Error: Requested frame ID is larger than the number of frames in Media Data" << std::endl;
×
54
        return;
×
55
    }
56

57
    auto loaded_image = cv::imread(_image_paths[frame_id].string());
×
58

59
    updateHeight(loaded_image.rows);
×
60
    updateWidth(loaded_image.cols);
×
61

62
    auto converted_image = convert_to_display_format(loaded_image, this->getFormat());
×
63

64
    size_t const num_bytes = converted_image.total() * converted_image.elemSize();
×
65
    // std::cout << converted_image.elemSize() << ' ' << converted_image.total() << std::endl;
66
    this->setRawData(std::vector<uint8_t>(static_cast<uint8_t *>(converted_image.data), static_cast<uint8_t *>(converted_image.data) + num_bytes));
×
67
}
×
68

69
std::string ImageData::GetFrameID(int frame_id) {
×
70
    return _image_paths[frame_id].filename().string();
×
71
}
72

73
int ImageData::getFrameIndexFromNumber(int frame_id) {
×
UNCOV
74
    for (std::size_t i = 0; i < _image_paths.size(); i++) {
×
75
        auto image_frame_id = extract_numbers_from_string(_image_paths[i].filename().string());
×
76
        if (std::stoi(image_frame_id) == frame_id) {
×
77
            return static_cast<int>(i);
×
78
        }
UNCOV
79
    }
×
80
    std::cout << "No matching frame found for requested ID" << std::endl;
×
81
    return 0;
×
82
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc