Create Mat from vector

前端 未结 1 659
野趣味
野趣味 2021-01-12 06:22

I am extremely new to computer vision and the opencv library.

I\'ve done some googling around to try to find how to make a new image from a vector of Point2fs and ha

1条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-12 06:40

    Should be as simple as

    std::vector points;
    cv::Mat image(points);
    //or
    cv::Mat image = cv::Mat(points) 
    

    The probably confusion is that a cv::Mat is an image width*height*number of channels but it also a mathematical matrix , rows*columns*other dimension.

    If you make a Mat from a vector of 'n' 2D points it will create a 2 column by 'n' rows matrix. You are passing this to a function which expects an image.

    If you just have a scattered set of 2D points and want to display them as an image you need to make an empty cv::Mat of large enough size (whatever your maximum x,y point is) and then draw the dots using the drawing functions http://docs.opencv.org/doc/tutorials/core/basic_geometric_drawing/basic_geometric_drawing.html

    If you just want to set the pixel values at those point coordinates search SO for opencv setting pixel values, there are lots of answers

    0 讨论(0)
提交回复
热议问题