Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Find squares and save the region of interest

static void drawSquares( Mat& image, const vector<vector<point> >& squares ) { //cout << "square size " << squares.size();

for( size_t i = 0; i < squares.size(); i++ )
{
    const Point* p = &squares[i][0];

    int n = (int)squares[i].size();
    //cout << "square size  " << n;

    //dont detect the border
    if (p-> x > 3 && p->y > 3){
    //  printf("x value %u y value %u\n",p-> x,p-> y);
      polylines(image, &p, &n, 1, true, Scalar(255,255,0), 3, LINE_AA);
    }

}
imshow(wndname, image);

}

Here is a part of the code I got from opencv sample code:https://github.com/opencv/opencv/blob/master/samples/cpp/squares.cpp

I want to save (imwrite) only the detected squares image description out of the whole imageimage description

I tried printing out x and y value of p but it only gives me the only a corner pixel value of the square. Could anyone please help how to save the squares only?

click to hide/show revision 2
None

updated 2018-05-13 05:24:32 -0600

berak gravatar image

Find squares and save the region of interest

static void drawSquares( Mat& image, const vector<vector<point> >& squares ) { //cout << "square size " << squares.size();

for( size_t i = 0; i < squares.size(); i++ )
{
    const Point* p = &squares[i][0];

    int n = (int)squares[i].size();
    //cout << "square size  " << n;

    //dont detect the border
    if (p-> x > 3 && p->y > 3){
    //  printf("x value %u y value %u\n",p-> x,p-> y);
      polylines(image, &p, &n, 1, true, Scalar(255,255,0), 3, LINE_AA);
    }

}
imshow(wndname, image);

}

Here is a part of the code I got from opencv sample code:https://github.com/opencv/opencv/blob/master/samples/cpp/squares.cpp

static void drawSquares( Mat& image, const vector<vector<Point> >& squares )
{
   //cout << "square size " << squares.size();

    for( size_t i = 0; i < squares.size(); i++ )
    {
        const Point* p = &squares[i][0];

        int n = (int)squares[i].size();
        //cout << "square size  " << n;

        //dont detect the border
        if (p-> x > 3 && p->y > 3){
        //  printf("x value %u y value %u\n",p-> x,p-> y);
          polylines(image, &p, &n, 1, true, Scalar(255,255,0), 3, LINE_AA);
        }

    }
    imshow(wndname, image);
}

I want to save (imwrite) only the detected squares image description out of the whole imageimage description

I tried printing out x and y value of p but it only gives me the only a corner pixel value of the square. Could anyone please help how to save the squares only?