Ask Your Question

Jorge Pereira's profile - activity

2017-08-24 06:59:32 -0600 received badge  Notable Question (source)
2015-03-14 13:08:42 -0600 received badge  Popular Question (source)
2014-03-22 01:31:50 -0600 received badge  Student (source)
2013-10-06 16:06:28 -0600 commented question Resize row from Mat

I already cropped the image, I want to resize the row lenght as the example in the image. I have to perform those modifications (c to d).

2013-10-06 15:46:05 -0600 commented question Resize row from Mat

It doesn't... I have this image witch is a Mat with different row size and I want to stretch the rows to make them of constant length.

2013-10-06 13:35:57 -0600 asked a question Resize row from Mat

I'm trying to resize the rows of a ROI Mat, witch is a polygon with different row size, to the half of the cols of the original Mat, and so I thought of run through all the rows of the Roi Mat and resize each one.

for (int j = 0; j < crop.rows; j++)
{
    if(pointPolygonTest( contours[0], Point2f((float)i,(float)j), true) > 0)

    //resize(crop.row(j), crop.row(j), Size(img.rows, img.cols/2), 0, 0, CV_INTER_LINEAR);
}

What am I doing wrong? Thank you!

2013-10-03 17:43:19 -0600 commented question Stretch all of the image rows in order to make them of constant length

no one?...

2013-10-03 05:17:20 -0600 asked a question Stretch all of the image rows in order to make them of constant length

Hi, I have the left side image and I want to stretch the rows in order to obtain the right side image.

image description

APPROACH 1:

This code (from here), gives me the contours.

vector< vector<Point> > contours;
contours.push_back(contour);

// you could also reuse img1 here
Mat mask = Mat::zeros(poseNormImg.rows, poseNormImg.cols, CV_8UC1);

// CV_FILLED fills the connected components found
drawContours(mask, contours, -1, Scalar(255), CV_FILLED);

// let's create a new image now
Mat crop(poseNormImg.rows, poseNormImg.cols, CV_8UC3);

// set background to green
crop.setTo(Scalar(255,255,0));

// and copy the magic apple
poseNormImg.copyTo(crop, mask);

imshow("cropped", crop);

How can I stretch the image from the contours, since it is a polygon with 10 points and and not a rectangle?

APPROACH 2:

Based on this question, I implemented this function , witch allow me to stretch a rectangle.

/**
 * http://stackoverflow.com/questions/7838487/executing-cvwarpperspective-for-a-fake-deskewing-on-a-set-of-cvpoint
 */
Mat deskewing(Mat src, Point pt1, Point pt2, Point pt3, Point pt4)
{
    vector<Point> not_a_rect_shape;
    not_a_rect_shape.push_back(pt1);
    not_a_rect_shape.push_back(pt2);
    not_a_rect_shape.push_back(pt3);
    not_a_rect_shape.push_back(pt4);

    // Assemble a rotated rectangle out of that info
    RotatedRect box = minAreaRect(cv::Mat(not_a_rect_shape));
    std::cout << "Rotated box set to (" << box.boundingRect().x << "," << box.boundingRect().y << ") " << box.size.width << "x" << box.size.height << std::endl;

    Point2f pts[4];

    box.points(pts);

    cv::Point2f src_vertices[3];
    src_vertices[0] = pts[0];
    src_vertices[1] = pts[1];
    src_vertices[2] = pts[3];

    Point2f dst_vertices[4];
    dst_vertices[0] = Point(0, 0);
    dst_vertices[1] = Point(box.boundingRect().width-1, 0); // Bug was: had mistakenly switched these 2 parameters
    dst_vertices[2] = Point(0, box.boundingRect().height-1);
    dst_vertices[3] = Point(box.boundingRect().width-1, box.boundingRect().height-1);


    Mat warpAffineMatrix = getAffineTransform(src_vertices, dst_vertices);

    cv::Mat rotated;
    cv::Size size(src.cols/2/*box.boundingRect().width*/, box.boundingRect().height);
    warpAffine(src, rotated, warpAffineMatrix, size, INTER_LINEAR, BORDER_CONSTANT);

    return rotated;
}

