Domanda

In ARuco, a marker is a custom class.

Using the line: cout<<Markers[0]; Where Markers is vector<Marker>

The following example could be output: 185=(61.277,163.281) (186.9,174.062) (182.589,293.509) (55.8044,296.465) Txyz=-999999 -999999 -999999 Rxyz=-999999 -999999 -999999

I need the first 4 sets of numbers, but afaik they're not an accessible attribute of the class via markername.attributename. The only way to get them output is via cout. Everything else gets me the address e.g. 0xbf76ea14

So two possible answers I can see: 1) Easiest way to retrieving the line after cout and get it into a string I can work with 2) Any way trick it into thinking its printing to cout and skip a step?

È stato utile?

Soluzione

You cannot programmatically retrieve things that have already been sent to cout.

You could output the item to a memory buffer instead:

#include <sstream>
#include <ostream>
#include <string>

// ...

std::ostringstream oss;
oss << Markers[0];
std::string the_output = oss.str();

// you write some code to parse out the info you want from this string

Altri suggerimenti

From the Aruco source you can see for the stream insertion operator it is using:

for (int i=0;i<4;i++) str<<"("<<M[i].x<< ","<<M[i].y<<") ";

Assuming that Markers is of type aruno::Marker you should be able to just use Markers[0].x to get the x value of the first point.

If instead Markers is of type std::vector<aruno::Marker> then you can access it using Markers[0][0].x.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top