17void crop(
const ImageOf<PixelRgb> &inImg, ImageOf<PixelRgb> &outImg,
size_t start_x,
size_t start_y,
size_t width,
size_t height)
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);
23 for (
size_t r_src = start_y, r_dst = 0; r_src < end_y; r_dst++, r_src++)
25 unsigned char *tmp_dst = outImg.getRow(r_dst);
26 const unsigned char *tmp_src = inImg.getRow(r_src);
28 for (
size_t c_src = start_x, c_dst = 0; c_src < end_x; c_dst++, c_src++)
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];
37int main(
int argc,
char *argv[])
42 rf.configure(argc, argv);
44 BufferedPort<ImageOf<PixelRgb> > input;
45 BufferedPort<ImageOf<PixelRgb> >
out;
47 input.open(
"/imageCropper/in");
48 out.open(
"/imageCropper/out");
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);
61 yDebug() <<
"Available options:";
71 ImageOf< PixelRgb> *inImg = input.read(
true);
72 ImageOf< PixelRgb> &outImg=
out.prepare();
76 crop(*inImg, outImg, start_x, start_y, width, height);
80 printFrame(outImg.height(), outImg.width(), c);
void crop(const ImageOf< PixelRgb > &inImg, ImageOf< PixelRgb > &outImg, size_t start_x, size_t start_y, size_t width, size_t height)