1 |
jakw |
1 |
|
|
|
2 |
#include <opencv2/opencv.hpp>
|
|
|
3 |
|
|
|
4 |
cv::Mat DLP3000InterpImage(cv::Mat I){
|
|
|
5 |
//DLP3000INTERPIMAGE Interpolates a 684 x 608 image for projection on the DLP3000
|
|
|
6 |
//diamond pixel array from a FWVGA image at 853 x 480.
|
|
|
7 |
//
|
|
|
8 |
// Input parameter:
|
|
|
9 |
// C (853 x 480 pixels): input image of type double
|
|
|
10 |
//
|
|
|
11 |
// Output parameter:
|
|
|
12 |
// I (684 x 608 matrix): output image
|
|
|
13 |
//
|
|
|
14 |
// Note that using a 853 x 480 provides the correct aspect ratio for projecting on the DLP3000.
|
|
|
15 |
// Note that the code assumes that the image is projected 1:1 aka "short-axis flip".
|
|
|
16 |
//
|
|
|
17 |
// DTU 2013, Jakob Wilm
|
|
|
18 |
|
|
|
19 |
cv::Mat ret(684, 608, CV_8U);
|
|
|
20 |
|
|
|
21 |
if(I.rows != 480 || I.cols != 853){
|
|
|
22 |
std::cerr << "Input image has wrong dimensions" << std::endl;
|
|
|
23 |
return ret;
|
|
|
24 |
}
|
|
|
25 |
|
|
|
26 |
// interpolation points
|
|
|
27 |
float mdiag = 853.0/607.5; // mirror diagonal in input pixels
|
|
|
28 |
|
|
|
29 |
cv::Mat mapX(684, 608, CV_32F), mapY(684, 608, CV_32F);
|
|
|
30 |
|
|
|
31 |
for(unsigned int row=0; row<684; row++){
|
|
|
32 |
for(unsigned int col=0; col<608; col++){
|
|
|
33 |
mapY.at<float>(row,col) = row * 479.0/683.0;
|
|
|
34 |
mapX.at<float>(row,col) = col*(852.0-0.5*mdiag)/607.0 + (row%2)*0.5*mdiag;
|
|
|
35 |
}
|
|
|
36 |
}
|
|
|
37 |
|
|
|
38 |
cv::remap(I, ret, mapX, mapY, cv::INTER_LINEAR);
|
|
|
39 |
|
|
|
40 |
return ret;
|
|
|
41 |
}
|