cv::fitLine doesn't accept cv::Point inherited class

asked 2015-07-31 02:31:09 -0500

victl gravatar image

Hi, everyone. I'm working on a project which has a 'MyPoint' class inherited from cv::Point. I just want to use cv::fitLine to process a std::vector< MyPoint >. But cv::fitLine simply can't process it. The codes compiles but produces a runtime error:

OpenCV Error: Assertion failed ((is2d || is3d) && (points.depth() == CV_32F || points.depth() == CV_32S)) in fitLine, file /build/opencv/src/opencv-2.4.10/modules/imgproc/src/contours.cpp, line 2033
terminate called after throwing an instance of 'cv::Exception'
what():  /build/opencv/src/opencv-2.4.10/modules/imgproc/src/contours.cpp:2033: error: (-215) (is2d || is3d) && (points.depth() == CV_32F || points.depth() == CV_32S) in function fitLine

I think it might because of the cv::fitLine used some strange techniques to determine if the real input is 2d or 3d, and whether it's Mat or vector< T >, which can not process my class. But since 'MyPoint' is inherited from cv::Point, and cv::fitLine do accept cv::Point, this problem is really violating the principles of OOP, I think... Do anybody knows how work around this issue? Thank you so much! And my codes:

class MyPoint: public cv::Point{
public:
MyPoint(int _x, int _y){
x=_x;
y=_y;
}
};

std::vector<MyPoint> points;
points.push_back(MyPoint(3,3));
points.push_back(MyPoint(4,4));
points.push_back(MyPoint(5,5));
cv::Vec4f line;
cv::fitLine(points,line, CV_DIST_L2,0,0.01,0.01);
edit retag flag offensive close merge delete

Comments

why do you want to inherit from cv::Point ?

berak gravatar imageberak ( 2015-08-01 05:59:26 -0500 )edit

I have the same error condition with a vector of the normal cv::Point class

2ros0 gravatar image2ros0 ( 2017-04-05 18:53:18 -0500 )edit