Question

I'm new in opencv. I should implement a siemens star (http://upload.wikimedia.org/wikipedia/commons/5/50/Siemens_star.svg) in c++ and opencv. After days of searching the internet I'm very frustrated and I hope you can help me. I don't know how to start. My first idea to realize it, is to draw filled triangles from center and crop them with a circle. But I think there are no functions in opencv to draw a triangle. My 2nd approach is to plot all points between two vectors, but my mathematical knowledge is very poor (like my english, sorry ;)). Pleaseeee help me..

Thanks!

Was it helpful?

Solution

this is how you can do it with cv::ellipse :

cv::Mat siemensStar(unsigned int radius, unsigned int number_of_pieces)
{
    // create output image
    cv::Mat star(2*radius, 2*radius, CV_8UC1, 255);

    // center in the middle of the image
    cv::Point2f center(radius,radius);

    // angle of a single arc (mind that there is always one black and one white arc
    float angle = 360.0f/(2*(float)number_of_pieces);

    // draw all arcs
    for(float i=0; i<360; i+=2*angle)
    {
        // draw the outlines anti-aliased or change the line type if you want
        cv::ellipse(star, center, cv::Size(radius,radius), 0, i, i+angle, cv::Scalar(0),-1, CV_AA);
    }

    return star;
}

this works and gives me with the call cv::imshow("siemens star", siemensStar(256,16)); this result:

enter image description here

beware that this might not be what you want (since the optical effect in the center isnt really visible), but thats the problem of rastering (during drawing) I think. We don't work with vector images here. Maybe better if the number of elements is reduced...

OTHER TIPS

You can use ellipse() to draw a group of filled ellipse sectors.

Your assumption is wrong, there is a function to draw a triangle: fillPoly. You could have found that by simply googling "OpenCV draw".

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top