Ask Your Question
0

Solid Fill Rectangle Error [LineType Parameter?]

asked 2013-10-19 15:19:12 -0500

dmcenan gravatar image

updated 2013-10-19 15:19:50 -0500

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);
    }
edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
3

answered 2013-10-20 03:13:05 -0500

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.

edit flag offensive delete link more
0

answered 2013-10-19 16:00:23 -0500

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 )

edit flag offensive delete link more

Comments

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

berak gravatar imageberak ( 2013-10-19 16:37:54 -0500 )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 ( 2013-10-19 17:08:42 -0500 )edit

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

berak gravatar imageberak ( 2013-10-20 04:17:19 -0500 )edit
Login/Signup to Answer

Question Tools

Stats

Asked: 2013-10-19 15:19:12 -0500

Seen: 1,900 times

Last updated: Oct 20 '13