Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add ability to clear out contents of ImgFrame #686

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/depthai/pipeline/datatype/ADatatype.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class ADatatype {
explicit ADatatype(std::shared_ptr<RawBuffer> r) : raw(std::move(r)) {}
virtual ~ADatatype() = default;
virtual std::shared_ptr<dai::RawBuffer> serialize() const = 0;
std::shared_ptr<RawBuffer> getRaw() const {
const std::shared_ptr<RawBuffer>& getRaw() const {
return raw;
}
};
Expand Down
10 changes: 9 additions & 1 deletion include/depthai/pipeline/datatype/ImgFrame.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace dai {
*/
class ImgFrame : public Buffer {
std::shared_ptr<RawBuffer> serialize() const override;
RawImgFrame& img;
RawImgFrame* img;

public:
// Raw* mirror
Expand All @@ -39,6 +39,14 @@ class ImgFrame : public Buffer {
explicit ImgFrame(std::shared_ptr<RawImgFrame> ptr);
virtual ~ImgFrame() = default;

ImgFrame& operator=(const ImgFrame&) = delete;

// helpers
/**
* Clears the contents of this class.
*/
void clear();

// getters
/**
* Retrieves image timestamp related to dai::Clock::now()
Expand Down
56 changes: 30 additions & 26 deletions src/pipeline/datatype/ImgFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,90 +8,94 @@ std::shared_ptr<RawBuffer> ImgFrame::serialize() const {
return raw;
}

ImgFrame::ImgFrame() : Buffer(std::make_shared<RawImgFrame>()), img(*dynamic_cast<RawImgFrame*>(raw.get())) {
ImgFrame::ImgFrame() : Buffer(std::make_shared<RawImgFrame>()), img(dynamic_cast<RawImgFrame*>(raw.get())) {
// set timestamp to now
setTimestamp(std::chrono::steady_clock::now());
}
ImgFrame::ImgFrame(std::shared_ptr<RawImgFrame> ptr) : Buffer(std::move(ptr)), img(*dynamic_cast<RawImgFrame*>(raw.get())) {}
ImgFrame::ImgFrame(std::shared_ptr<RawImgFrame> ptr) : Buffer(std::move(ptr)), img(dynamic_cast<RawImgFrame*>(raw.get())) {}

// helpers
void ImgFrame::clear() {
raw = std::make_shared<RawImgFrame>();
img = dynamic_cast<RawImgFrame*>(raw.get());
}

// getters
std::chrono::time_point<std::chrono::steady_clock, std::chrono::steady_clock::duration> ImgFrame::getTimestamp() const {
using namespace std::chrono;
return time_point<steady_clock, steady_clock::duration>{seconds(img.ts.sec) + nanoseconds(img.ts.nsec)};
return time_point<steady_clock, steady_clock::duration>{seconds(img->ts.sec) + nanoseconds(img->ts.nsec)};
}
std::chrono::time_point<std::chrono::steady_clock, std::chrono::steady_clock::duration> ImgFrame::getTimestampDevice() const {
using namespace std::chrono;
return time_point<steady_clock, steady_clock::duration>{seconds(img.tsDevice.sec) + nanoseconds(img.tsDevice.nsec)};
return time_point<steady_clock, steady_clock::duration>{seconds(img->tsDevice.sec) + nanoseconds(img->tsDevice.nsec)};
}
unsigned int ImgFrame::getInstanceNum() const {
return img.instanceNum;
return img->instanceNum;
}
unsigned int ImgFrame::getCategory() const {
return img.category;
return img->category;
}
int64_t ImgFrame::getSequenceNum() const {
return img.sequenceNum;
return img->sequenceNum;
}
unsigned int ImgFrame::getWidth() const {
return img.fb.width;
return img->fb.width;
}
unsigned int ImgFrame::getHeight() const {
return img.fb.height;
return img->fb.height;
}
RawImgFrame::Type ImgFrame::getType() const {
return img.fb.type;
return img->fb.type;
}
std::chrono::microseconds ImgFrame::getExposureTime() const {
return std::chrono::microseconds(img.cam.exposureTimeUs);
return std::chrono::microseconds(img->cam.exposureTimeUs);
}
int ImgFrame::getSensitivity() const {
return img.cam.sensitivityIso;
return img->cam.sensitivityIso;
}
int ImgFrame::getColorTemperature() const {
return img.cam.wbColorTemp;
return img->cam.wbColorTemp;
}
int ImgFrame::getLensPosition() const {
return img.cam.lensPosition;
return img->cam.lensPosition;
}

// setters
ImgFrame& ImgFrame::setTimestamp(std::chrono::time_point<std::chrono::steady_clock, std::chrono::steady_clock::duration> tp) {
// Set timestamp from timepoint
using namespace std::chrono;
auto ts = tp.time_since_epoch();
img.ts.sec = duration_cast<seconds>(ts).count();
img.ts.nsec = duration_cast<nanoseconds>(ts).count() % 1000000000;
img->ts.sec = duration_cast<seconds>(ts).count();
img->ts.nsec = duration_cast<nanoseconds>(ts).count() % 1000000000;
return *this;
}
ImgFrame& ImgFrame::setTimestampDevice(std::chrono::time_point<std::chrono::steady_clock, std::chrono::steady_clock::duration> tp) {
// Set timestamp from timepoint
using namespace std::chrono;
auto ts = tp.time_since_epoch();
img.tsDevice.sec = duration_cast<seconds>(ts).count();
img.tsDevice.nsec = duration_cast<nanoseconds>(ts).count() % 1000000000;
img->tsDevice.sec = duration_cast<seconds>(ts).count();
img->tsDevice.nsec = duration_cast<nanoseconds>(ts).count() % 1000000000;
return *this;
}
ImgFrame& ImgFrame::setInstanceNum(unsigned int instanceNum) {
img.instanceNum = instanceNum;
img->instanceNum = instanceNum;
return *this;
}
ImgFrame& ImgFrame::setCategory(unsigned int category) {
img.category = category;
img->category = category;
return *this;
}
ImgFrame& ImgFrame::setSequenceNum(int64_t sequenceNum) {
img.sequenceNum = sequenceNum;
img->sequenceNum = sequenceNum;
return *this;
}
ImgFrame& ImgFrame::setWidth(unsigned int width) {
img.fb.width = width;
img.fb.stride = width;
img->fb.width = width;
img->fb.stride = width;
return *this;
}
ImgFrame& ImgFrame::setHeight(unsigned int height) {
img.fb.height = height;
img->fb.height = height;
return *this;
}
ImgFrame& ImgFrame::setSize(unsigned int width, unsigned int height) {
Expand All @@ -104,8 +108,8 @@ ImgFrame& ImgFrame::setSize(std::tuple<unsigned int, unsigned int> size) {
return *this;
}
ImgFrame& ImgFrame::setType(RawImgFrame::Type type) {
img.fb.type = type;
img.fb.bytesPP = RawImgFrame::typeToBpp(img.fb.type);
img->fb.type = type;
img->fb.bytesPP = RawImgFrame::typeToBpp(img->fb.type);
return *this;
}

Expand Down