Skip to content

Commit

Permalink
Accurate frame period reporting in oat-framserve wcam
Browse files Browse the repository at this point in the history
- Controlling frame rate of webcams is not worth it.
- Instead, I have choosen to send the measured frame period along with
  each frame
  • Loading branch information
jonnew committed May 4, 2016
1 parent 0e67705 commit 89498c0
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
2 changes: 0 additions & 2 deletions src/frameserver/FileReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ FileReader::FileReader(const std::string &image_sink_address,

void FileReader::connectToNode() {

// TODO: bind without using example frame from video stream. See PGGigECam.cpp
// for example
cv::Mat example_frame;
file_reader_ >> example_frame;

Expand Down
10 changes: 6 additions & 4 deletions src/frameserver/WebCam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,6 @@ void WebCam::connectToNode() {

shared_frame_ = frame_sink_.retrieve(
example_frame.rows, example_frame.cols, example_frame.type());

// TODO: this does not appear to be very accurate/work
shared_frame_.sample().set_rate_hz(cv_camera_->get(CV_CAP_PROP_FPS));
}

bool WebCam::serveFrame() {
Expand All @@ -81,7 +78,12 @@ bool WebCam::serveFrame() {
}

// Increment sample count
shared_frame_.sample().incrementCount();
if (shared_frame_.sample().count() == 0)
start_ = clock_.now();

auto period =
std::chrono::duration_cast<Sample::Microseconds>(clock_.now() - start_);
shared_frame_.sample().incrementCount(period);

// Tell sources there is new data
frame_sink_.post();
Expand Down
4 changes: 4 additions & 0 deletions src/frameserver/WebCam.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ class WebCam : public FrameServer {
// The webcam object
int64_t index_;
std::unique_ptr<cv::VideoCapture> cv_camera_;

// frame generation clock
std::chrono::steady_clock clock_;
std::chrono::steady_clock::time_point start_;
};

} /* namespace oat */
Expand Down

0 comments on commit 89498c0

Please sign in to comment.