OpenCV Q&A Forum - RSS feedhttp://answers.opencv.org/questions/OpenCV answersenCopyright <a href="http://www.opencv.org">OpenCV foundation</a>, 2012-2018.Mon, 18 Sep 2017 04:33:48 -0500inverse perspective mapping (IPM) on the capture from camera feed?http://answers.opencv.org/question/174548/inverse-perspective-mapping-ipm-on-the-capture-from-camera-feed/Hi, I am an OpenCV noobie looking to perform IPM on the input camera feed, without having to set the camera angles? (X, Y, Z axes) my modification of the code obtained from the following GitHub link: https://gist.github.com/anujonthemove/7b35b7c1e05f01dd11d74d94784c1e58 **where I have manully added X as 43 rad, Y and Z as 90 rad, after trying out the windowed example**, is,
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
using namespace std;
using namespace cv;
#define PI 3.1415926
int frameWidth = 640;
int frameHeight = 480;
int main(int argc, char const *argv[]) {
if(argc < 2) {
cerr << "Usage: " << argv[0] << " /dev/video1" << endl;
cout << "Exiting...." << endl;
return -1;
}
// get file name from the command line
string filename = argv[1];
// capture object
VideoCapture capture(filename);
// mat container to receive images
Mat source, destination;
// check if capture was successful
if( !capture.isOpened()) throw "Error reading video";
int alpha_ = 90, beta_ = 90, gamma_ = 90;
int f_ = 500, dist_ = 500;
// namedWindow("Result", 1);
//createTrackbar("Alpha", "Result", &alpha_, 180);
//createTrackbar("Beta", "Result", &beta_, 180);
//createTrackbar("Gamma", "Result", &gamma_, 180);
//createTrackbar("f", "Result", &f_, 2000);
//createTrackbar("Distance", "Result", &dist_, 2000);
while( true ) {
capture >> source;
resize(source, source,Size(frameWidth, frameHeight));
double focalLength, dist, alpha, beta, gamma;
alpha = 43;
beta =((double)beta_ -90) * PI/180;
gamma =((double)gamma_ -90) * PI/180;
focalLength = (double)f_;
dist = (double)dist_;
Size image_size = source.size();
double w = (double)image_size.width, h = (double)image_size.height;
// Projecion matrix 2D -> 3D
Mat A1 = (Mat_<float>(4, 3)<<
1, 0, -w/2,
0, 1, -h/2,
0, 0, 0,
0, 0, 1 );
// Rotation matrices Rx, Ry, Rz
Mat RX = (Mat_<float>(4, 4) <<
1, 0, 0, 0,
0, cos(alpha), -sin(alpha), 0,
0, sin(alpha), cos(alpha), 0,
0, 0, 0, 1 );
Mat RY = (Mat_<float>(4, 4) <<
cos(beta), 0, -sin(beta), 0,
0, 1, 0, 0,
sin(beta), 0, cos(beta), 0,
0, 0, 0, 1 );
Mat RZ = (Mat_<float>(4, 4) <<
cos(gamma), -sin(gamma), 0, 0,
sin(gamma), cos(gamma), 0, 0,
0, 0, 1, 0,
0, 0, 0, 1 );
// R - rotation matrix
Mat R = RX * RY * RZ;
// T - translation matrix
Mat T = (Mat_<float>(4, 4) <<
1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 1, dist,
0, 0, 0, 1);
// K - intrinsic matrix
Mat K = (Mat_<float>(3, 4) <<
focalLength, 0, w/2, 0,
0, focalLength, h/2, 0,
0, 0, 1, 0
);
Mat transformationMat = K * (T * (R * A1));
warpPerspective(source, destination, transformationMat, image_size, INTER_CUBIC | WARP_INVERSE_MAP);
imshow("Result", destination);
waitKey(200);
}
return 0;
}
The Input:
![image description](/upfiles/15057267541228827.png)
and the output:
![image description](/upfiles/15057267932738349.png)
Is it possible to make the camera automatically convert the image into its IPM transform without having to set the angles (Here, X)?
**Any help would be highly appreciated.Thanks in advance.**
**UPDATE**
I used the same example to assign values to an input video's angles, instead of using a png input. The results and values are shown below, It will be helpful **If the camera automatically converts input feed into its IPM transform** instead of taking the user values for parameters.
Input 2:
![image description](/upfiles/15057315751644999.png)
Output 2:
![image description](/upfiles/1505731595891104.png)srx2365Mon, 18 Sep 2017 04:33:48 -0500http://answers.opencv.org/question/174548/Inverse Perspective Mapping Lib OpenCVhttp://answers.opencv.org/question/62836/inverse-perspective-mapping-lib-opencv/ Hi, just a short q, is there a library for IPM? I did try looking but fail. Please let me know then.
TQVMzmsFri, 29 May 2015 00:23:35 -0500http://answers.opencv.org/question/62836/How to build lookup table for inverse perspective mapping?http://answers.opencv.org/question/11379/how-to-build-lookup-table-for-inverse-perspective-mapping/Hi, I want to build a lookup table to use with inverse perspective mapping.
Instead of applying warpPerspective with the transform matrix on each frame, I want to use a lookup table (LUT).
Right now I use the following code to generate the transformation matrix
m = new Mat(3, 3, CvType.CV_32FC1);
m = Imgproc.getPerspectiveTransform(src, dst);
In the onCameraFrame() I apply the warpPerspective() function. How can I build a LUT knowing some input pixels on the original frame and their correspondences in the output frame, and knowing the transfromation matrix?? razvanThu, 11 Apr 2013 13:18:18 -0500http://answers.opencv.org/question/11379/Inverse Perspective Mappinghttp://answers.opencv.org/question/2309/inverse-perspective-mapping/Hi,
I would like to generate the birds eye view of an input image (given as Mat) with OpenCV.
The intrinsic and extrinsic parameters of the camera are known.
Among other things I need to know the Viewpoint of the camera (l,h,d) and the viewing direction:
[IPM.jpeg](/upfiles/13476431139813413.jpeg)
So my question is how can I determine these parameters with the help of the known intrinsic and extrinsic parameters? Or have I to measure them otherwise?
Thank you.njaaFri, 14 Sep 2012 12:14:19 -0500http://answers.opencv.org/question/2309/