OpenCV std :: vector for arguments cv :: Mat

Doing this:

std::vector<cv::Point2f> pts; // contains 4 elements
cv::Mat ptsMat = ((cv::InputArray)pts).getMat();

On one machine, I get 4 on 1 cv::Mat with two channels. Each element is a two-dimensional point. On another machine, I get 2090-on-1 cv::Mat with two channels with strange data. This is wrong and this is a problem since the vector contains only 4 elements.

On both machines using OpenCV 3.1, built from the source, using CMake on Windows 10.

EDIT

I had a similar problem on another machine. In Visual Studio, in debug mode, the following snippet works fine:

std::vector<cv::Point2f> points = { cv::Point2f(2, 1), cv::Point2f(2, 1), cv::Point2f(1, 3) };
cv::InputArray arr = points;
cv::Mat ma = arr.getMat();
std::cout << ma.ptr<float>(0)[1];

But when I compile it in Release, it crashes in the last line with the location of the read access violation ...

Further research has shown that a key flag that matters:

: (/MD) -------- >

: DLL- (/MDd) -------- >

2

Mateen Ulhaq,

std::vector<cv::Point2f> points;
cv::Mat image(points);

. , OpenCV (, undistortPoints) getMat(). , .

3

, OpenCV 3.2

+4
1

, , .

, , , Windows.

: VTK, OpenCV, Eigen , , .

.

0

Source: https://habr.com/ru/post/1676843/


All Articles