Problem with perspective
Hello evrybody
I'm trying to apply a perspective transform on an image but I doesn't worklike I would like. Since code and pictures are easier to understand than a long speech (and because my english is quite poor) here is the code (in C):
#include <stdio.h>
#include "opencv/highgui.h"
#include "opencv/cv.h"
int main() {
int flags;
CvScalar fillval;
CvPoint2D32f P[3], Q[3];
IplImage *image, *resultat;
CvMat* matrice = cvCreateMat(3,3,CV_32FC1);
cvNamedWindow("Entrée", CV_WINDOW_AUTOSIZE);
cvNamedWindow("Résultat", CV_WINDOW_AUTOSIZE);
image = cvLoadImage("C:\\Users\\Julien\\Pictures\\tennis-3d.jpg", CV_LOAD_IMAGE_COLOR);
resultat=cvCloneImage(image);
cvShowImage( "Entrée", image);
cvShowImage( "Résultat", resultat);
P[0].x=266;
P[0].y=101;
P[1].x=534;
P[1].y=101;
P[2].x=667;
P[2].y=394;
P[3].x=133;
P[3].y=393;
Q[0].x=0;
Q[0].y=0;
Q[1].x=image->width;
Q[1].y=0;
Q[2].x=image->width;
Q[2].y=image->height;
Q[3].x=0;
Q[3].y=image->height;
cvGetPerspectiveTransform(P,Q,matrice);
cvWarpPerspective(image,resultat, matrice,flags=CV_WARP_FILL_OUTLIERS,fillval=cvScalarAll(0) );
cvShowImage( "Résultat", resultat);
cvWaitKey(1000000);
return 0;
}
And the result : The goal is to have a "top view" of the court
Thank you for your help
Sparrow
sorry for the downvote, but using opencv's c-api is no more a valid solution in 2015 (which makes this a 'bad question')
Sorry I didn't konw. It mays explain why I don't find many topic on opencv with C
your main problem is, that you have 4 points, but only allocate 3 here : P[3],Q[3];
so that's out of bounds / undefined behaviour, please always start a new program in debug mode, so the compiler can complain about things like this.
I'm stupid Thank you very much I'll open in debug mode
^^ you're not stupid, you're a noob, and it's a sunday. relax, and have fun with opencv ;)