6#define _USE_MATH_DEFINES
16#include <opencv2/opencv.hpp>
52 cv::putText(img, buff, cv::Point(20, 20), cv::FONT_HERSHEY_SIMPLEX, 0.4, cv::Scalar(90, 90, 90), 1, cv::LINE_AA);
57 yInfo() <<
"Available options:";
58 yInfo() <<
"--stats display statistics about the recevied iamges";
59 yInfo() <<
"--remote <portname> the port to which the gui connects to";
60 yInfo() <<
"--local <portname> the name of the port opened by the gui";
61 yInfo() <<
"--carrier <carriername> the communication protocol used to connect to the remote port";
62 yInfo() <<
"--record_filename <filename> the name of the output file";
63 yInfo() <<
"--record_start automatically start recording on receiving the first frame (or press `w` runtime)";
64 yInfo() <<
"--record_fps the framerate of the output file";
65 yInfo() <<
"--record_codec the codec used to save the file";
66 yInfo() <<
"--layered";
69int main(
int argc,
char* argv[])
76 if (rf.
check(
"help")) {
81 std::string filename = rf.
check(
"record_filename",
Value(
""),
"filename e.g. output.avi").asString();
82 std::string
codec_s = rf.
check(
"record_codec",
Value(
"MJPG"),
"codec (max 4 chars, e.g. MJPG)").asString();
85 yInfo() <<
"Invalid codec. Should be e 4 chars string, e.g. MJPG, DIVX, MP4V etc.";
88 bool recording = rf.
check(
"record_start",
Value(
false),
"automatically start recording on receiving the first frame").asBool();
89 int fps = rf.
check(
"record_fps",
Value(30),
"fps of the output video file").asInt32();
90 if (!filename.empty())
92 yInfo() <<
"Output file will be stored:" << filename <<
"(fps:" << fps <<
", codec:" <<
codec_s <<
")";
95 yInfo() <<
"record_start option found. Recoding will start on first received frame";
99 bool verbose = rf.
check(
"stats",
Value(
false),
"verbose stats [0/1]").asBool();
100 std::string remote = rf.
check(
"remote",
Value(
""),
"remote port name").asString();
101 std::string carrier = rf.
check(
"carrier",
Value(
"fast_tcp"),
"carrier name").asString();
102 std::string local = rf.
check(
"local",
Value(
"/yarpopencvdisplay:i"),
"local port name").asString();
103 bool layered = rf.
check(
"layered",
Value(
false),
"set if the input port will receive a layered image or not").asBool();
106 yInfo() <<
"yarpopencvdisplay ready. Press ESC to quit.";
118 if (inputPort->
open(local) ==
false)
120 yError() <<
"Failed to open port" << local;
127 yInfo() <<
"Opened LAYERED port:" << local;
131 yInfo() <<
"Opened port:" << local;
135 if (!remote.empty()) {
137 yInfo() <<
"Successfully connected to port:" << remote;
139 yError() <<
"Failed to connect to port:" << remote;
144 yInfo() <<
"Waiting for port connection...";
147 std::string
window_name =
"yarpopencvdisplay: " + local;
173 for (
size_t i = 0; i <
ly->layers.size(); i++)
177 ly->layers[i].enable =
true;
181 ly->layers[i].enable =
false;
213 if (filename.empty() ==
false)
220 yError(
"Unable to open the output file");
226 else if (frame.cols != (
int)
imgdata->width() || frame.rows != (
int)
imgdata->height())
228 yDebug() <<
"Steam has received a frame with different size" <<
imgdata->width() <<
imgdata->height();
234 for (
size_t y = 0; y <
imgdata->height(); y++) {
235 for (
size_t x = 0; x <
imgdata->width(); x++) {
243 stats.copy_time = b - a;
246 yDebug(
"copytime: %5.3f frameintervale %5.3f",
stats.copy_time,
stats.interval_time);
274 yInfo(
"recording is now ON");
276 yInfo(
"recording is now OFF");
290 yInfo(
"verbose mode is now ON");
292 yInfo(
"verbose mode is now OFF");
300 cv::destroyAllWindows();
A mini-server for performing network communication in the background.
void release(void *handle) override
Return control to YARP of an object previously taken control of with the acquire() method.
bool open(const std::string &name) override
Start port operation, with a specific name, with automatically-chosen network parameters.
T * read(bool shouldWait=true) override
Read an available object from the port.
void write(bool forceStrict=false)
Write the current object being returned by BufferedPort::prepare.
static bool connect(const std::string &src, const std::string &dest, const std::string &carrier="", bool quiet=true)
Request that an output port connect to an input port.
Utilities for manipulating the YARP network, including initialization and shutdown.
Helper class for finding config files and other external resources.
bool check(const std::string &key) const override
Check if there exists a property of the given name.
bool configure(int argc, char *argv[], bool skipFirstArgument=true)
Sets up the ResourceFinder.
bool setDefaultConfigFile(const std::string &fname)
Provide a default value for the configuration file (can be overridden from command line with the –fro...
static void delaySystem(double seconds)
A single value (typically within a Bottle).
Image class with user control of representation details.
A Layered Image, composed by a background and multiple layers.
const CvScalar color_gray
const CvScalar color_yellow
const CvScalar color_white
const CvScalar color_bwhite
const CvScalar color_black
int main(int argc, char *argv[])
struct stats_struct stats
void drawImageExtraStuff(cv::Mat &img)
double now()
Return the current time in seconds, relative to an arbitrary starting point.
An interface to the operating system, including Port based communication.
The main, catch-all namespace for YARP.