JeVoisBase  1.21
JeVois Smart Embedded Machine Vision Toolkit Base Modules
Share this page:
Loading...
Searching...
No Matches
ARtoolkit.H
Go to the documentation of this file.
1// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2//
3// JeVois Smart Embedded Machine Vision Toolkit - Copyright (C) 2016 by Laurent Itti, the University of Southern
4// California (USC), and iLab at USC. See http://iLab.usc.edu and http://jevois.org for information about this project.
5//
6// This file is part of the JeVois Smart Embedded Machine Vision Toolkit. This program is free software; you can
7// redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software
8// Foundation, version 2. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
9// without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
10// License for more details. You should have received a copy of the GNU General Public License along with this program;
11// if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
12//
13// Contact information: Shixian Wen - 3641 Watt Way, HNB-10A - Los Angeles, BA 90089-2520 - USA.
14// Tel: +1 213 740 3527 - shixianw@usc.edu - http://iLab.usc.edu - http://jevois.org
15// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
16/*! \file */
17
18#pragma once
19
21#include <jevois/Types/Enum.H>
23
24#include <AR/ar.h>
25#include <AR/video.h>
26#include <AR/config.h>
27#include <AR/param.h>
29
30// I need to define diferent camera_para.dat according to different camera size because of the limitation of the
31// original ARtoolkit library or change the original ARtoolkit library and I think its not a good way to go, makes the
32// package hard to distribute and update
33namespace jevois { class StdModule; }
34
35namespace artoolkit
36{
37 static jevois::ParameterCategory const ParamCateg("ARtoolkit Options");
38
39 //! Parameter \relates ARtoolkit
40 JEVOIS_DECLARE_PARAMETER(camparams, std::string, "File stem of camera parameters, or empty. Camera resolution "
41 "will be appended, as well as a .dat extension. For example, specifying 'camera_para' "
42 "here and running the camera sensor at 320x240 will attempt to load "
43 "camera_para320x240.dat from within the module's directory (if relative stem) or "
44 "from the specified absolute location (if absolute stem).",
45 JEVOIS_SHARE_PATH "/camera/camera_para", ParamCateg);
46
47 //! Parameter \relates ARtoolkit
48 JEVOIS_DECLARE_PARAMETER(contpose, bool, "Use continuous pose estimation in good quality video",
49 true, ParamCateg);
50
51 //! Parameter \relates ARtoolkit
52 JEVOIS_DECLARE_PARAMETER(msg3d, bool, "Send 3D serial messages if true, otherwise 2D",
53 false, ParamCateg);
54
55 //! Enum for parameter \relates ARtoolkit
56 JEVOIS_DEFINE_ENUM_CLASS(Dict, (AR_MATRIX_CODE_3x3) (AR_MATRIX_CODE_3x3_HAMMING63) (AR_MATRIX_CODE_3x3_PARITY65) );
57
58 //! ThreshMode to overcome different lighting situation \relates ARtoolkit
59 JEVOIS_DEFINE_ENUM_CLASS(DictThreshMode, (AR_LABELING_THRESH_MODE_MANUAL) (AR_LABELING_THRESH_MODE_AUTO_MEDIAN)
60 (AR_LABELING_THRESH_MODE_AUTO_OTSU) (AR_LABELING_THRESH_MODE_AUTO_ADAPTIVE)
61 (AR_LABELING_THRESH_MODE_AUTO_BRACKETING) );
62
63 //! Parameter \relates ARtoolkit
64 JEVOIS_DECLARE_PARAMETER(threshmode, DictThreshMode, "Dictionary threshold mode to use, affects "
65 "robustness to varying lighting conditions",
66 DictThreshMode::AR_LABELING_THRESH_MODE_AUTO_OTSU, DictThreshMode_Values, ParamCateg);
67
68 //! Parameter \relates ARtoolkit
69 JEVOIS_DECLARE_PARAMETER(dictionary, Dict, "Symbol dictionary to use",
70 Dict::AR_MATRIX_CODE_3x3_PARITY65, Dict_Values, ParamCateg);
71
72 //! Parameter \relates ARtoolkit
73 JEVOIS_DECLARE_PARAMETER(confthresh, double, "Minimum confidence threshold required for valid detections",
74 0.7, jevois::Range<double>(0.0, 1.0), ParamCateg)
75}
76
77//! Augmented reality markers using ARtoolkit
78/*! Detect and decode patterns known as ARtoolkit markers, which are small 2D barcodes often used in augmented
79 reality and robotics.
80
81 \ingroup Components */
83 public jevois::Parameter<artoolkit::camparams, artoolkit::contpose, artoolkit::dictionary,
84 artoolkit::msg3d, artoolkit::confthresh, artoolkit::threshmode>
85{
86 public:
87 //! Constructor
89
90 //! Core initialization
91 /*! Note that initialization is only partial and will complete once the frame size and format is known at the first
92 call to detectMarkers() */
93 void postInit() override;
94
95 // Un-init in preparation for destruction
96 void postUninit() override;
97
98 //! Destructor
99 ~ARtoolkit();
100
101 //! Detect markers in an image
102 /*! Probably the fastest if you have not already converted your input image to cv::Mat */
103 void detectMarkers(jevois::RawImage const & image);
104
105 //! Detect markers in an image
106 void detectMarkers(cv::Mat const & image);
107
108 //! Draw any markers previously detected by detectMarkers()
109 /*! If txtx,txty are positive, also print a text string there */
110 void drawDetections(jevois::RawImage & outimg, int txtx = -1, int txty = -1);
111
112#ifdef JEVOIS_PRO
113 //! Draw any markers previously detected by detectMarkers() using ImGui
114 /*! Detections are drawn to scale on the last image drawn by the helper. */
115 void drawDetections(jevois::GUIhelper & helper);
116#endif
117
118 //! Send serial messages about detections
119 /*! The module given should be the owner of this component, we will use it to actually send each serial message
120 using some variant of jevois::Module::sendSetial(). */
121 void sendSerial(jevois::StdModule * mod);
122
124 {
125 int id; //!< Marker ID
126 double width; //!< size in mm
127 double height; //!< size in mm
128 double q[4]; //!< quaternion
129 double pos[3]; //!< 3d position
130 int p2d[2]; //!< 2d position in image coords
131 std::vector<cv::Point> corners; //!< corners in standardized image coords
132 };
133
134 std::vector<arresults> itsResults; //!< Results of the last detection round
135
136 protected:
137 //! Manual initialization which should be run on first frame once its size is known
138 /*! pixformat should be AR_PIXEL_FORMAT_BGR, AR_PIXEL_FORMAT_RGB_565, etc */
139 void manualinit(int w, int h, AR_PIXEL_FORMAT pixformat);
140
141 void detectInternal(unsigned char const * data);
142
143 // some other not important parameters related to the initialization of the ARtoolkit
144
145 // initialization required
146 ARHandle * arHandle = nullptr;
147 ARPattHandle *arPattHandle;
149 AR3DHandle * ar3DHandle;
150 ARParamLT * gCparamLT = nullptr;
153 unsigned int itsW, itsH;
154};
Augmented reality markers using ARtoolkit.
Definition ARtoolkit.H:85
JEVOIS_DECLARE_PARAMETER(contpose, bool, "Use continuous pose estimation in good quality video", true, ParamCateg)
Parameter.
void detectInternal(unsigned char const *data)
Definition ARtoolkit.C:168
int gARPattDetectionMode
Definition ARtoolkit.H:148
ARMarkerSquare * markersSquare
Definition ARtoolkit.H:151
AR3DHandle * ar3DHandle
Definition ARtoolkit.H:149
~ARtoolkit()
Destructor.
Definition ARtoolkit.C:25
JEVOIS_DECLARE_PARAMETER(msg3d, bool, "Send 3D serial messages if true, otherwise 2D", false, ParamCateg)
Parameter.
std::vector< arresults > itsResults
Results of the last detection round.
Definition ARtoolkit.H:134
ARParamLT * gCparamLT
Definition ARtoolkit.H:150
JEVOIS_DECLARE_PARAMETER(threshmode, DictThreshMode, "Dictionary threshold mode to use, affects " "robustness to varying lighting conditions", DictThreshMode::AR_LABELING_THRESH_MODE_AUTO_OTSU, DictThreshMode_Values, ParamCateg)
Parameter.
void drawDetections(jevois::RawImage &outimg, int txtx=-1, int txty=-1)
Draw any markers previously detected by detectMarkers()
Definition ARtoolkit.C:237
void sendSerial(jevois::StdModule *mod)
Send serial messages about detections.
Definition ARtoolkit.C:281
JEVOIS_DECLARE_PARAMETER(dictionary, Dict, "Symbol dictionary to use", Dict::AR_MATRIX_CODE_3x3_PARITY65, Dict_Values, ParamCateg)
Parameter.
unsigned int itsH
Definition ARtoolkit.H:153
JEVOIS_DEFINE_ENUM_CLASS(Dict,(AR_MATRIX_CODE_3x3)(AR_MATRIX_CODE_3x3_HAMMING63)(AR_MATRIX_CODE_3x3_PARITY65))
Enum for parameter.
void manualinit(int w, int h, AR_PIXEL_FORMAT pixformat)
Manual initialization which should be run on first frame once its size is known.
Definition ARtoolkit.C:58
ARPattHandle * arPattHandle
Definition ARtoolkit.H:147
ARHandle * arHandle
Definition ARtoolkit.H:146
int markersSquareCount
Definition ARtoolkit.H:152
unsigned int itsW
Definition ARtoolkit.H:153
void postInit() override
Core initialization.
Definition ARtoolkit.C:29
JEVOIS_DECLARE_PARAMETER(camparams, std::string, "File stem of camera parameters, or empty. Camera resolution " "will be appended, as well as a .dat extension. For example, specifying 'camera_para' " "here and running the camera sensor at 320x240 will attempt to load " "camera_para320x240.dat from within the module's directory (if relative stem) or " "from the specified absolute location (if absolute stem).", JEVOIS_SHARE_PATH "/camera/camera_para", ParamCateg)
Parameter.
void postUninit() override
Definition ARtoolkit.C:36
void detectMarkers(jevois::RawImage const &image)
Detect markers in an image.
Definition ARtoolkit.C:130
friend friend class Component
double q[4]
quaternion
Definition ARtoolkit.H:128
std::vector< cv::Point > corners
corners in standardized image coords
Definition ARtoolkit.H:131
int id
Marker ID.
Definition ARtoolkit.H:125
double width
size in mm
Definition ARtoolkit.H:126
double pos[3]
3d position
Definition ARtoolkit.H:129
double height
size in mm
Definition ARtoolkit.H:127
int p2d[2]
2d position in image coords
Definition ARtoolkit.H:130