iCub-main
Loading...
Searching...
No Matches
main.cpp
Go to the documentation of this file.
1/*
2* Copyright (C) 2016 iCub Facility - Istituto Italiano di Tecnologia
3* Author: Marco Randazzo <marco.randazzo@iit.it>
4* CopyPolicy: Released under the terms of the GPLv2 or later, see GPL.TXT
5*/
6
7#include <yarp/sig/Image.h>
8#include <yarp/os/all.h>
9
10#include <iostream>
11#include <math.h>
12
13using namespace yarp::os;
14using namespace yarp::sig;
15void printFrame(int h, int w, int c);
16
17void crop(const ImageOf<PixelRgb> &inImg, ImageOf<PixelRgb> &outImg, size_t start_x, size_t start_y, size_t width, size_t height)
18{
19 size_t end_x = (start_x + width) < size_t(inImg.width()) ? (start_x + width) : (inImg.width());
20 size_t end_y = (start_y + height) < size_t(inImg.height()) ? (start_y + height) : (inImg.height());
21 outImg.resize(end_x-start_x, end_y-start_y);
22
23 for (size_t r_src = start_y, r_dst = 0; r_src < end_y; r_dst++, r_src++)
24 {
25 unsigned char *tmp_dst = outImg.getRow(r_dst);
26 const unsigned char *tmp_src = inImg.getRow(r_src);
27
28 for (size_t c_src = start_x, c_dst = 0; c_src < end_x; c_dst++, c_src++)
29 {
30 tmp_dst[0 + c_dst * 3] = tmp_src[0 + c_src * 3];
31 tmp_dst[1 + c_dst * 3] = tmp_src[1 + c_src * 3];
32 tmp_dst[2 + c_dst * 3] = tmp_src[2 + c_src * 3];
33 }
34 }
35}
36
37int main(int argc, char *argv[])
38{
39 Network yarp;
40 int c=0;
41 ResourceFinder rf;
42 rf.configure(argc, argv);
43
44 BufferedPort<ImageOf<PixelRgb> > input;
45 BufferedPort<ImageOf<PixelRgb> > out;
46
47 input.open("/imageCropper/in");
48 out.open("/imageCropper/out");
49
50 size_t start_x = 0;
51 size_t start_y = 0;
52 size_t width = 0;
53 size_t height = 0;
54 if (rf.check("x_off")) start_x = (size_t) rf.find("x_off").asFloat64();
55 if (rf.check("y_off")) start_y = (size_t) rf.find("y_off").asFloat64();
56 if (rf.check("width")) width = (size_t)rf.find("width").asFloat64();
57 if (rf.check("height")) height = (size_t)rf.find("height").asFloat64();
58 yDebug("x_off %lu, y_off %lu, width %lu, height %lu", start_x, start_y, width, height);
59 if (rf.check("help"))
60 {
61 yDebug() << "Available options:";
62 yDebug() << "x_off";
63 yDebug() << "y_off";
64 yDebug() << "width";
65 yDebug() << "height";
66 return 0;
67 }
68
69 while(true)
70 {
71 ImageOf< PixelRgb> *inImg = input.read(true);
72 ImageOf< PixelRgb> &outImg=out.prepare();
73
74 if (inImg != 0)
75 {
76 crop(*inImg, outImg, start_x, start_y, width, height);
77 out.write();
78 c++;
79 }
80 printFrame(outImg.height(), outImg.width(), c);
81 }
82 return 0;
83}
84
85void printFrame(int h, int w, int c)
86{
87 if (c%500 == 0)
88 printf("Frame #%d %dx%d \n", c, h, w);
89}
void crop(const ImageOf< PixelRgb > &inImg, ImageOf< PixelRgb > &outImg, size_t start_x, size_t start_y, size_t width, size_t height)
Definition main.cpp:17
void printFrame(int h, int w, int c)
Definition main.cpp:85
int main()
Definition main.cpp:67
Copyright (C) 2008 RobotCub Consortium.
out
Definition sine.m:8