Store details of a binary image consisting simple polygons

后端 未结 4 1518
礼貌的吻别
礼貌的吻别 2020-12-22 14:56

This question relates to somewhat practice and experienced based process. I have an Mat binary image which consist of simple white color polygons in a black background. Actu

4条回答
  •  长情又很酷
    2020-12-22 15:33

    cv::Mat inputImage = cv::imread("input.png", CV_LOAD_IMAGE_GRAYSCALE);
    
    // find non-zero point coordinates
    cv::Mat nonZeroCoordinates;
    cv::findNonZero(inputImage, nonZeroCoordinates);
    

    Then you can save the nonZeroCoordinates matrix into your file to use.

    If you want to create a same image using these coordinates, you can do like this:

    std::vector > points;
    points.push_back(nonZeroCoordinates);
    
    cv::Mat output = cv::Mat::zeros(inputImage.size(), CV_8UC1);
    cv::fillPoly(output, points, cv::Scalar(255));
    

    Hope it helps!

提交回复
热议问题