Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Many internal algorithms exploit the fact that the Point_ class only has the x and y coordinate data.

An example (that seems to be the source of your error) is transparent conversion between vector<Point_<> > and cv::Mat.

Internally, it initializes a matrix using the vector data, assuming the matrix row size to be 2 (2 dimensions in vector) and col size to be vector size. Then, it accesses the raw data using a pointer:

mat.data = &(vec[0].x) // this is the address of the first element in the vector

If the data struct only has two member vars, the next matrix column can be easily accessed by

((int*)mat.data)[j + width * i] // where w == 2.

But in the modified struct, the bool adds 32 more bits, and the conversion fails.

Conclusion: do not mess with the OpenCV core unless you know what you're doing.

Anyway, that is a bad programming practice, and there are many clean ways to solve your problem without modifying it. By example, create your own data struct:

struct MyPoint
{
    cv::Point p;
    bool myData;
}

Final word: before rushing to build a vector of points (original points) and a separate vector of bools, you should be aware of this "special property" of std::vector<bool>: http://stackoverflow.com/questions/6781985/is-the-use-of-stdvectorbool-objects-in-c-acceptable-or-should-i-use-an-al

Many internal algorithms exploit the fact that the Point_ class only has the x and y coordinate data.

An example (that seems to be the source of your error) is transparent conversion between vector<Point_<> > and cv::Mat.

Internally, it initializes a matrix using the vector data, assuming the matrix row size to be 2 (2 dimensions in vector) and col size to be vector size. Then, it accesses the raw data using a pointer:

mat.data = &(vec[0].x) // this is the address of the first element in the vector

If the data struct only has two member vars, the next matrix column can be easily accessed by

((int*)mat.data)[j + width * i] // where w == 2.

But in the modified struct, the bool adds 32 more bits, and the conversion fails.

Conclusion: do not mess with the OpenCV core unless you know what you're doing.

Anyway, that is a bad programming practice, and there are many clean ways to solve your problem without modifying it. the core. By example, create your own data struct:

struct MyPoint
{
    cv::Point p;
    bool myData;
}

Final word: before rushing to build a vector of points (original points) and a separate vector of bools, you should be aware of this "special property" of std::vector<bool>: http://stackoverflow.com/questions/6781985/is-the-use-of-stdvectorbool-objects-in-c-acceptable-or-should-i-use-an-al