First time here? Check out the FAQ!

Ask Your Question
1

Solid Fill Rectangle Error [LineType Parameter?]

asked Oct 19 '13

dmcenan gravatar image

updated Oct 19 '13

Hi Folks,

When creating shapes with OpenCV, can someone tell me what the "LineType" parameter is? From the definition of the various shapes, it appears that linetype has a default value of 8. What is curious though, is when I use the code below to create a solid fill rectangle, the code produces a run time error whenever I use values of [2,3,5,6,7] for the LineType along with a value of -1 for the thickness (to produce a solid fill rectangle). However, when I change the thickness value to 6 and leave the linetype = 2, the code runs fine. Why is this??

Error: Assertion failed (connectivity == 8 || connectivity == 4) in LineIterator

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>

using namespace std;
using namespace cv;

//solid fill rectangle example
    int main()
    {
        Mat image(200, 200, CV_8UC3, Scalar(255,0,0));

        Point start = Point (50,50);
        Point end = Point (150,150);
        int thickness = -1;
        int linetype =2; //error

        rectangle (image, start, end, Scalar(0,255,0), thickness, linetype);

        namedWindow("Image");
        imshow("Image", image);

    waitKey(0);
    }
Preview: (hide)

2 answers

Sort by » oldest newest most voted
3

answered Oct 20 '13

Michael Burdinov gravatar image

As you can see in documentation of line, it has only 3 valid types: 4, 8 and 16(CV_AA). Passing any other value as lineType is not legal. But for any line thickness bigger than 1, type of line does not matter (not used, not checked). This is why your program runs fine when thickness = 2 and lineType = 2 which is illegal value. It is checked in only two cases: when thickness is 1, and when it is -1 (since your polygon may have just a single line, filling it is the same as just drawing it with thickness 1).

You can check wikipedia for more information about 4 and 8 connectivity.

Preview: (hide)
0

answered Oct 19 '13

berak gravatar image

linetype=2 seems to be the culprit here. no idea why (so far), but if you just omit it,

rectangle (image, start, end, Scalar(0,255,0), thickness );

you get the desired green rect.

( looking here ) , it seems, 4,8,16 are the legit values for linetype )

Preview: (hide)

Comments

ah, looking again at your q, [2,3,5,6,7] , - you made a trick question of it .. (+1)

berak gravatar imageberak (Oct 19 '13)edit

Thank you for your reply Berak. I am not too sure what to conclude here but I will stick with the default lineType value of 8. Some lineType values seem to depend on the thickness parameter for some reason. For example when thickness = 2 and lineType = 2 the code above runs fine but when I change the thickness to 1, a run time errorr occurs. With both thickness and lineType set to 1, the code again runs fine!

dmcenan gravatar imagedmcenan (Oct 19 '13)edit

please have a look at Michael Burdinov's answer, imho the better explanation.

berak gravatar imageberak (Oct 20 '13)edit

Question Tools

Stats

Asked: Oct 19 '13

Seen: 5,410 times

Last updated: Oct 20 '13