opencv / opencv_contrib

Repository for OpenCV's extra modules
Apache License 2.0
9.4k stars 5.76k forks source link

Create plot based on STL map #954

Open darkdragon-001 opened 7 years ago

darkdragon-001 commented 7 years ago

I would like to construct a cv::plot::Plot2d based on a STL std::map which is basically a std::list of std::pair<X,Y> which is similar to cv::Point. I guess supporting a std::list/std::vector/std::iterable/cv::Mat of cv::Point is crucial, since plotting points is what you normally do. Further, when you do plotting, you always need those pairs (btw: it implicitly ensures there is an equal number of x and y coordinates). Currently, you store both vectors separately - probably because you can easily handle the case when the user only supplies y coordinates.

Should I write a conversion to two std::vector? Or would it be a better idea to rewrite internal storage?

@nmoutinho Maybe you can have a look?

Edit: clarified the question.

darkdragon-001 commented 7 years ago

@alalek Why is this invalid?

I want to create a cv::plot::Plot2d via cv::plot::createPlot2d() and my data is in a std::map which is a list of (x,y) pairs. I think this should be supported since it is very similar to a vector<cv::Point> which can implicitly be converted to InputArray<cv::Point> which should definitely be supported in the OpenCV world! I mean, it is quite common to plot a list of points in a plot...

alalek commented 7 years ago

Because it was unclear how this issue is related to OpenCV.

BTW, InputArray will not support std::map, so overloaded function which extracts points (into std::vector) should be implemented.

darkdragon-001 commented 7 years ago

@alalek could you please add the label category:plot ?

nmoutinho commented 7 years ago

Hi @darkdragon-001, most of OpenCV classes only accept very limited types of inputs, either Mat or std::vector in some cases. To keep the same criteria, I implemented Plot2d this way. You can easily change your input data to match those, by creating separate vectors.

alalek commented 7 years ago

BTW, Only "InputArray" parameter type is supported as wrapper for Python/Java bindings - std::map and other non-scalar types are not supported.

nmoutinho commented 7 years ago

@alalek is correct, there are standards for the OpenCV classes due to this multi-language compatibility. I kept the same criteria when implementing Plot2d. By changing the input types to not match these standards, Plot2d could not be an OpenCV module.

StevenPuttemans commented 7 years ago

I would also relocate suggestions like this to #961