Since I was not able to stretch the entire polygon sub matrix, I thought of decomposing the polygon in to rectangles, stretching those areas and then sum them.

Using this approach I have two problems: the rectangle area is re sized to min area and rotated.

Is this the correct approach or is there another way?

Thank you

2013-10-03 03:35:24 -0600 commented answer Opencv v2.4.6 with eclipse kebler and windows x64

It was just an alternative, no need for down vote.

2013-10-01 02:20:33 -0600 received badge  Necromancer (source)
2013-09-30 14:37:07 -0600 commented answer Convert point vector to Mat

With this code I was able to get the left side! How can I obtain the right one?...

    std::vector&lt;Point&gt; contour;
    Mat roi(poseNormImg.rows, poseNormImg.cols, CV_8UC1);

    contour.push_back(normImgTop);
    contour.push_back(normImgEyebrowInner);
    contour.push_back(normImgCNoseTip);
    contour.push_back(normImgCNoseBase);
    contour.push_back(normImgTopLip);
    contour.push_back(normImgDownLip);
    contour.push_back(normImgTipOfChin);
    contour.push_back(normImgBottom);
    contour.push_back(normImgBottomRight);
    contour.push_back(normImgTopRight);

    vector&lt; vector&lt;Point&gt; &gt; contours;

    contours.push_back(contour);

    // draw the polygon
    polylines(roi, contours, true, Scalar(255), CV_AA);

    Mat mask = c
2013-09-30 14:17:35 -0600 commented answer Convert point vector to Mat

Hi, thank you for your answer. This codes gives me the same result, "just" the draw. Do you know how can I convert it to a Mat?

2013-09-30 13:25:33 -0600 commented answer Convert point vector to Mat

Hi, I already have submatrixs obtained like that, the problem is that this submatrix is not a rectangle, its a polygon.

2013-09-30 11:10:46 -0600 answered a question Opencv v2.4.6 with eclipse kebler and windows x64

Hi, I had several problems with Windows x64 and decided to change to Linux Mint (x64). I followed this tutorial and was able to install the latest version of OpenCv.

2013-09-30 10:53:00 -0600 commented question Convert point vector to Mat

Hi, thank you for your answer. I rephrased my question and added some code.

2013-09-29 17:04:24 -0600 received badge  Editor (source)
2013-09-29 17:01:06 -0600 asked a question Convert point vector to Mat

Hi, my objective is to obtain the right side of this image.

I thought I'd see the image as a polygon because I have the coordinates of the vertices, and then transform the vector that has the vertices in a matrix (cvMat).

My thought is correct or is there a simpler way to get this submatrix?

With the following code I can draw the polygon but I need to convert it to a matrix.

Point normImgTop, normImgEyebrowInner, normImgCNoseTip, normImgCNoseBase, normImgTipOfChin, normImgTopLip, normImgDownLip, normImgBottom, normImgTopRight, normImgBottomRight;

(...)

        std::vector<Point> contour;
        Mat roi(poseNormImg.rows, poseNormImg.cols, CV_8UC1);

        contour.push_back(normImgTop);
        contour.push_back(normImgEyebrowInner);
        contour.push_back(normImgCNoseTip);
        contour.push_back(normImgCNoseBase);
        contour.push_back(normImgTopLip);
        contour.push_back(normImgDownLip);
        contour.push_back(normImgTipOfChin);
        contour.push_back(normImgBottom);
        contour.push_back(normImgBottomRight);
        contour.push_back(normImgTopRight);

        const cv::Point *pts = (const cv::Point*) Mat(contour).data;
        int npts = Mat(contour).rows;
        std::cout << "Number of polygon vertices: " << npts << std::endl;

        // draw the polygon
        polylines(roi, &pts,&npts, 1,
                            true,           // draw closed contour (i.e. joint end to start)
                            Scalar(0,255,0),// colour RGB ordering (here = green)
                            3,              // line thickness
                            CV_AA, 0);

I'm using OpenCV 2.4.6.1 and C++.

Thank you