How to draw on only one marker by using at function?

asked 2020-04-29 10:01:58 -0500

maha mohy gravatar image

Hello! I have 4 aruco markers, and i need to draw on only one of them, by selecting it's index, I tried to use .at () , but it draws on all the four markers for a while, any help? here is the code:

// Detect markers
    std::vector<int> ids;
    std::vector<std::vector<cv::Point2f> > corners;
    cv::aruco::detectMarkers(image, marker_dict, corners, ids);

    // Draw markers using opencv tool
    cv::aruco::drawDetectedMarkers(mid, corners, ids);

    // Draw markers custom
    for (size_t i = 0; i < corners.size(); ++i)
    {
        // Convert to integer ponits
        int num = static_cast<int>(corners[i].size());
        std::vector<cv::Point> points;
        for (size_t j = 0; j < corners[i].size(); ++j)
            points.push_back(cv::Point(static_cast<int>(corners[i][j].x), static_cast<int>(corners[i][j].y)));
        const cv::Point* pts = &(points[0]);


        // Draw
        if (ids.at(0) == 45) {
            cv::fillPoly(right, &pts, &num, 1, cv::Scalar(255, 0, 0));

        // Draw contour
        for (size_t j = 0; j < corners[i].size(); ++j)
        {
            size_t next = (j + 1) % corners[i].size();
            cv::line(right, corners[i][j], corners[i][next], cv::Scalar(0, 255, 0), 5);
        }
    }
    }
edit retag flag offensive close merge delete