Proportions of an image resized with OpenCV?

1

I have a project where I need to identify objects in an image, I am currently using the OpenCV library in C ++. I used the warpPerspective() function of OpenCV on a 605x141 size image to resize its perspective to a 674x35 size image. When doing this the object of the image was distorted as in the example illustration in the image below:

Let's say the width of the object in the first image is 100, for example. How can I identify the new width of the object in the new distorted image? It seems obvious but I tried using basic three rule, using the area and the aspect ratio of the two images, however the result is not beating when I manually compare the width in an image editor.

Note: If this question is not compatible with some forum policy, please let me know so I can try to rephrase it.

EDIT:

I do not know exactly if it will help solve the problem, but here is the code where I perform the perspective transformation:

void MyClass::TransformPerspec(){

Mat mat = cvCreateMat(3, 3, CV_8UC1);
this->fileira = cvCreateMat(35, 674, CV_8UC1); // matriz de saida da fileira será de tamanho 674x35

// Input Quadilateral or Image plane coordinates
Point2f inputQ[4];
// Output Quadilateral or World plane coordinates
Point2f outputQ[4];

inputQ[0].x = this->X1; inputQ[0].y = this->Y1;
inputQ[1].x = this->X2; inputQ[1].y = this->Y2;
inputQ[2].x = this->X3; inputQ[2].y = this->Y3;
inputQ[3].x = this->X4; inputQ[3].y = this->Y4;

outputQ[0].x = 0 ; outputQ[0].y = 0;
outputQ[1].x = 674;outputQ[1].y = 0;
outputQ[2].x = 0;  outputQ[2].y = 35;
outputQ[3].x = 674;outputQ[3].y = 35;

mat = getPerspectiveTransform(inputQ, outputQ);
warpPerspective(this->imagem_proc, this->fileira, mat, this->fileira.size());

imwrite("Teste.bmp", this->fileira);

}

After transforming perspective I just call this method:

reconheceObject(int largura);

where I use the width of the first image object for recognition, but since the object is distorted after the perspective transform, the 'width' value needs to be recalculated based on the new image. So I initially thought I could use a rule of three to find the new width. But now I know that a possible solution is not so simple.

    
asked by anonymous 10.09.2016 / 18:41

2 answers

1

Live, I think you need the resize (src, dst, size) function, where src is your original image and dst is a new image variable that you will create and size is the size of the final image that you can declare like this: Size size (100,100) .

    
27.09.2016 / 16:32
1

To maintain proportions of the original image without distortion you can only arbitrarily choose the size of one of the new dimensions, the other dimension will increase or decrease according to the change that occurred in the chosen dimension, your image has height 100 and you want to increase it to 140 (40% growth), your new width should be 40% larger. This is valid for choosing both dimensions. The following code snippet gives an idea of how to solve.

    double novaLargura = antigaLargura * novaAltura / antigaAltura;
    resize(img, img, Size(novaLargura, novaAltura));
    
07.06.2017 / 15:50