Infinity marking



  • How do you recognize the infinity sign (namely it) in a photo or video?

    I would be grateful if you could bring the code back.

    UPD: Explain how, for example, through a contour analysis, it is clear whether there is an infinity in the photograph. The example below (there may be a full connection, a person may be visible - he may hold a sheet, the colour is not important).

    Контуры могут смежаться, человека может быть видно - он может держать лист, цвет не важен



  • OpenCV provides many tools to recognize samples, including through contour analysis. In the third version of the Fremworth, almost everything with regard to the comparison of contours has been assigned to a separate module with a title http://docs.opencv.org/master/d1/d85/group__shape.html ♪

    The author of the question did not specify which figures (bands of figures) would be compared to the infinity sign, and only noted that interest was only the fact that the was likely to be a candidate.

    Obviously, the notion of "finality" in itself would not say anything, but it would therefore have to offer her some form of reference. Let this image look like that. model1.jpg😞

    However, in order to make sure that the method further revealed allows for different features, add several different images (Files) to the reference model. model2.jpgmodel3.jpg and model4.jpg respectively):

    In fact, all images of the same size and are shown in a reduced form only to save space on the page.

    Let's start by deleting the object the author gave the question:

    cv::Mat tst_src_mat = cv::imread("test.jpg", cv::IMREAD_GRAYSCALE);
    if(tst_src_mat.empty()) return;
    

    cv::Mat tst_bin_mat;
    cv::threshold(tst_src_mat, tst_bin_mat, 0, 255
    , cv::THRESH_OTSU | cv::THRESH_BINARY_INV);

    After the binarization, there will be an artifact in addition to the object of interest in the image in the left bottom corner:

    It could be eliminated through a simple and philosophical approach, without paying attention, leaving only the contours of interest in the contrary. This can be done, for example, by focusing on the maximum area and the corresponding index in the vector:

    std::vector<std::vector<cv::Point> > tst_cs;
    cv::findContours(tst_bin_mat.clone(), tst_cs
    , cv::RETR_EXTERNAL, cv::CHAIN_APPROX_SIMPLE);

    int ci = -1; double max_area = 0.;
    for(int i = 0, n = tst_cs.size(); i < n; ++i) {
    const double area = cv::contourArea(tst_cs.at(i));
    if(area > max_area) {max_area = area; ci = i;}
    }

    if(ci == -1) return;

    It follows a nuance which implies that any comparable contours shall have the same number of points in their composition. Of course, the different figures will not normally follow this rule, which means they're gonna have to help it by adding the required number of points, but only at the coordinates that already exist in the figure:

    const int num_pts = 300;

    for(int i = tst_cs.at(ci).size()-1, d = 0; i < num_pts; ++i)
    tst_cs[ci].push_back(tst_cs[ci][d++]);

    Constant num_pts - this is an arbitrary number. It depends, in principle, on the complexity of the Ideally, it should be equal to the maximum number of points at the e-e-e... a multi-point contour the compared.

    Perhaps it is time to turn to the previously considered reference and images that are very different from the test figure:

    // Герой настоящей статьи, который собственно
    // и будет производить сравнение контуров.
    cv::Ptr<cv::ShapeContextDistanceExtractor> sc
    = cv::createShapeContextDistanceExtractor();

    for(int i = 0; i < 4; ++i) {
    std::string fname
    = std::string("model") + std::to_string(i+1) + std::string(".jpg");

    cv::Mat src_mat = cv::imread(fname, cv::IMREAD_GRAYSCALE);
    if(src_mat.empty()) return -1;
    
    cv::Mat bin_mat;
    cv::threshold(src_mat, bin_mat, 0, 255
        , cv::THRESH_OTSU | cv::THRESH_BINARY_INV);
    
    std::vector&lt;std::vector&lt;cv::Point&gt; &gt; cs;
    cv::findContours(bin_mat.clone(), cs
        , cv::RETR_EXTERNAL, cv::CHAIN_APPROX_SIMPLE);
    
    for(int i = cs.at(0).size()-1, d = 0; i &lt; num_pts; ++i)
        cs[0].push_back(cs[0][d++]);
    
    std::cout &lt;&lt; fname &lt;&lt; " - "
        &lt;&lt; sc-&gt;computeDistance(tst_cs[ci], cs[0]) &lt;&lt; std::endl;
    

    }

    The result of the code will be such:

    model1.jpg - 2.84489

    model2.jpg - 112.033

    model3.jpg - 32.8308

    model4.jpg - 524.659

    Presentation model1.jpg contains infinity, and consequently has the lowest distance between the test figure. Sobca images.model2.jpg) and hammer serpa.model4.jpg(d) In view of the obvious differences, the list of irregularities has been completed. But who would have thought "Betman"model3.jpgThis is the second place. But if you look around, it's quite possible to catch a common with an endless line.




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2