Visual Servoing Platform  version 3.3.0
testImageDraw.cpp

Test for vpImageDraw class.

/****************************************************************************
*
* ViSP, open source Visual Servoing Platform software.
* Copyright (C) 2005 - 2019 by Inria. All rights reserved.
*
* This software is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
* See the file LICENSE.txt at the root directory of this source
* distribution for additional information about the GNU GPL.
*
* For using ViSP with software that can not be combined with the GNU
* GPL, please contact Inria about acquiring a ViSP Professional
* Edition License.
*
* See http://visp.inria.fr for more information.
*
* This software was developed at:
* Inria Rennes - Bretagne Atlantique
* Campus Universitaire de Beaulieu
* 35042 Rennes Cedex
* France
*
* If you have questions regarding the use of this file, please contact
* Inria at visp@inria.fr
*
* This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
* WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* Description:
* Test for vpImageDraw class.
*
*****************************************************************************/
#include <iostream>
#include <visp3/core/vpImageDraw.h>
#include <visp3/core/vpFont.h>
#include <visp3/io/vpImageIo.h>
int main(int argc ,char *argv[])
{
bool save = false;
for (int i = 1; i < argc; i++) {
if (std::string(argv[i]) == "--save") {
save = true;
}
else if (std::string(argv[i]) == "--help" || std::string(argv[i]) == "-h") {
std::cout << "\nUsage: " << argv[0]
<< " [--save] [--help] [-h]\n"
<< std::endl;
return 0;
}
}
std::cout << "Save: " << save << std::endl;
//vpRGBa
{
vpImage<vpRGBa> I(480, 640, vpRGBa(255));
vpImagePoint iP1, iP2;
iP1.set_i(20);
iP1.set_j(10);
iP2.set_i(20);
iP2.set_j(30);
vpImageDraw::drawArrow(I, iP1, iP2, vpColor::green, 4, 2, 3);
iP1.set_i(20);
iP1.set_j(60);
vpFont font(32);
font.drawText(I, "Test...", iP1, vpColor::blue);
iP1.set_i(200);
iP1.set_j(200);
font.drawText(I, "Test...", iP1, vpColor::white, vpColor::black);
iP1.set_i(80);
iP1.set_j(220);
iP2.set_i(80);
iP2.set_j(480);
iP1.set_i(20);
iP1.set_j(220);
iP1.set_i(140);
iP1.set_j(10);
iP2.set_i(140);
iP2.set_j(50);
iP1.set_i(120);
iP1.set_j(180);
iP2.set_i(160);
iP2.set_j(250);
iP1.set_i(160);
iP1.set_j(280);
iP2.set_i(120);
iP2.set_j(340);
iP1.set_i(220);
iP1.set_j(400);
iP2.set_i(120);
iP2.set_j(400);
iP1.set_i(220);
iP1.set_j(480);
iP2.set_i(120);
iP2.set_j(450);
vpHomogeneousMatrix cMo(vpTranslationVector(0.15, -0.07, 0.37), vpRotationMatrix(vpRxyzVector(0.1, -0.4, 0.41)));
vpCameraParameters cam(600, 600, 320, 240);
vpImageDraw::drawFrame(I, cMo, cam, 0.05, vpColor::none, 3);
iP1.set_i(140);
iP1.set_j(80);
iP2.set_i(140);
iP2.set_j(150);
iP1.set_i(140);
iP1.set_j(400);
iP1.set_i(350);
iP1.set_j(20);
int w = 60;
int h = 50;
vpImageDraw::drawRectangle(I, vpRect(iP1, w, h), vpColor::red, false, 3);
iP1.set_i(350);
iP1.set_j(110);
iP1.set_i(350);
iP1.set_j(200);
iP2.set_i(400);
iP2.set_j(260);
iP1.set_i(350);
iP1.set_j(290);
iP2.set_i(400);
iP2.set_j(350);
vpRect rectangle(iP1, iP2);
vpImageDraw::drawRectangle(I, rectangle, vpColor::yellow, false, 3);
std::vector<vpImagePoint> polygon;
polygon.push_back(vpImagePoint(250, 500));
polygon.push_back(vpImagePoint(350, 600));
polygon.push_back(vpImagePoint(450, 500));
polygon.push_back(vpImagePoint(350, 400));
polygon.clear();
polygon.push_back(vpImagePoint(300, 500));
polygon.push_back(vpImagePoint(350, 550));
polygon.push_back(vpImagePoint(400, 500));
polygon.push_back(vpImagePoint(350, 450));
vpImageDraw::drawPolygon(I, polygon, vpColor::cyan, 3, false);
if (save) {
std::string filename = "canvas_color.png";
std::cout << "Save " << filename << std::endl;
vpImageIo::write(I, filename);
}
}
//unsigned char
{
vpImage<unsigned char> I(480, 640, 0);
vpImagePoint iP1, iP2;
unsigned char color = 255;
iP1.set_i(20);
iP1.set_j(10);
iP2.set_i(20);
iP2.set_j(30);
vpImageDraw::drawArrow(I, iP1, iP2, color, 4, 2, 3);
iP1.set_i(20);
iP1.set_j(60);
vpFont font(32);
font.drawText(I, "Test...", iP1, color);
iP1.set_i(200);
iP1.set_j(200);
font.drawText(I, "Test...", iP1, 0, 255);
iP1.set_i(80);
iP1.set_j(220);
iP2.set_i(80);
iP2.set_j(480);
vpImageDraw::drawCircle(I, iP1, 30, color, 3);
iP1.set_i(20);
iP1.set_j(220);
vpImageDraw::drawCross(I, iP1, 5, color, 1);
iP1.set_i(140);
iP1.set_j(10);
iP2.set_i(140);
iP2.set_j(50);
vpImageDraw::drawDottedLine(I, iP1, iP2, color, 3);
iP1.set_i(120);
iP1.set_j(180);
iP2.set_i(160);
iP2.set_j(250);
vpImageDraw::drawDottedLine(I, iP1, iP2, color, 3);
iP1.set_i(160);
iP1.set_j(280);
iP2.set_i(120);
iP2.set_j(340);
vpImageDraw::drawDottedLine(I, iP1, iP2, color, 3);
iP1.set_i(220);
iP1.set_j(400);
iP2.set_i(120);
iP2.set_j(400);
vpImageDraw::drawDottedLine(I, iP1, iP2, color, 3);
iP1.set_i(220);
iP1.set_j(480);
iP2.set_i(120);
iP2.set_j(450);
vpImageDraw::drawDottedLine(I, iP1, iP2, color, 3);
vpHomogeneousMatrix cMo(vpTranslationVector(0.15, -0.07, 0.37), vpRotationMatrix(vpRxyzVector(0.1, -0.4, 0.41)));
vpCameraParameters cam(600, 600, 320, 240);
vpImageDraw::drawFrame(I, cMo, cam, 0.05, color, 3);
iP1.set_i(140);
iP1.set_j(80);
iP2.set_i(140);
iP2.set_j(150);
vpImageDraw::drawLine(I, iP1, iP2, color, 3);
iP1.set_i(140);
iP1.set_j(400);
vpImageDraw::drawPoint(I, iP1, color);
iP1.set_i(350);
iP1.set_j(20);
int w = 60;
int h = 50;
vpImageDraw::drawRectangle(I, vpRect(iP1, w, h), color, false, 3);
iP1.set_i(350);
iP1.set_j(110);
vpImageDraw::drawRectangle(I, vpRect(iP1, w, h), color, true, 3);
iP1.set_i(350);
iP1.set_j(200);
iP2.set_i(400);
iP2.set_j(260);
vpImageDraw::drawRectangle(I, vpRect(iP1, iP2), color, false, 3);
iP1.set_i(350);
iP1.set_j(290);
iP2.set_i(400);
iP2.set_j(350);
vpRect rectangle(iP1, iP2);
vpImageDraw::drawRectangle(I, rectangle, color, false, 3);
std::vector<vpImagePoint> polygon;
polygon.push_back(vpImagePoint(250, 500));
polygon.push_back(vpImagePoint(350, 600));
polygon.push_back(vpImagePoint(450, 500));
polygon.push_back(vpImagePoint(350, 400));
vpImageDraw::drawPolygon(I, polygon, color, 3);
polygon.clear();
polygon.push_back(vpImagePoint(300, 500));
polygon.push_back(vpImagePoint(350, 550));
polygon.push_back(vpImagePoint(400, 500));
polygon.push_back(vpImagePoint(350, 450));
vpImageDraw::drawPolygon(I, polygon, color, 3, false);
if (save) {
std::string filename = "canvas_gray.png";
std::cout << "Save " << filename << std::endl;
vpImageIo::write(I, filename);
}
}
return EXIT_SUCCESS;
}
vpImageDraw::drawCircle
static void drawCircle(vpImage< unsigned char > &I, const vpImagePoint &center, unsigned int radius, unsigned char color, unsigned int thickness=1)
Definition: vpImageDraw.cpp:327
vpColor::white
static const vpColor white
Definition: vpColor.h:174
vpColor::orange
static const vpColor orange
Definition: vpColor.h:189
vpCameraParameters
Generic class defining intrinsic camera parameters.
Definition: vpCameraParameters.h:234
vpImageDraw::drawArrow
static void drawArrow(vpImage< unsigned char > &I, const vpImagePoint &ip1, const vpImagePoint &ip2, unsigned char color, unsigned int w=4, unsigned int h=2, unsigned int thickness=1)
Definition: vpImageDraw.cpp:237
vpColor::black
static const vpColor black
Definition: vpColor.h:173
vpColor::blue
static const vpColor blue
Definition: vpColor.h:185
vpImageDraw::drawDottedLine
static void drawDottedLine(vpImage< unsigned char > &I, const vpImagePoint &ip1, const vpImagePoint &ip2, unsigned char color, unsigned int thickness=1)
Definition: vpImageDraw.cpp:402
vpImageDraw::drawFrame
static void drawFrame(vpImage< unsigned char > &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, double size, unsigned char color, unsigned int thickness=1, const vpImagePoint &offset=vpImagePoint(0, 0))
Definition: vpImageDraw.cpp:752
vpRGBa
Definition: vpRGBa.h:67
vpTranslationVector
Class that consider the case of a translation vector.
Definition: vpTranslationVector.h:120
vpColor::none
static const vpColor none
Definition: vpColor.h:191
vpImageDraw::drawPoint
static void drawPoint(vpImage< unsigned char > &I, const vpImagePoint &ip, unsigned char color, unsigned int thickness=1)
Definition: vpImageDraw.cpp:870
vpColor::yellow
static const vpColor yellow
Definition: vpColor.h:187
vpImageIo::write
static void write(const vpImage< unsigned char > &I, const std::string &filename)
Definition: vpImageIo.cpp:445
vpRotationMatrix
Implementation of a rotation matrix and operations on such kind of matrices.
Definition: vpRotationMatrix.h:123
vpImageDraw::drawCross
static void drawCross(vpImage< unsigned char > &I, const vpImagePoint &ip, unsigned int size, unsigned char color, unsigned int thickness=1)
Definition: vpImageDraw.cpp:355
vpImageDraw::drawPolygon
static void drawPolygon(vpImage< unsigned char > &I, const std::vector< vpImagePoint > &vip, unsigned char color, unsigned int thickness=1, bool closed=true)
Definition: vpImageDraw.cpp:895
vpImagePoint
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition: vpImagePoint.h:89
vpFont
Font drawing functions for image.
Definition: vpFont.h:56
vpFont::drawText
bool drawText(vpImage< unsigned char > &I, const std::string &text, const vpImagePoint &position, unsigned char color) const
Definition: vpFont.cpp:1962
vpColor::green
static const vpColor green
Definition: vpColor.h:182
vpImage< vpRGBa >
vpColor::red
static const vpColor red
Definition: vpColor.h:179
vpHomogeneousMatrix
Implementation of an homogeneous matrix and operations on such kind of matrices.
Definition: vpHomogeneousMatrix.h:150
vpImagePoint::set_i
void set_i(double ii)
Definition: vpImagePoint.h:167
vpImagePoint::set_j
void set_j(double jj)
Definition: vpImagePoint.h:178
vpRxyzVector
Implementation of a rotation vector as Euler angle minimal representation.
Definition: vpRxyzVector.h:184
vpImageDraw::drawRectangle
static void drawRectangle(vpImage< unsigned char > &I, const vpRect &rectangle, unsigned char color, bool fill=false, unsigned int thickness=1)
Definition: vpImageDraw.cpp:927
vpRect
Defines a rectangle in the plane.
Definition: vpRect.h:79
vpColor::cyan
static const vpColor cyan
Definition: vpColor.h:188
vpImageDraw::drawLine
static void drawLine(vpImage< unsigned char > &I, const vpImagePoint &ip1, const vpImagePoint &ip2, unsigned char color, unsigned int thickness=1)
Definition: vpImageDraw.cpp:841