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.