Re: [eigen] Eigen::Matrix and cv::Mat conversions |

[ Thread Index | Date Index | More lists.tuxfamily.org/eigen Archives ]

*To*: eigen@xxxxxxxxxxxxxxxxxxx*Subject*: Re: [eigen] Eigen::Matrix and cv::Mat conversions*From*: Benoit Jacob <jacob.benoit.1@xxxxxxxxx>*Date*: Fri, 20 Aug 2010 12:52:44 -0400*Dkim-signature*: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:in-reply-to :references:date:message-id:subject:from:to:content-type; bh=cTbOgPS8g0tqeNEuH+ybx/xeeT9UzERzNolZ/jA3+lg=; b=YRo4daXvCaM4VAK96pAG82bpOwFT+mkgT9ZEPr8olIWjBI5ds8UHSSFbqXYHBsM/Fy m36FyeuN826qrZVrcV2kwwQlCPosiZlhjEM0SBkQB9QGLlguHb3WLr+9wqrtPuARJz5y 4kYhTZvD1Pd1oeadTY8P/MByjsu5qo86IG05Y=*Domainkey-signature*: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; b=rpzBh15IUTYEl6p7NYGQXhwHddIY0n1IZAYubE5jY/ougy7oOxYxkslRu7VCY3ePBA guK48FsjJFw6snYDR1OLWiRPmNBku9Z6eOmLozIjlSkr0WfHBOkG3UekDwK5bTI15/wY Luoh3Y6Ltswb4lcLdPqQTKfihoQK3Y8PMnO4Y=

2010/8/20 <lfrfly@xxxxxxxxxxx>

Eigen defaults to column-major.

If you want row-major with Eigen you can do:

typedef Matrix<float,2,2,RowMajor> MyRowMajorMatrixType;

or you can even do:

#define EIGEN_DEFAULT_TO_ROW_MAJOR

before including eigen headers.

Benoit

I want to store the vertices of a convex polygon in an Eigen::Matrix<double, 7,2>, and then find the area of the polygon using the method of determinants. In other words, I need to make a series of mat.block<2,2>(n,0).det() calls. However, for this to work, the vertices must be in order (clockwise or ccw doesn't matter). So I figured I'd use a convex hull algorithm to reorder them.

Well, I already have a dependency on OpenCV, so I thought I'd use their convexHull() method. However, to do this I must either reinterpret or copy the contents of the Eigen::Matrix into a cv::Mat_<cv::Vec2f>(7,1). The internal format of this type is straightforward----I can just write floats in rowmajor order using std::transform() and it will be fine.

The tricky part is figuring how what is the best way to get at that data in the Eigen::Matrix. Curiously, upon examining the internals from data() in the debugger, the data appears to be in column-major order even though I didn't specify that (is it the default for some reason?). I know I can use the rowwise() method, but it isn't obvious to me if it's possible to get any kind of iterator from that, or if there's some other way to do the copy cleanly.

Eigen defaults to column-major.

If you want row-major with Eigen you can do:

typedef Matrix<float,2,2,RowMajor> MyRowMajorMatrixType;

or you can even do:

#define EIGEN_DEFAULT_TO_ROW_MAJOR

before including eigen headers.

Benoit

Of course I could simply loop over the thing, but I strive for more elegant solutions when possible.

**Follow-Ups**:**Re: [eigen] Eigen::Matrix and cv::Mat conversions***From:*lfrfly

**References**:**[eigen] Eigen::Matrix and cv::Mat conversions***From:*lfrfly

**Messages sorted by:**[ date | thread ]- Prev by Date:
**Re: [eigen] Optimization Algorithms** - Next by Date:
**Re: [eigen] Optimization Algorithms** - Previous by thread:
**[eigen] Eigen::Matrix and cv::Mat conversions** - Next by thread:
**Re: [eigen] Eigen::Matrix and cv::Mat conversions**

Mail converted by MHonArc 2.6.19+ | http://listengine.tuxfamily.org/ |