Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

You have to do it manually. Use the LineIterator to draw lines algorithmically; you can change the color of each pixel.

Then you have to iterate the lines that form the polygon of a contour and through the different contours.

Here is the pseudocode of the algorithm. It's almost ready, but it isn't tested, so you'll have to finish it and adapt it to your needs.

for(int k=0;k<contours.size();k++){
    contour = contours[k];  //the current contour
    for(int l=0;l<contour.size();l++){
        p0=contour[l];p1=contour[(l+1)%contour.size()]; //the endpoints of the line
        //the last line will be between the last and first points, that's why the % operator
        LineIterator it(img, p0, p1, 8); //this will generate the list of points on the line.
        for(int i=0; i<it.count; i++)
        {
            Vec3b(*it)=nextColor(); //it's up to you to generate the gradient as you like
            it++;
        }
    }
}